Daily Docker Image Build #147
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Daily Docker Image Build | |
| on: | |
| schedule: | |
| # Run daily at midnight UTC | |
| - cron: "0 0 * * *" | |
| push: | |
| branches: ["main"] | |
| paths: | |
| - "src/**" | |
| - "Dockerfile" | |
| - "docker-compose.yml" | |
| - "requirements.txt" | |
| - "main.py" | |
| - "entrypoint.sh" | |
| - "geoip.conf" | |
| workflow_dispatch: | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }} | |
| CONTAINER_NAME: ${{ github.event.repository.name }} | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| packages: write | |
| contents: read | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Verify MaxMind secrets are set | |
| run: | | |
| if [ -z "${{ secrets.GEOIPUPDATE_ACCOUNT_ID }}" ]; then | |
| echo "::error::GEOIPUPDATE_ACCOUNT_ID secret is not set" | |
| echo "Please add GEOIPUPDATE_ACCOUNT_ID to repository secrets" | |
| echo "Go to Settings → Secrets and variables → Actions → New repository secret" | |
| exit 1 | |
| fi | |
| if [ -z "${{ secrets.GEOIPUPDATE_LICENSE_KEY }}" ]; then | |
| echo "::error::GEOIPUPDATE_LICENSE_KEY secret is not set" | |
| echo "Please add GEOIPUPDATE_LICENSE_KEY to repository secrets" | |
| echo "Go to Settings → Secrets and variables → Actions → New repository secret" | |
| exit 1 | |
| fi | |
| echo "MaxMind secrets are configured" | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata for Docker | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| type=sha,prefix={{branch}}- | |
| type=schedule,pattern={{date 'YYMMDD'}} | |
| - name: Build and push Docker image with daily updated GeoIP databases | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| platforms: linux/amd64 | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| build-args: | | |
| GEOIPUPDATE_ACCOUNT_ID=${{ secrets.GEOIPUPDATE_ACCOUNT_ID }} | |
| GEOIPUPDATE_LICENSE_KEY=${{ secrets.GEOIPUPDATE_LICENSE_KEY }} | |
| cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache | |
| cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache,mode=max | |
| - name: Image digest | |
| run: echo ${{ steps.meta.outputs.digest }} |