ci: unified workflow - single job, DOCKER_HOST, build+push on all events
CI / CI (pull_request) Failing after 2m38s
CI / CI (pull_request) Failing after 2m38s
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user