Skip to content

Commit 4c8d3c8

Browse files
Merge pull request #31 from redis-performance/docker
Docker publish setup
2 parents 9117041 + f0e53a0 commit 4c8d3c8

File tree

13 files changed

+1319
-11
lines changed

13 files changed

+1319
-11
lines changed

.dockerignore

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Compiled binaries
2+
pubsub-sub-bench
3+
*.exe
4+
*.exe~
5+
*.dll
6+
*.so
7+
*.dylib
8+
9+
# Test binaries
10+
*.test
11+
12+
# Coverage files
13+
coverage.txt
14+
*.out
15+
16+
# Profiling files
17+
*.pprof
18+
cpuprofile-extended.pprof
19+
v10.pprof
20+
v6.pprof
21+
22+
# Log files
23+
*.log
24+
25+
# OS generated files
26+
.DS_Store
27+
.DS_Store?
28+
._*
29+
.Spotlight-V100
30+
.Trashes
31+
ehthumbs.db
32+
Thumbs.db
33+
34+
# IDE files
35+
.idea/
36+
.vscode/
37+
.project
38+
*.swp
39+
*.swo
40+
*~
41+
42+
# Git files
43+
.git/
44+
.gitignore
45+
46+
# CI/CD files
47+
.github/
48+
49+
# Documentation
50+
README.md
51+
LICENSE
52+
53+
# JavaScript/Node.js directories (not needed for Go build)
54+
js/
55+
node_modules/
56+
package-lock.json
57+
58+
# Distribution directories
59+
dist/
60+
out/
61+
62+
# Temporary files
63+
tmp/
64+
temp/
65+
66+
# Archive files
67+
*.7z
68+
*.dmg
69+
*.gz
70+
*.iso
71+
*.jar
72+
*.rar
73+
*.tar
74+
*.zip
75+
*.bz2
76+
77+
# Database files
78+
*.sql
79+
*.sqlite
80+
81+
# Makefile (we're using Docker build instead)
82+
Makefile
83+
84+
# Docker files themselves
85+
Dockerfile*
86+
.dockerignore
87+
docker-compose*.yml
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
name: Docker Build - PR Validation
2+
3+
on:
4+
pull_request:
5+
branches: [master, main]
6+
paths:
7+
- 'Dockerfile'
8+
- '.dockerignore'
9+
- 'docker-build.sh'
10+
- 'docker-run.sh'
11+
- 'subscriber.go'
12+
- 'go.mod'
13+
- 'go.sum'
14+
- 'Makefile'
15+
- '.github/workflows/docker-build-pr.yml'
16+
17+
env:
18+
IMAGE_NAME: pubsub-sub-bench-pr
19+
20+
jobs:
21+
docker-build-test:
22+
runs-on: ubuntu-latest
23+
permissions:
24+
contents: read
25+
pull-requests: write
26+
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0 # Fetch full history for Git info
32+
33+
- name: Set up Docker Buildx
34+
uses: docker/setup-buildx-action@v3
35+
36+
- name: Extract Git metadata
37+
id: meta
38+
run: |
39+
GIT_SHA=$(git rev-parse HEAD)
40+
GIT_DIRTY=$(git diff --no-ext-diff 2>/dev/null | wc -l)
41+
echo "git_sha=${GIT_SHA}" >> $GITHUB_OUTPUT
42+
echo "git_dirty=${GIT_DIRTY}" >> $GITHUB_OUTPUT
43+
echo "short_sha=${GIT_SHA:0:7}" >> $GITHUB_OUTPUT
44+
45+
- name: Check Docker Hub credentials
46+
id: check_credentials
47+
run: |
48+
if [[ -n "${{ secrets.DOCKER_USERNAME }}" && -n "${{ secrets.DOCKER_PASSWORD }}" ]]; then
49+
echo "credentials_available=true" >> $GITHUB_OUTPUT
50+
echo "✅ Docker Hub credentials are configured"
51+
else
52+
echo "credentials_available=false" >> $GITHUB_OUTPUT
53+
echo "⚠️ Docker Hub credentials not configured (DOCKER_USERNAME and/or DOCKER_PASSWORD secrets missing)"
54+
echo "This is expected for forks and external PRs. Docker build validation will still work."
55+
fi
56+
57+
- name: Build Docker image (single platform)
58+
uses: docker/build-push-action@v5
59+
with:
60+
context: .
61+
platforms: linux/amd64
62+
push: false
63+
load: true
64+
tags: ${{ env.IMAGE_NAME }}:pr-${{ github.event.number }}
65+
build-args: |
66+
GIT_SHA=${{ steps.meta.outputs.git_sha }}
67+
GIT_DIRTY=${{ steps.meta.outputs.git_dirty }}
68+
cache-from: type=gha
69+
cache-to: type=gha,mode=max
70+
71+
- name: Test Docker image
72+
run: |
73+
echo "Testing Docker image functionality..."
74+
75+
# Verify image was built
76+
if docker images | grep -q "${{ env.IMAGE_NAME }}"; then
77+
echo "✅ Docker image built successfully"
78+
else
79+
echo "❌ Docker image not found"
80+
exit 1
81+
fi
82+
83+
# Test help command
84+
echo "Testing --help command..."
85+
docker run --rm ${{ env.IMAGE_NAME }}:pr-${{ github.event.number }} --help
86+
87+
# Test version output
88+
echo "Testing --version command..."
89+
docker run --rm ${{ env.IMAGE_NAME }}:pr-${{ github.event.number }} --version
90+
91+
echo "✅ Docker image tests passed!"
92+
93+
- name: Build multi-platform image (validation only)
94+
uses: docker/build-push-action@v5
95+
with:
96+
context: .
97+
platforms: linux/amd64,linux/arm64
98+
push: false
99+
tags: ${{ env.IMAGE_NAME }}:pr-${{ github.event.number }}-multiplatform
100+
build-args: |
101+
GIT_SHA=${{ steps.meta.outputs.git_sha }}
102+
GIT_DIRTY=${{ steps.meta.outputs.git_dirty }}
103+
cache-from: type=gha
104+
cache-to: type=gha,mode=max
105+
106+
- name: Generate PR comment
107+
if: github.event_name == 'pull_request'
108+
uses: actions/github-script@v7
109+
with:
110+
script: |
111+
const credentialsStatus = '${{ steps.check_credentials.outputs.credentials_available }}' === 'true'
112+
? '✅ Docker Hub credentials configured'
113+
: '⚠️ Docker Hub credentials not configured (expected for forks)';
114+
115+
const output = `## 🐳 Docker Build Validation
116+
117+
✅ **Docker build successful!**
118+
119+
**Platforms tested:**
120+
- ✅ linux/amd64 (built and tested)
121+
- ✅ linux/arm64 (build validated)
122+
123+
**Git SHA:** \`${{ steps.meta.outputs.git_sha }}\`
124+
125+
**Docker Hub Status:** ${credentialsStatus}
126+
127+
**Image details:**
128+
- Single platform: \`${{ env.IMAGE_NAME }}:pr-${{ github.event.number }}\`
129+
- Multi-platform: \`${{ env.IMAGE_NAME }}:pr-${{ github.event.number }}-multiplatform\`
130+
131+
**Tests performed:**
132+
- ✅ Docker Hub credentials check
133+
- ✅ Help command execution
134+
- ✅ Version output validation
135+
- ✅ Multi-platform build validation
136+
137+
The Docker image is ready for deployment! 🚀`;
138+
139+
github.rest.issues.createComment({
140+
issue_number: context.issue.number,
141+
owner: context.repo.owner,
142+
repo: context.repo.repo,
143+
body: output
144+
});
145+
146+
- name: Clean up test images
147+
if: always()
148+
run: |
149+
docker rmi ${{ env.IMAGE_NAME }}:pr-${{ github.event.number }} || true
150+
echo "Cleanup completed"
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Docker Publish - Master
2+
3+
on:
4+
push:
5+
branches: [master]
6+
paths-ignore:
7+
- '**.md'
8+
- 'docs/**'
9+
- 'js/**'
10+
- '.github/workflows/unit-tests.yml'
11+
- '.github/workflows/codeql-analysis.yml'
12+
- '.github/workflows/release-drafter.yml'
13+
14+
env:
15+
REGISTRY: docker.io
16+
IMAGE_NAME: filipe958/pubsub-sub-bench
17+
18+
jobs:
19+
docker-publish:
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
23+
packages: write
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0 # Fetch full history for Git info
30+
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v3
33+
34+
- name: Check Docker Hub credentials
35+
run: |
36+
if [[ -z "${{ secrets.DOCKER_USERNAME }}" || -z "${{ secrets.DOCKER_PASSWORD }}" ]]; then
37+
echo "❌ Docker Hub credentials not configured!"
38+
echo "Please set DOCKER_USERNAME and DOCKER_PASSWORD secrets in repository settings."
39+
exit 1
40+
fi
41+
echo "✅ Docker Hub credentials are configured"
42+
43+
- name: Log in to Docker Hub
44+
uses: docker/login-action@v3
45+
with:
46+
registry: ${{ env.REGISTRY }}
47+
username: ${{ secrets.DOCKER_USERNAME }}
48+
password: ${{ secrets.DOCKER_PASSWORD }}
49+
50+
- name: Extract Git metadata
51+
id: meta
52+
run: |
53+
GIT_SHA=$(git rev-parse HEAD)
54+
GIT_DIRTY=$(git diff --no-ext-diff 2>/dev/null | wc -l)
55+
echo "git_sha=${GIT_SHA}" >> $GITHUB_OUTPUT
56+
echo "git_dirty=${GIT_DIRTY}" >> $GITHUB_OUTPUT
57+
echo "short_sha=${GIT_SHA:0:7}" >> $GITHUB_OUTPUT
58+
59+
- name: Extract metadata for Docker
60+
id: docker_meta
61+
uses: docker/metadata-action@v5
62+
with:
63+
images: ${{ env.IMAGE_NAME }}
64+
tags: |
65+
type=raw,value=latest
66+
type=raw,value=master-{{sha}}
67+
type=raw,value=master-{{date 'YYYYMMDD-HHmmss'}}
68+
69+
- name: Build and push Docker image
70+
uses: docker/build-push-action@v5
71+
with:
72+
context: .
73+
platforms: linux/amd64,linux/arm64
74+
push: true
75+
tags: ${{ steps.docker_meta.outputs.tags }}
76+
labels: ${{ steps.docker_meta.outputs.labels }}
77+
build-args: |
78+
GIT_SHA=${{ steps.meta.outputs.git_sha }}
79+
GIT_DIRTY=${{ steps.meta.outputs.git_dirty }}
80+
cache-from: type=gha
81+
cache-to: type=gha,mode=max
82+
83+
- name: Generate summary
84+
run: |
85+
echo "## 🐳 Docker Image Published" >> $GITHUB_STEP_SUMMARY
86+
echo "" >> $GITHUB_STEP_SUMMARY
87+
echo "**Repository:** \`${{ env.IMAGE_NAME }}\`" >> $GITHUB_STEP_SUMMARY
88+
echo "**Tags:**" >> $GITHUB_STEP_SUMMARY
89+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
90+
echo "${{ steps.docker_meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
91+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
92+
echo "" >> $GITHUB_STEP_SUMMARY
93+
echo "**Git SHA:** \`${{ steps.meta.outputs.git_sha }}\`" >> $GITHUB_STEP_SUMMARY
94+
echo "" >> $GITHUB_STEP_SUMMARY
95+
echo "**Usage:**" >> $GITHUB_STEP_SUMMARY
96+
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
97+
echo "docker run --rm ${{ env.IMAGE_NAME }}:latest --help" >> $GITHUB_STEP_SUMMARY
98+
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
99+
echo "" >> $GITHUB_STEP_SUMMARY
100+
echo "🔗 [View on Docker Hub](https://hub.docker.com/r/filipe958/pubsub-sub-bench)" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)