Author SHA1 Message Date
Story Crater Bot bcd964dcca ci: unified workflow - single job, DOCKER_HOST, build+push on all events
CI / CI (pull_request) Failing after 2m38s
2026-09-07 13:47:12 -07:00
+14 -84
View File
@@ -5,18 +5,22 @@ on:
branches: [main] branches: [main]
pull_request: pull_request:
branches: [main] branches: [main]
workflow_dispatch:
env: env:
REGISTRY: forgejo.riotpiao.com REGISTRY: forgejo.riotpiao.com
IMAGE: forgejo.riotpiao.com/rock/portfolio IMAGE: forgejo.riotpiao.com/rock/portfolio
DOCKER_HOST: tcp://localhost:2375
jobs: jobs:
test: ci:
name: Test name: CI
runs-on: node runs-on: node
steps: steps:
- name: Install Node.js for actions runtime - name: Install Node.js and Docker
run: apt-get update && apt-get install -y nodejs run: |
apt-get update
apt-get install -y nodejs docker.io
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
@@ -27,67 +31,9 @@ jobs:
- name: Run tests - name: Run tests
run: npm test -- --run 2>&1 || echo "Tests completed" 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 - name: Get short SHA
id: sha id: sha
run: | run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
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 }}
- name: Registry login - name: Registry login
run: | run: |
@@ -97,33 +43,17 @@ jobs:
REGISTRY_USER: ${{ secrets.FORGEJO_REGISTRY_USER }} REGISTRY_USER: ${{ secrets.FORGEJO_REGISTRY_USER }}
REGISTRY_TOKEN: ${{ secrets.FORGEJO_REGISTRY_TOKEN }} REGISTRY_TOKEN: ${{ secrets.FORGEJO_REGISTRY_TOKEN }}
- name: Delete old latest image - name: Build Docker 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
run: | run: |
docker build --no-cache \ docker build --no-cache \
--build-arg COMMIT_SHA=${{ steps.sha.outputs.short_sha }} \
-t "${IMAGE}:${{ 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: | run: |
docker push "${IMAGE}:${{ steps.sha.outputs.short_sha }}" docker push "${IMAGE}:${{ steps.sha.outputs.short_sha }}"
docker push "${IMAGE}:latest" 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 - name: Prune unused images
run: | run: docker image prune -a --force 2>&1 | tail -3 || true
docker image prune -a --force 2>&1 | tail -3 || true