Skip to content

Commit

Permalink
[add] github workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
aqidd committed Dec 30, 2024
1 parent d87b74e commit 75fae5b
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 22 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Docker Build and Publish

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

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

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

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=sha,format=long
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,31 @@ All API endpoints require a Bearer token which can be generated from the admin p
- DELETE endpoint `/api/v1/vouchers/{code}` to remove vouchers
- Request logging middleware to track API requests with timing information
- Improved error handling for voucher creation with detailed error messages
- GitHub Actions workflow for automated Docker image builds
- Container Registry integration for Docker image distribution

#### Changed
- Enhanced API error responses to include more detailed information
- Updated Swagger documentation with new delete endpoint

## CI/CD Pipeline

The project uses GitHub Actions for continuous integration and delivery:

### Docker Image Publishing
- Images are automatically built and published to GitHub Container Registry
- Tags are created for:
- Branch names (e.g., `develop`, `main`)
- Git SHA (for precise version tracking)
- Latest tag (only for main branch)

### Pull Images
```bash
# Pull latest main branch image
docker pull ghcr.io/[username]/voucher-management:latest

# Pull specific branch
docker pull ghcr.io/[username]/voucher-management:develop
```

Replace `[username]` with your GitHub username.
22 changes: 0 additions & 22 deletions dockerignore

This file was deleted.

0 comments on commit 75fae5b

Please sign in to comment.