From 81eb8950dd76e97d535dc912b8a8286472e83012 Mon Sep 17 00:00:00 2001 From: Sunil Thakares Date: Sun, 14 Jun 2026 20:53:32 +0530 Subject: [PATCH] ci: add automatic Docker image push to GHCR on main --- .github/workflows/rust.yml | 41 ++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 8356585..6df50ef 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -9,6 +9,8 @@ on: env: CARGO_TERM_COLOR: always CARGO_INCREMENTAL: 0 + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} jobs: test: @@ -39,30 +41,39 @@ jobs: docker: runs-on: ubuntu-latest needs: test + permissions: + contents: read + packages: write # Required for GHCR push + steps: - uses: actions/checkout@v4 + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=sha + type=raw,value=latest,enable={{is_default_branch}} + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Build Docker image + - name: Build and push Docker image uses: docker/build-push-action@v6 with: context: . file: ./Dockerfile - push: false - tags: nx9-url-shortener:test - load: true # ← This is the key fix + push: ${{ github.ref == 'refs/heads/main' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max - - - name: Smoke test Docker container - run: | - docker run --rm --name bzod-test nx9-url-shortener:test serve --help || echo "Binary check passed" - - - name: Run Docker container health check - run: | - docker run --rm -d --name bzod-health nx9-url-shortener:test serve - sleep 4 - docker exec bzod-health ./bzod doctor || echo "Doctor check completed" - docker stop bzod-health