Build and Publish Docker Images #1303
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: Build and Publish Docker Images | |
| on: | |
| schedule: | |
| - cron: '0 4 * * *' | |
| - cron: '0 16 * * *' | |
| push: | |
| branches: [ "main" ] | |
| env: | |
| DOCKER_IMAGE_NAME: ${{ github.repository }} | |
| DOCKER_REGISTRY: ghcr.io | |
| GITHUB_SHA: ${{ github.sha }} | |
| MAX_RETRIES: 3 | |
| jobs: | |
| setup-timestamp: | |
| # Run the job if triggered by a scheduled event or a push with a specific commit message | |
| if: github.event_name == 'schedule' || (github.event_name == 'push' && contains(github.event.head_commit.message, 'run-ci')) | |
| runs-on: ubuntu-24.04 | |
| outputs: | |
| date: ${{ steps.timestamp.outputs.date }} | |
| date_time: ${{ steps.timestamp.outputs.date_time }} | |
| source_date_epoch: ${{ steps.timestamp.outputs.source_date_epoch }} | |
| steps: | |
| - name: Generate build timestamp | |
| id: timestamp | |
| run: | | |
| # Capture the current time as a Unix timestamp | |
| now=$(date '+%s') | |
| # Format the date variables using the captured timestamp | |
| date=$(date -u -d "@$now" '+%Y-%m-%d') | |
| date_time=$(date -u -d "@$now" '+%Y-%m-%d.%H-%M-%S') | |
| # Get the first day of the current month at 00:00 UTC | |
| year_month=$(date -u -d "@$now" '+%Y-%m') | |
| source_date_epoch=$(date -u -d "${year_month}-01 00:00:00" '+%s') | |
| echo "date=$date" >> $GITHUB_OUTPUT | |
| echo "date_time=$date_time" >> $GITHUB_OUTPUT | |
| echo "source_date_epoch=$source_date_epoch" >> $GITHUB_OUTPUT | |
| build-matrix: | |
| needs: setup-timestamp | |
| runs-on: ${{ matrix.runner }} | |
| strategy: | |
| matrix: | |
| include: | |
| - platform: amd64 | |
| runner: ubuntu-24.04 | |
| - platform: arm64 | |
| runner: ubuntu-24.04-arm | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| # Set up Docker Buildx (Builder for multi-platform images) | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0 | |
| # Login to Docker Registry | |
| - name: Log into Docker Registry ${{ env.DOCKER_REGISTRY }} | |
| uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 | |
| with: | |
| registry: ${{ env.DOCKER_REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| # Set up Python Environment | |
| - name: Set up Python Environment | |
| uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 | |
| with: | |
| python-version: '3.12' | |
| # Run Python script to discover and build Docker images in parallel | |
| - name: Discover, Build, and Push Docker Images in Parallel | |
| run: python .github/scripts/build_docker_images.py | |
| env: | |
| DATE_STR: ${{ needs.setup-timestamp.outputs.date }} | |
| DATE_TIME_STR: ${{ needs.setup-timestamp.outputs.date_time }} | |
| DOCKER_PLATFORM: ${{ matrix.platform }} | |
| SOURCE_DATE_EPOCH: ${{ needs.setup-timestamp.outputs.source_date_epoch }} | |
| create-manifest: | |
| needs: [setup-timestamp, build-matrix] | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| # Set up Docker Buildx (Builder for multi-platform images) | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0 | |
| # Login to Docker Registry | |
| - name: Log into Docker Registry ${{ env.DOCKER_REGISTRY }} | |
| uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 | |
| with: | |
| registry: ${{ env.DOCKER_REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| # Set up Python Environment | |
| - name: Set up Python Environment | |
| uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 | |
| with: | |
| python-version: '3.12' | |
| # Run Python script to create and push Docker manifests | |
| - name: Create and Push Docker Manifests | |
| run: python .github/scripts/create_docker_manifests.py | |
| env: | |
| DATE_STR: ${{ needs.setup-timestamp.outputs.date }} | |
| DATE_TIME_STR: ${{ needs.setup-timestamp.outputs.date_time }} | |
| MAX_RETRIES: ${{ env.MAX_RETRIES }} |