Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CI/CD

on:
pull_request:
branches:
- main
push:
branches:
- main

permissions:
contents: read
packages: write

env:
IMAGE_NAME: ghcr.io/aldriondev/http-server-devops

jobs:
build:
name: Test, build and publish
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Run tests
run: go test ./...

- name: Log in to github container registry
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up docker buildx
uses: docker/setup-buildx-action@v3

- name: Build and optionally push docker image
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
tags: |
${{ env.IMAGE_NAME }}:latest
${{ env.IMAGE_NAME }}:${{ github.sha }}
49 changes: 46 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ containerization, CI/CD, Kubernetes deployment, and Terraform infrastructure.
- **Language:** Go
- **Container:** Docker
- **CI/CD:** GitHub Actions
- **Registry:** Docker Hub
- **Registry:** GitHub Container Registry
- **Orchestration:** Kubernetes
- **IaC:** Terraform

Expand All @@ -17,7 +17,8 @@ containerization, CI/CD, Kubernetes deployment, and Terraform infrastructure.
```text
http-server-devops/
├── .github/
│ └── workflows/ # CI/CD pipeline
│ └── workflows/
│ └── docker-publish.yml
├── k8s/ # Kubernetes manifests
├── terraform/ # Terraform configuration
├── Dockerfile
Expand All @@ -31,7 +32,7 @@ http-server-devops/

- [x] Task 1: HTTP Server
- [x] Task 2: Dockerize
- [ ] Task 3: CI/CD Pipeline
- [x] Task 3: CI/CD Pipeline
- [ ] Task 4: Kubernetes Deployment
- [ ] Task 5: Terraform Configuration

Expand Down Expand Up @@ -94,3 +95,45 @@ docker run --rm -p 9090:9090 -e PORT=9090 http-server-devops:local
```bash
curl http://localhost:9090/
```

## CI/CD

This project uses GitHub Actions to run tests, build the Docker image, and publish it to GitHub Container Registry.

The workflow is defined in:

```text
.github/workflows/docker-publish.yml
```

On pull requests to `main`, the pipeline:

- runs Go tests
- builds the Docker image without publishing it

On pushes to `main`, the pipeline:

- runs Go tests
- builds the Docker image
- publishes the image to GitHub Container Registry

Published image:

```text
ghcr.io/aldriondev/http-server-devops
```

Published tags:

- `latest`
- ghcr.io/aldriondev/http-server-devops:latest

The workflow uses the built-in GITHUB_TOKEN with following permissions:

```yaml
permissions:
contents: read
packages: write
```

No external Docker registry credentials are required.
Loading