fix: validate registry credentials before docker login
CI / Test (pull_request) Successful in 2m8s
CI / Build & Push Image (pull_request) Skipped

Problem: Registry login fails silently if secrets aren't configured
- Empty FORGEJO_REGISTRY_USER/TOKEN → docker login hangs/fails
- No clear error message about missing credentials

Solution: Add validation step that checks credentials exist
- Fails early with clear error if secrets missing
- Shows how to configure in repo settings
- Uses direct secret injection (not via env vars)
- Isolates docker config to /tmp/docker-config

Result: CI will fail fast with actionable error if credentials missing
This commit is contained in:
2026-09-06 23:32:42 -07:00
parent 1858dc1606
commit a940e84970
+17 -9
View File
@@ -49,27 +49,35 @@ jobs:
SHORT_SHA=$(git rev-parse --short HEAD) SHORT_SHA=$(git rev-parse --short HEAD)
echo "short_sha=${SHORT_SHA}" >> $GITHUB_OUTPUT echo "short_sha=${SHORT_SHA}" >> $GITHUB_OUTPUT
- name: Validate registry credentials
run: |
if [ -z "${{ secrets.FORGEJO_REGISTRY_USER }}" ] || [ -z "${{ secrets.FORGEJO_REGISTRY_TOKEN }}" ]; then
echo "❌ ERROR: Registry secrets not configured"
echo "Set FORGEJO_REGISTRY_USER and FORGEJO_REGISTRY_TOKEN in repo settings"
exit 1
fi
echo "✓ Registry credentials configured"
- name: Registry login - name: Registry login
run: | run: |
echo "${REGISTRY_TOKEN}" | docker login "${REGISTRY}" \ echo "${{ secrets.FORGEJO_REGISTRY_TOKEN }}" | docker login "${{ env.REGISTRY }}" \
--username "${REGISTRY_USER}" --password-stdin --username "${{ secrets.FORGEJO_REGISTRY_USER }}" --password-stdin
env: env:
REGISTRY_USER: ${{ secrets.FORGEJO_REGISTRY_USER }} DOCKER_CONFIG: /tmp/docker-config
REGISTRY_TOKEN: ${{ secrets.FORGEJO_REGISTRY_TOKEN }}
- name: Build Docker image - name: Build Docker image
run: | run: |
docker build --no-cache \ docker build --no-cache \
-t "${IMAGE}:${{ steps.sha.outputs.short_sha }}" \ -t "${{ env.IMAGE }}:${{ steps.sha.outputs.short_sha }}" \
-t "${IMAGE}:latest" \ -t "${{ env.IMAGE }}:latest" \
-f Dockerfile \ -f Dockerfile \
. .
- name: Push Docker image - name: Push Docker image
run: | run: |
docker push "${IMAGE}:${{ steps.sha.outputs.short_sha }}" docker push "${{ env.IMAGE }}:${{ steps.sha.outputs.short_sha }}"
docker push "${IMAGE}:latest" docker push "${{ env.IMAGE }}:latest"
echo "✓ Image pushed: ${IMAGE}:${{ steps.sha.outputs.short_sha }}" echo "✓ Image pushed: ${{ env.IMAGE }}:${{ steps.sha.outputs.short_sha }}"
- name: Prune unused images - name: Prune unused images
run: docker image prune -a --force 2>&1 | tail -3 || true run: docker image prune -a --force 2>&1 | tail -3 || true