From 70681997f970e54b7a86deca95c4dee76afc9082 Mon Sep 17 00:00:00 2001 From: "Tomi P. Hakala" Date: Thu, 16 Jan 2025 08:05:36 +0200 Subject: [PATCH] chore: enhance GitHub Actions workflow for Docker image builds - Added concurrency configuration to manage multiple pushes and prevent overlapping builds. - Implemented a scheduled trigger to run the workflow daily at 02:00 UTC. - Introduced a wait step to ensure a quiet period before proceeding with builds on push events. - Updated Docker actions to their latest versions for improved reliability and security. - Ensured the workflow only runs on pushes to the main branch. These changes improve the efficiency and reliability of the Docker image build process. --- .github/workflows/docker-build.yml | 37 ++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 336ea9bf..e136913d 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -1,27 +1,46 @@ name: Build docker image +# Add concurrency configuration to handle multiple pushes +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + on: - push: + schedule: + # Runs at 02:00 UTC every day + - cron: '0 2 * * *' pull_request: workflow_dispatch: + push: + branches: + # Only run on push to main branch + - main jobs: + wait-for-quiet-period: + if: github.event_name == 'push' + runs-on: ubuntu-latest + steps: + - name: Wait for quiet period + run: sleep 3600 # Wait for 1 hour + golangci: + needs: [wait-for-quiet-period] uses: ./.github/workflows/golangci-lint.yml test-docker-image: - needs: golangci + needs: [wait-for-quiet-period, golangci] # Ubuntu-20.04 required until this is fixed: https://github.com/actions/runner-images/discussions/9074 runs-on: ubuntu-20.04 steps: - name: Checkout GitHub Action - uses: actions/checkout@v4.1.5 + uses: actions/checkout@v4 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3.3.0 + uses: docker/setup-buildx-action@v3 - name: Build amd64 image for testing - uses: docker/build-push-action@v5.3.0 + uses: docker/build-push-action@v6 with: context: . tags: birdnet-go:test @@ -53,10 +72,10 @@ jobs: runs-on: ubuntu-20.04 steps: - name: Checkout GitHub Action - uses: actions/checkout@v4.1.5 + uses: actions/checkout@v4 - name: Login to GitHub Container Registry - uses: docker/login-action@v3.1.0 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} @@ -67,10 +86,10 @@ jobs: echo "REPO=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV} - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3.3.0 + uses: docker/setup-buildx-action@v3 - name: Build and push docker image - uses: docker/build-push-action@v5.3.0 + uses: docker/build-push-action@v6 with: context: . push: true