Skip to content

Commit 12ed4e5

Browse files
karthiknittclaude
andauthored
Add automated Docker image publishing to Docker Hub and GHCR (#26)
Enhanced the Docker build workflow to automatically build and push images to both Docker Hub and GitHub Container Registry on pushes to main branch. Changes: - Added Docker Hub and GHCR authentication steps - Configured multi-registry image tagging (latest, branch, SHA) - Updated health and API endpoint tests to use published images - Added required permissions for GHCR package publishing Required secrets: DOCKERHUB_USERNAME, DOCKERHUB_TOKEN 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8f7bd04 commit 12ed4e5

File tree

1 file changed

+52
-11
lines changed

1 file changed

+52
-11
lines changed

.github/workflows/docker-build.yml

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,73 @@
1-
name: Docker Build Test
1+
name: Docker Build and Push
22

33
on:
44
push:
55
branches: [ main ]
66
pull_request:
77
branches: [ main ]
88

9+
env:
10+
REGISTRY_DOCKERHUB: docker.io
11+
REGISTRY_GHCR: ghcr.io
12+
IMAGE_NAME: ${{ github.repository_owner }}/tamil-panchang-api
13+
914
jobs:
10-
build:
15+
build-and-push:
1116
runs-on: ubuntu-latest
12-
17+
18+
permissions:
19+
contents: read
20+
packages: write
21+
1322
steps:
14-
- uses: actions/checkout@v3
15-
16-
- name: Build Docker image
17-
run: docker build -t tamil-panchang-api:test .
18-
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
- name: Log in to Docker Hub
27+
uses: docker/login-action@v3
28+
with:
29+
username: ${{ secrets.DOCKERHUB_USERNAME }}
30+
password: ${{ secrets.DOCKERHUB_TOKEN }}
31+
32+
- name: Log in to GitHub Container Registry
33+
uses: docker/login-action@v3
34+
with:
35+
registry: ${{ env.REGISTRY_GHCR }}
36+
username: ${{ github.actor }}
37+
password: ${{ secrets.GITHUB_TOKEN }}
38+
39+
- name: Extract metadata
40+
id: meta
41+
uses: docker/metadata-action@v5
42+
with:
43+
images: |
44+
${{ env.REGISTRY_DOCKERHUB }}/${{ env.IMAGE_NAME }}
45+
${{ env.REGISTRY_GHCR }}/${{ env.IMAGE_NAME }}
46+
tags: |
47+
type=ref,event=branch
48+
type=ref,event=pr
49+
type=sha,prefix={{branch}}-
50+
type=raw,value=latest,enable={{is_default_branch}}
51+
52+
- name: Build and push Docker image
53+
uses: docker/build-push-action@v5
54+
with:
55+
context: .
56+
push: true
57+
tags: ${{ steps.meta.outputs.tags }}
58+
labels: ${{ steps.meta.outputs.labels }}
59+
1960
- name: Test health endpoint
2061
run: |
21-
docker run -d --name test-api -p 8000:8000 tamil-panchang-api:test
62+
docker run -d --name test-api -p 8000:8000 ${{ env.REGISTRY_DOCKERHUB }}/${{ env.IMAGE_NAME }}:latest
2263
sleep 10
2364
curl -f http://localhost:8000/health || exit 1
2465
docker stop test-api
2566
docker rm test-api
26-
67+
2768
- name: Test API endpoint
2869
run: |
29-
docker run -d --name test-api -p 8000:8000 tamil-panchang-api:test
70+
docker run -d --name test-api -p 8000:8000 ${{ env.REGISTRY_DOCKERHUB }}/${{ env.IMAGE_NAME }}:latest
3071
sleep 10
3172
curl -X POST http://localhost:8000/api/today \
3273
-H "Content-Type: application/json" \

0 commit comments

Comments
 (0)