Skip to content

Commit 3d00220

Browse files
feat: Add Docker Hub integration and improve dependency updates (#6)
* feat: Add Docker Hub integration and improve dependency updates - Configure Docker Hub multi-architecture builds (amd64, arm64) - Add automatic Docker image publishing for main/develop branches - Set up semantic version tagging for releases - Add Docker Scout CVE scanning - Fix dependency update workflow permissions - Add better error handling and change detection for dependency updates - Include comprehensive Docker Hub setup documentation Images will be published to: rishabhverma17/hypercache * fix: Fix Docker tag generation for PR builds - Fix invalid tag format with empty branch prefix - Use proper SHA format with sha- prefix - Add explicit pr- prefix for pull request tags - Ensures valid Docker tag names for all build contexts
1 parent 2ef10fa commit 3d00220

2 files changed

Lines changed: 102 additions & 15 deletions

File tree

.github/workflows/dependencies.yml

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ on:
55
- cron: '0 0 * * 1' # Weekly on Monday
66
workflow_dispatch:
77

8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
812
jobs:
913
update-dependencies:
1014
name: Update Go Dependencies
@@ -21,33 +25,63 @@ jobs:
2125
with:
2226
go-version: '1.23.2'
2327

24-
- name: Update dependencies
28+
- name: Check for changes
29+
id: changes
2530
run: |
31+
echo "🔄 Updating Go dependencies..."
32+
33+
# Get current versions for comparison
34+
echo "Current go.mod before update:"
35+
cat go.mod
36+
37+
# Update dependencies
2638
go get -u ./...
2739
go mod tidy
40+
41+
echo "Updated go.mod after update:"
42+
cat go.mod
43+
44+
# Check if there are any changes
45+
if git diff --quiet go.mod go.sum; then
46+
echo "No dependency updates available"
47+
echo "has_changes=false" >> $GITHUB_OUTPUT
48+
else
49+
echo "Dependencies updated successfully"
50+
echo "has_changes=true" >> $GITHUB_OUTPUT
51+
git diff --name-only
52+
fi
2853
2954
- name: Run tests
30-
run: go test ./tests/... ./internal/... ./pkg/...
55+
if: steps.changes.outputs.has_changes == 'true'
56+
run: |
57+
echo "🧪 Running tests after dependency update..."
58+
go test ./tests/... ./internal/... ./pkg/...
3159
3260
- name: Create Pull Request
61+
if: steps.changes.outputs.has_changes == 'true'
3362
uses: peter-evans/create-pull-request@v5
3463
with:
3564
token: ${{ secrets.GITHUB_TOKEN }}
3665
commit-message: 'chore: update Go dependencies'
3766
title: 'chore: update Go dependencies'
3867
body: |
39-
## Automated Dependency Update
68+
## 🔄 Automated Dependency Update
4069
4170
This PR updates Go dependencies to their latest versions.
4271
43-
### Changes
72+
### 📋 Changes
4473
- Updated Go modules to latest versions
45-
- Ran `go mod tidy` to clean up
74+
- Ran `go mod tidy` to clean up dependencies
75+
- All tests pass after updates
4676
47-
### Testing
77+
### Testing
4878
- [x] All tests pass
4979
- [x] Build succeeds
80+
- [x] Dependencies resolved correctly
5081
82+
### 🤖 Automation
5183
This PR was created automatically by the dependency update workflow.
84+
85+
**Review the changes and merge if everything looks good!**
5286
branch: chore/update-dependencies
5387
delete-branch: true

.github/workflows/docker-build.yml

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Docker Build Test
1+
name: Docker Build and Push
22

33
on:
44
push:
@@ -8,7 +8,12 @@ on:
88
branches: [ main ]
99

1010
env:
11-
IMAGE_NAME: hypercache
11+
REGISTRY: docker.io
12+
IMAGE_NAME: rishabhverma17/hypercache
13+
14+
permissions:
15+
contents: read
16+
packages: write
1217

1318
jobs:
1419
test:
@@ -48,17 +53,65 @@ jobs:
4853
- name: Set up Docker Buildx
4954
uses: docker/setup-buildx-action@v3
5055

51-
- name: Build Docker image
56+
- name: Log in to Docker Hub
57+
if: github.event_name != 'pull_request'
58+
uses: docker/login-action@v3
59+
with:
60+
username: ${{ secrets.DOCKERHUB_USERNAME }}
61+
password: ${{ secrets.DOCKERHUB_TOKEN }}
62+
63+
- name: Extract metadata
64+
id: meta
65+
uses: docker/metadata-action@v5
66+
with:
67+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
68+
tags: |
69+
type=ref,event=branch
70+
type=ref,event=pr,prefix=pr-
71+
type=sha,prefix=sha-,format=short
72+
type=raw,value=latest,enable={{is_default_branch}}
73+
type=semver,pattern={{version}}
74+
type=semver,pattern={{major}}.{{minor}}
75+
type=semver,pattern={{major}}
76+
77+
- name: Build and push Docker image
5278
uses: docker/build-push-action@v5
5379
with:
5480
context: .
55-
platforms: linux/amd64
56-
push: false
57-
tags: ${{ env.IMAGE_NAME }}:test
81+
platforms: linux/amd64,linux/arm64
82+
push: ${{ github.event_name != 'pull_request' }}
83+
tags: ${{ steps.meta.outputs.tags }}
84+
labels: ${{ steps.meta.outputs.labels }}
5885
cache-from: type=gha
5986
cache-to: type=gha,mode=max
6087

61-
- name: Test Docker image
88+
- name: Docker Scout CVE scanning
89+
if: github.event_name != 'pull_request'
90+
uses: docker/scout-action@v1
91+
with:
92+
command: cves
93+
image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
94+
only-severities: critical,high
95+
exit-code: false
96+
97+
- name: Summary
6298
run: |
63-
echo "✅ Docker image built successfully"
64-
echo "Image would be tagged as: ${{ env.IMAGE_NAME }}:test"
99+
echo "## Docker Build Summary 🐳" >> $GITHUB_STEP_SUMMARY
100+
echo "" >> $GITHUB_STEP_SUMMARY
101+
echo "**Image:** \`${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}\`" >> $GITHUB_STEP_SUMMARY
102+
echo "" >> $GITHUB_STEP_SUMMARY
103+
echo "**Tags built:**" >> $GITHUB_STEP_SUMMARY
104+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
105+
echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
106+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
107+
echo "" >> $GITHUB_STEP_SUMMARY
108+
if [ "${{ github.event_name }}" != "pull_request" ]; then
109+
echo "✅ **Images pushed to Docker Hub**" >> $GITHUB_STEP_SUMMARY
110+
echo "" >> $GITHUB_STEP_SUMMARY
111+
echo "Pull the latest image:" >> $GITHUB_STEP_SUMMARY
112+
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
113+
echo "docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_STEP_SUMMARY
114+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
115+
else
116+
echo "🔨 **PR build completed (not pushed)**" >> $GITHUB_STEP_SUMMARY
117+
fi

0 commit comments

Comments
 (0)