ci: add automatic Docker image push to GHCR on main
This commit is contained in:
1 parent
914563e883
commit
81eb8950dd
1 file changed
+26
-15
+26
-15
@@ -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
|
||||
Reference in new issue
Block a user