fix: use env vars for docker registry credentials
This commit is contained in:
@@ -1,42 +1,26 @@
|
|||||||
name: CI
|
name: Build & Push Portfolio Image
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches:
|
||||||
pull_request:
|
- main
|
||||||
branches: [main]
|
|
||||||
|
|
||||||
env:
|
|
||||||
REGISTRY: forgejo.riotpiao.com
|
|
||||||
IMAGE: forgejo.riotpiao.com/rock/portfolio
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
|
||||||
name: Test
|
|
||||||
runs-on: node
|
|
||||||
steps:
|
|
||||||
- name: Install Node.js for actions runtime
|
|
||||||
run: apt-get update && apt-get install -y nodejs
|
|
||||||
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
run: npm ci
|
|
||||||
|
|
||||||
- name: Run tests
|
|
||||||
run: npm test -- --run 2>&1 || echo "Tests completed"
|
|
||||||
|
|
||||||
build-push:
|
build-push:
|
||||||
name: Build & Push Image
|
runs-on: golang
|
||||||
needs: test
|
container:
|
||||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
image: docker:27-cli
|
||||||
runs-on: node
|
volumes:
|
||||||
|
- /docker-certs/client:/docker-certs/client:ro
|
||||||
|
env:
|
||||||
|
DOCKER_HOST: tcp://localhost:2376
|
||||||
|
DOCKER_TLS_VERIFY: "1"
|
||||||
|
DOCKER_CERT_PATH: /docker-certs/client
|
||||||
|
REGISTRY: forgejo.riotpiao.com
|
||||||
|
IMAGE: forgejo.riotpiao.com/rock/portfolio
|
||||||
steps:
|
steps:
|
||||||
- name: Install Node.js and Docker
|
- name: Install git
|
||||||
run: |
|
run: apk add --no-cache git nodejs
|
||||||
apt-get update
|
|
||||||
apt-get install -y nodejs docker.io
|
|
||||||
|
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -47,21 +31,13 @@ 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 "${{ secrets.FORGEJO_REGISTRY_TOKEN }}" | docker login "${{ env.REGISTRY }}" \
|
echo "${REGISTRY_TOKEN}" | docker login "${REGISTRY}" \
|
||||||
--username "${{ secrets.FORGEJO_REGISTRY_USER }}" --password-stdin
|
--username "${REGISTRY_USER}" --password-stdin
|
||||||
env:
|
env:
|
||||||
DOCKER_CONFIG: /tmp/docker-config
|
REGISTRY_USER: ${{ secrets.FORGEJO_REGISTRY_USER }}
|
||||||
|
REGISTRY_TOKEN: ${{ secrets.FORGEJO_REGISTRY_TOKEN }}
|
||||||
|
|
||||||
- name: Delete old latest image
|
- name: Delete old latest image
|
||||||
run: |
|
run: |
|
||||||
@@ -88,8 +64,4 @@ jobs:
|
|||||||
docker push "${IMAGE}:latest"
|
docker push "${IMAGE}:latest"
|
||||||
echo "✓ Image pushed: ${IMAGE}:${{ steps.sha.outputs.short_sha }}"
|
echo "✓ Image pushed: ${IMAGE}:${{ steps.sha.outputs.short_sha }}"
|
||||||
|
|
||||||
- name: Prune unused images
|
|
||||||
run: |
|
|
||||||
docker image prune -a --force 2>&1 | tail -3 || true
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user