Skip to content

Commit c8402a3

Browse files
authored
Merge pull request #6 from AldrionDev/task-3-ci-cd-pipeline
add GitHub Actions CI/CD pipeline
2 parents abd3311 + e42095f commit c8402a3

2 files changed

Lines changed: 99 additions & 3 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: CI/CD
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
11+
permissions:
12+
contents: read
13+
packages: write
14+
15+
env:
16+
IMAGE_NAME: ghcr.io/aldriondev/http-server-devops
17+
18+
jobs:
19+
build:
20+
name: Test, build and publish
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v4
26+
27+
- name: Set up go
28+
uses: actions/setup-go@v5
29+
with:
30+
go-version-file: go.mod
31+
32+
- name: Run tests
33+
run: go test ./...
34+
35+
- name: Log in to github container registry
36+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
37+
uses: docker/login-action@v3
38+
with:
39+
registry: ghcr.io
40+
username: ${{ github.actor }}
41+
password: ${{ secrets.GITHUB_TOKEN }}
42+
43+
- name: Set up docker buildx
44+
uses: docker/setup-buildx-action@v3
45+
46+
- name: Build and optionally push docker image
47+
uses: docker/build-push-action@v6
48+
with:
49+
context: .
50+
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
51+
tags: |
52+
${{ env.IMAGE_NAME }}:latest
53+
${{ env.IMAGE_NAME }}:${{ github.sha }}

README.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ containerization, CI/CD, Kubernetes deployment, and Terraform infrastructure.
88
- **Language:** Go
99
- **Container:** Docker
1010
- **CI/CD:** GitHub Actions
11-
- **Registry:** Docker Hub
11+
- **Registry:** GitHub Container Registry
1212
- **Orchestration:** Kubernetes
1313
- **IaC:** Terraform
1414

@@ -17,7 +17,8 @@ containerization, CI/CD, Kubernetes deployment, and Terraform infrastructure.
1717
```text
1818
http-server-devops/
1919
├── .github/
20-
│ └── workflows/ # CI/CD pipeline
20+
│ └── workflows/
21+
│ └── docker-publish.yml
2122
├── k8s/ # Kubernetes manifests
2223
├── terraform/ # Terraform configuration
2324
├── Dockerfile
@@ -31,7 +32,7 @@ http-server-devops/
3132

3233
- [x] Task 1: HTTP Server
3334
- [x] Task 2: Dockerize
34-
- [ ] Task 3: CI/CD Pipeline
35+
- [x] Task 3: CI/CD Pipeline
3536
- [ ] Task 4: Kubernetes Deployment
3637
- [ ] Task 5: Terraform Configuration
3738

@@ -94,3 +95,45 @@ docker run --rm -p 9090:9090 -e PORT=9090 http-server-devops:local
9495
```bash
9596
curl http://localhost:9090/
9697
```
98+
99+
## CI/CD
100+
101+
This project uses GitHub Actions to run tests, build the Docker image, and publish it to GitHub Container Registry.
102+
103+
The workflow is defined in:
104+
105+
```text
106+
.github/workflows/docker-publish.yml
107+
```
108+
109+
On pull requests to `main`, the pipeline:
110+
111+
- runs Go tests
112+
- builds the Docker image without publishing it
113+
114+
On pushes to `main`, the pipeline:
115+
116+
- runs Go tests
117+
- builds the Docker image
118+
- publishes the image to GitHub Container Registry
119+
120+
Published image:
121+
122+
```text
123+
ghcr.io/aldriondev/http-server-devops
124+
```
125+
126+
Published tags:
127+
128+
- `latest`
129+
- ghcr.io/aldriondev/http-server-devops:latest
130+
131+
The workflow uses the built-in GITHUB_TOKEN with following permissions:
132+
133+
```yaml
134+
permissions:
135+
contents: read
136+
packages: write
137+
```
138+
139+
No external Docker registry credentials are required.

0 commit comments

Comments
 (0)