From c5b3e969a7e8f0a35fc0d0a8297a5614052918e9 Mon Sep 17 00:00:00 2001 From: Matthias Blaser Date: Tue, 14 Jan 2025 13:36:18 +0100 Subject: [PATCH] Cleanup container build --- .dockerignore | 4 +++ .github/workflows/build.yml | 50 +++++++++++++++++++++---------------- 2 files changed, 32 insertions(+), 22 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9161bb8 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.docker +.github +.venv +test_data diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e4dfe8e..7542700 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,43 +7,49 @@ on: - cron: '15 12 * * 1' env: - QUAY_IMAGE: quay.io/zebbra/netbox-init - CONTAINER_PLATFORMS: "linux/amd64,linux/arm64" - TAG: latest + REGISTRY: quay.io + IMAGE: zebbra/netbox-init + PLATFORMS: "linux/amd64,linux/arm64" jobs: build: - runs-on: ubuntu-latest + runs-on: hetzner + permissions: + contents: read + id-token: write steps: - name: Checkout uses: actions/checkout@v4 - # https://github.com/docker/setup-qemu-action - name: Set up QEMU uses: docker/setup-qemu-action@v3 - # https://github.com/docker/setup-buildx-action - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Login to quay.io Container Registry + - name: Generate image tags + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ env.REGISTRY }}/${{ env.IMAGE }} + tags: | + type=raw, value=latest + type=sha + + - name: Login to container registry uses: docker/login-action@v3 with: - registry: quay.io + registry: ${{ env.REGISTRY }} username: ${{ secrets.QUAY_USERNAME }} password: ${{ secrets.QUAY_PASSWORD }} - - name: Inject slug/short variables - uses: rlespinasse/github-slug-action@v4 - - - name: Generate image tag - id: tag - run: echo "tag=$(date +%Y%m%d%H%M)-${{ env.GITHUB_SHA_SHORT }}" >> "$GITHUB_OUTPUT" - - - name: Build - run: > - docker buildx build --pull --push - -t ${{ env.QUAY_IMAGE }}:${{ env.TAG }} - -t ${{ env.QUAY_IMAGE }}:${{ steps.tag.outputs.tag }} - --platform ${{ env.CONTAINER_PLATFORMS }} - . + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + cache-from: type=gha + cache-to: type=gha,mode=max + platforms: ${{ env.PLATFORMS }} + tags: ${{ steps.meta.outputs.tags }}