Skip to content

Commit e4114f9

Browse files
karthiknittclaude
andauthored
Fix workflow GHCR permissions issue (#28)
* Add automated Docker image publishing to Docker Hub and GHCR 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> * Fix workflow to skip push operations on pull requests The workflow was failing because it attempted to push to GHCR during PR builds, which don't have write permissions. This fix ensures that push operations only occur on direct pushes to main. Changes: - Added conditional checks to skip Docker registry login on PRs - Set push parameter to false for PRs (build-only mode) - Skip test steps on PRs since images aren't pushed to registry - Maintains full build validation on PRs without requiring write access This allows PRs to validate builds while only pushing images when merging to main. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2dac897 commit e4114f9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

.github/workflows/docker-build.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ jobs:
2424
uses: actions/checkout@v4
2525

2626
- name: Log in to Docker Hub
27+
if: github.event_name != 'pull_request'
2728
uses: docker/login-action@v3
2829
with:
2930
username: ${{ secrets.DOCKERHUB_USERNAME }}
3031
password: ${{ secrets.DOCKERHUB_TOKEN }}
3132

3233
- name: Log in to GitHub Container Registry
34+
if: github.event_name != 'pull_request'
3335
uses: docker/login-action@v3
3436
with:
3537
registry: ${{ env.REGISTRY_GHCR }}
@@ -53,11 +55,12 @@ jobs:
5355
uses: docker/build-push-action@v5
5456
with:
5557
context: .
56-
push: true
58+
push: ${{ github.event_name != 'pull_request' }}
5759
tags: ${{ steps.meta.outputs.tags }}
5860
labels: ${{ steps.meta.outputs.labels }}
5961

6062
- name: Test health endpoint
63+
if: github.event_name != 'pull_request'
6164
run: |
6265
docker run -d --name test-api -p 8000:8000 ${{ env.REGISTRY_DOCKERHUB }}/${{ env.IMAGE_NAME }}:latest
6366
sleep 10
@@ -66,6 +69,7 @@ jobs:
6669
docker rm test-api
6770
6871
- name: Test API endpoint
72+
if: github.event_name != 'pull_request'
6973
run: |
7074
docker run -d --name test-api -p 8000:8000 ${{ env.REGISTRY_DOCKERHUB }}/${{ env.IMAGE_NAME }}:latest
7175
sleep 10

0 commit comments

Comments
 (0)