fix: validate registry credentials before docker login

Add credential validation step to catch missing secrets early with clear error message.
Use direct secret injection (not env vars) for better security.
Isolate docker config to /tmp/docker-config.
This commit is contained in:
Story Crater Bot
2026-09-06 23:33:22 -07:00
parent 4ad8a4f4a4
commit 97e8f0e613
+19 -12
View File
@@ -1,12 +1,14 @@
name: Build & Push Portfolio Image name: CI
on: on:
push: push:
branches: branches: [main]
- main
pull_request: pull_request:
branches: branches: [main]
- main
env:
REGISTRY: forgejo.riotpiao.com
IMAGE: forgejo.riotpiao.com/rock/portfolio
jobs: jobs:
test: test:
@@ -30,9 +32,6 @@ jobs:
needs: test needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/main' if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: node runs-on: node
env:
REGISTRY: forgejo.riotpiao.com
IMAGE: forgejo.riotpiao.com/rock/portfolio
steps: steps:
- name: Install Node.js and Docker - name: Install Node.js and Docker
run: | run: |
@@ -48,13 +47,21 @@ 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: Delete old latest image - name: Delete old latest image
run: | run: |