Skip to content

Commit f0e53a0

Browse files
Add Docker Hub credential validation to all workflows
- Add credential checks to PR validation workflow * Check if DOCKER_USERNAME and DOCKER_PASSWORD secrets exist * Continue validation even without credentials (expected for forks) * Include credential status in PR comments - Add mandatory credential checks to publishing workflows * docker-publish-master.yml: Fail if credentials missing * docker-publish-release.yml: Fail if credentials missing * publish.yml: Fail if credentials missing * Provide clear error messages for missing secrets - Fix Docker image loading in PR validation * Add 'load: true' to build-push-action for local testing * Verify image exists before running tests * Prevent 'image not found' errors during validation - Enhance local testing script (docker-test.sh) * Check for Docker Hub credentials in environment * Detect existing Docker login status * Provide helpful warnings for missing credentials - Update documentation * Document credential validation behavior * Explain differences between PR validation and publishing * Clarify requirements for external contributors This ensures proper credential management across all Docker workflows and provides clear feedback when credentials are missing or misconfigured.
1 parent 8393932 commit f0e53a0

File tree

6 files changed

+84
-3
lines changed

6 files changed

+84
-3
lines changed

.github/workflows/docker-build-pr.yml

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,25 @@ jobs:
4242
echo "git_dirty=${GIT_DIRTY}" >> $GITHUB_OUTPUT
4343
echo "short_sha=${GIT_SHA:0:7}" >> $GITHUB_OUTPUT
4444
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+
4557
- name: Build Docker image (single platform)
4658
uses: docker/build-push-action@v5
4759
with:
4860
context: .
4961
platforms: linux/amd64
5062
push: false
63+
load: true
5164
tags: ${{ env.IMAGE_NAME }}:pr-${{ github.event.number }}
5265
build-args: |
5366
GIT_SHA=${{ steps.meta.outputs.git_sha }}
@@ -58,13 +71,23 @@ jobs:
5871
- name: Test Docker image
5972
run: |
6073
echo "Testing Docker image functionality..."
61-
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+
6283
# Test help command
84+
echo "Testing --help command..."
6385
docker run --rm ${{ env.IMAGE_NAME }}:pr-${{ github.event.number }} --help
64-
86+
6587
# Test version output
88+
echo "Testing --version command..."
6689
docker run --rm ${{ env.IMAGE_NAME }}:pr-${{ github.event.number }} --version
67-
90+
6891
echo "✅ Docker image tests passed!"
6992
7093
- name: Build multi-platform image (validation only)
@@ -85,6 +108,10 @@ jobs:
85108
uses: actions/github-script@v7
86109
with:
87110
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+
88115
const output = `## 🐳 Docker Build Validation
89116
90117
✅ **Docker build successful!**
@@ -95,11 +122,14 @@ jobs:
95122
96123
**Git SHA:** \`${{ steps.meta.outputs.git_sha }}\`
97124
125+
**Docker Hub Status:** ${credentialsStatus}
126+
98127
**Image details:**
99128
- Single platform: \`${{ env.IMAGE_NAME }}:pr-${{ github.event.number }}\`
100129
- Multi-platform: \`${{ env.IMAGE_NAME }}:pr-${{ github.event.number }}-multiplatform\`
101130
102131
**Tests performed:**
132+
- ✅ Docker Hub credentials check
103133
- ✅ Help command execution
104134
- ✅ Version output validation
105135
- ✅ Multi-platform build validation

.github/workflows/docker-publish-master.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ jobs:
3131
- name: Set up Docker Buildx
3232
uses: docker/setup-buildx-action@v3
3333

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+
3443
- name: Log in to Docker Hub
3544
uses: docker/login-action@v3
3645
with:

.github/workflows/docker-publish-release.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ jobs:
2424
- name: Set up Docker Buildx
2525
uses: docker/setup-buildx-action@v3
2626

27+
- name: Check Docker Hub credentials
28+
run: |
29+
if [[ -z "${{ secrets.DOCKER_USERNAME }}" || -z "${{ secrets.DOCKER_PASSWORD }}" ]]; then
30+
echo "❌ Docker Hub credentials not configured!"
31+
echo "Please set DOCKER_USERNAME and DOCKER_PASSWORD secrets in repository settings."
32+
exit 1
33+
fi
34+
echo "✅ Docker Hub credentials are configured"
35+
2736
- name: Log in to Docker Hub
2837
uses: docker/login-action@v3
2938
with:

.github/workflows/publish.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ jobs:
4747
- name: Set up Docker Buildx
4848
uses: docker/setup-buildx-action@v3
4949

50+
- name: Check Docker Hub credentials
51+
run: |
52+
if [[ -z "${{ secrets.DOCKER_USERNAME }}" || -z "${{ secrets.DOCKER_PASSWORD }}" ]]; then
53+
echo "❌ Docker Hub credentials not configured!"
54+
echo "Please set DOCKER_USERNAME and DOCKER_PASSWORD secrets in repository settings."
55+
exit 1
56+
fi
57+
echo "✅ Docker Hub credentials are configured"
58+
5059
- name: Log in to Docker Hub
5160
uses: docker/login-action@v3
5261
with:

DOCKER_SETUP.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ To enable automated Docker publishing, you need to configure the following secre
2727

2828
⚠️ **Important**: Use an access token, not your Docker Hub password, for better security.
2929

30+
### Credential Validation
31+
32+
All Docker publishing workflows include automatic credential validation:
33+
34+
- **PR Validation**: Checks if credentials are available but continues without them (expected for forks)
35+
- **Master/Release Publishing**: **Requires** credentials and fails if not configured
36+
- **Local Testing**: Warns if credentials are missing but continues validation
37+
38+
This ensures that:
39+
- External contributors can still validate Docker builds in PRs
40+
- Publishing workflows fail fast if credentials are misconfigured
41+
- Local development works regardless of credential status
42+
3043
## 🚀 Automated Publishing
3144

3245
Once secrets are configured, Docker images will be automatically published:

docker-test.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ FULL_IMAGE_NAME="${IMAGE_NAME}:${TAG}"
3636

3737
print_info "Starting Docker validation tests..."
3838

39+
# Step 0: Check Docker Hub credentials (optional for local testing)
40+
print_step "Checking Docker Hub credentials..."
41+
if [[ -n "$DOCKER_USERNAME" && -n "$DOCKER_PASSWORD" ]]; then
42+
print_info "✅ Docker Hub credentials found in environment"
43+
elif docker info | grep -q "Username:"; then
44+
print_info "✅ Already logged in to Docker Hub"
45+
else
46+
print_warning "⚠️ Docker Hub credentials not found"
47+
print_info "Set DOCKER_USERNAME and DOCKER_PASSWORD environment variables or run 'docker login' for publishing"
48+
fi
49+
3950
# Step 1: Build the image
4051
print_step "Building Docker image..."
4152
if ./docker-build.sh -n "$IMAGE_NAME" -t "$TAG"; then

0 commit comments

Comments
 (0)