From bcd964dcca1a6a349b46a30d17a099f78f12c302 Mon Sep 17 00:00:00 2001 From: Story Crater Bot <19826264+Riotpiaole@users.noreply.github.com> Date: Mon, 7 Sep 2026 13:47:12 -0700 Subject: [PATCH] ci: unified workflow - single job, DOCKER_HOST, build+push on all events --- .gitea/workflows/build-push.yml | 98 +++++---------------------------- 1 file changed, 14 insertions(+), 84 deletions(-) diff --git a/.gitea/workflows/build-push.yml b/.gitea/workflows/build-push.yml index 477e9d0..4f5a3fd 100644 --- a/.gitea/workflows/build-push.yml +++ b/.gitea/workflows/build-push.yml @@ -5,18 +5,22 @@ on: branches: [main] pull_request: branches: [main] + workflow_dispatch: env: REGISTRY: forgejo.riotpiao.com IMAGE: forgejo.riotpiao.com/rock/portfolio + DOCKER_HOST: tcp://localhost:2375 jobs: - test: - name: Test + ci: + name: CI runs-on: node steps: - - name: Install Node.js for actions runtime - run: apt-get update && apt-get install -y nodejs + - name: Install Node.js and Docker + run: | + apt-get update + apt-get install -y nodejs docker.io - name: Checkout code uses: actions/checkout@v4 @@ -27,67 +31,9 @@ jobs: - name: Run tests run: npm test -- --run 2>&1 || echo "Tests completed" - build-push: - name: Build & Push Image - needs: test - if: github.event_name == 'push' && github.ref == 'refs/heads/main' - runs-on: node - env: - DOCKER_HOST: tcp://localhost:2376 - DOCKER_TLS_VERIFY: "1" - DOCKER_CERT_PATH: /docker-certs/client - steps: - - name: Install Node.js and Docker - run: | - apt-get update - apt-get install -y nodejs docker.io - - - name: Checkout code - uses: actions/checkout@v4 - - name: Get short SHA id: sha - run: | - SHORT_SHA=$(git rev-parse --short HEAD) - echo "short_sha=${SHORT_SHA}" >> $GITHUB_OUTPUT - - - name: Pre-verify Docker and Registry - run: | - echo "=== Docker Setup Verification ===" - echo "✓ DOCKER_HOST: ${DOCKER_HOST}" - echo "✓ DOCKER_TLS_VERIFY: ${DOCKER_TLS_VERIFY}" - echo "✓ DOCKER_CERT_PATH: ${DOCKER_CERT_PATH}" - echo "" - echo "=== Docker Daemon Check ===" - if ! docker version &>/dev/null; then - echo "❌ FAILED: Docker daemon not accessible at ${DOCKER_HOST}" - exit 1 - fi - echo "✓ Docker daemon is running" - docker version --format "Engine: {{.Server.Version}}" - echo "" - echo "=== Registry Credentials Check ===" - if [ -z "${REGISTRY_USER}" ] || [ -z "${REGISTRY_TOKEN}" ]; then - echo "❌ FAILED: FORGEJO_REGISTRY_USER or FORGEJO_REGISTRY_TOKEN not set" - exit 1 - fi - echo "✓ Registry credentials are set" - echo "" - echo "=== Dockerfile Check ===" - if [ ! -f Dockerfile ]; then - echo "❌ FAILED: Dockerfile not found" - exit 1 - fi - echo "✓ Dockerfile exists" - echo "" - echo "=== Image Tag Check ===" - echo "✓ IMAGE tag will be: ${IMAGE}:${{ steps.sha.outputs.short_sha }}" - echo "✓ Latest tag will be: ${IMAGE}:latest" - echo "" - echo "=== All pre-checks passed ===" - env: - REGISTRY_USER: ${{ secrets.FORGEJO_REGISTRY_USER }} - REGISTRY_TOKEN: ${{ secrets.FORGEJO_REGISTRY_TOKEN }} + run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT - name: Registry login run: | @@ -97,33 +43,17 @@ jobs: REGISTRY_USER: ${{ secrets.FORGEJO_REGISTRY_USER }} REGISTRY_TOKEN: ${{ secrets.FORGEJO_REGISTRY_TOKEN }} - - name: Delete old latest image - run: | - # Delete old :latest tag from Forgejo registry via API - curl -s -X DELETE \ - -u "${REGISTRY_USER}:${REGISTRY_TOKEN}" \ - "https://${REGISTRY}/v2/rock/portfolio/manifests/$(curl -s -H 'Accept: application/vnd.oci.image.index.v1+json' -u "${REGISTRY_USER}:${REGISTRY_TOKEN}" "https://${REGISTRY}/v2/rock/portfolio/manifests/latest" | head -1 | grep -o 'sha256:[a-f0-9]*' || true)" \ - 2>/dev/null || echo "No old latest to delete" - env: - REGISTRY_USER: ${{ secrets.FORGEJO_REGISTRY_USER }} - REGISTRY_TOKEN: ${{ secrets.FORGEJO_REGISTRY_TOKEN }} - - - name: Build image + - name: Build Docker image run: | docker build --no-cache \ - --build-arg COMMIT_SHA=${{ steps.sha.outputs.short_sha }} \ -t "${IMAGE}:${{ steps.sha.outputs.short_sha }}" \ - -t "${IMAGE}:latest" \ - . + -t "${IMAGE}:latest" . - - name: Push image + - name: Push Docker image run: | docker push "${IMAGE}:${{ steps.sha.outputs.short_sha }}" docker push "${IMAGE}:latest" - echo "✓ Image pushed: ${IMAGE}:${{ steps.sha.outputs.short_sha }}" + echo "✓ Pushed: ${IMAGE}:${{ steps.sha.outputs.short_sha }}" - 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