Skip to content

Commit

Permalink
chore: enhance GitHub Actions workflow for Docker image builds
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
tphakala committed Jan 16, 2025
1 parent 2b37f1e commit 7068199
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 }}
Expand All @@ -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
Expand Down

0 comments on commit 7068199

Please sign in to comment.