From df13d5b30bc2406497df5f658bb014327d1b35b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Tue, 23 Aug 2022 10:06:18 +0200 Subject: [PATCH] Change: Split building build and production container images The build image really rarely needs a rebuild. Therefore split this job into an own workflow and only rebuild if the corresponding dockerfile or workflow has changed. --- .github/workflows/build-container.yml | 65 +++++++++++++++++++++++++++ .github/workflows/container.yml | 49 +------------------- 2 files changed, 66 insertions(+), 48 deletions(-) create mode 100644 .github/workflows/build-container.yml diff --git a/.github/workflows/build-container.yml b/.github/workflows/build-container.yml new file mode 100644 index 000000000..d600ce85e --- /dev/null +++ b/.github/workflows/build-container.yml @@ -0,0 +1,65 @@ +name: Build Container Image Builds + +on: + push: + branches: [ main, stable, oldstable ] + tags: ["v*"] + paths: + - .github/workflows/build-container.yml + - .docker/build.Dockerfile + pull_request: + branches: [ main, stable, oldstable ] + paths: + - .github/workflows/build-container.yml + - .docker/build.Dockerfile + workflow_dispatch: + schedule: + # rebuild image every sunday + - cron: "0 0 * * 0" + +jobs: + build: + name: Build Images + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup container meta information + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ github.repository }}-build + labels: | + org.opencontainers.image.vendor=Greenbone + org.opencontainers.image.base.name=debian:stable-slim + flavor: latest=false # no latest container tag for git tags + tags: | + # create container tag for git tags + type=ref,event=tag + type=ref,event=pr + # use latest for stable branch + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'stable') }} + type=raw,value=stable,enable=${{ github.ref == format('refs/heads/{0}', 'stable') }} + type=raw,value=oldstable,enable=${{ github.ref == format('refs/heads/{0}', 'oldstable') }} + # use unstable for main branch + type=raw,value=unstable,enable={{is_default_branch}} + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to DockerHub + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - run: echo "Build and push ${{ steps.container.outputs.image-tags }}" + - name: Build and push + uses: docker/build-push-action@v3 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + file: .docker/build.Dockerfile + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index a556df4f3..0a99fe27d 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -9,56 +9,9 @@ on: workflow_dispatch: jobs: - build: - name: Build Images - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Setup container meta information - id: meta - uses: docker/metadata-action@v4 - with: - images: ${{ github.repository }}-build - labels: | - org.opencontainers.image.vendor=Greenbone - org.opencontainers.image.base.name=debian/stable-slim - flavor: latest=false # no latest container tag for git tags - tags: | - # create container tag for git tags - type=ref,event=tag - type=ref,event=pr - # use latest for stable branch - type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'stable') }} - type=raw,value=stable,enable=${{ github.ref == format('refs/heads/{0}', 'stable') }} - type=raw,value=oldstable,enable=${{ github.ref == format('refs/heads/{0}', 'oldstable') }} - # use unstable for main branch - type=raw,value=unstable,enable={{is_default_branch}} - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - name: Login to DockerHub - if: github.event_name != 'pull_request' - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - run: echo "Build and push ${{ steps.container.outputs.image-tags }}" - - name: Build and push - uses: docker/build-push-action@v3 - with: - context: . - push: ${{ github.event_name != 'pull_request' }} - file: .docker/build.Dockerfile - platforms: linux/amd64,linux/arm64 - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - production: name: Production Images runs-on: ubuntu-latest - needs: build steps: - name: Checkout repository uses: actions/checkout@v3 @@ -69,7 +22,7 @@ jobs: images: ${{ github.repository }} labels: | org.opencontainers.image.vendor=Greenbone - org.opencontainers.image.base.name=debian/stable-slim + org.opencontainers.image.base.name=debian:stable-slim flavor: latest=false # no latest container tag for git tags tags: | # create container tag for git tags