Refactor Docker image tagging strategy for consistency and clarity #50
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
| # PlatformIO Docker Build Workflow | |
| # | |
| # Build Strategy: | |
| # - Main repo master: Build + Push to GHCR | |
| # - Main repo dev/PR: Build only (validation) | |
| # - workflow_dispatch: Build on any branch/fork, push only on main repo master | |
| # - Forks: Can test builds, but push is restricted to main repo | |
| name: π³ PlatformIO Docker Image | |
| on: | |
| push: | |
| branches: [master, dev] | |
| paths: | |
| - '.github/workflows/platformio.yml' | |
| - 'images/platformio/**' | |
| pull_request: | |
| branches: [master, dev] | |
| paths: | |
| - '.github/workflows/platformio.yml' | |
| - 'images/platformio/**' | |
| workflow_dispatch: | |
| env: | |
| REGISTRY: ghcr.io | |
| PLATFORMIO_IMAGE_NAME: jethome-dev-platformio | |
| jobs: | |
| platformio-build: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 60 | |
| if: github.repository_owner == 'jethome-iot' || github.event_name == 'workflow_dispatch' | |
| permissions: | |
| contents: read | |
| packages: write | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| platform: [linux/amd64, linux/arm64] | |
| pio_version: ['v6.1.18'] | |
| steps: | |
| - name: π₯ Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: π§ Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: π Log in to GitHub Container Registry | |
| if: github.ref_name == 'master' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: π·οΈ Prepare platform tag | |
| id: platform | |
| run: | | |
| PLATFORM_PAIR=${{ matrix.platform }} | |
| PLATFORM_TAG=$(echo $PLATFORM_PAIR | sed 's/\//-/g') | |
| echo "tag=${PLATFORM_TAG}" >> $GITHUB_OUTPUT | |
| - name: π³ Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: images/platformio | |
| platforms: ${{ matrix.platform }} | |
| push: ${{ github.repository_owner == 'jethome-iot' && github.ref_name == 'master' }} | |
| tags: | | |
| ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.PLATFORMIO_IMAGE_NAME }}:pio-${{ matrix.pio_version }}-${{ steps.platform.outputs.tag }} | |
| cache-from: type=gha,scope=${{ env.PLATFORMIO_IMAGE_NAME }}-${{ steps.platform.outputs.tag }} | |
| cache-to: type=gha,mode=max,scope=${{ env.PLATFORMIO_IMAGE_NAME }}-${{ steps.platform.outputs.tag }} | |
| build-args: | | |
| PIO_VERSION=${{ matrix.pio_version }} | |
| platformio-manifest: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| needs: platformio-build | |
| if: github.repository_owner == 'jethome-iot' && github.ref_name == 'master' | |
| permissions: | |
| contents: read | |
| packages: write | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| pio_version: ['v6.1.18'] | |
| steps: | |
| - name: π Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: π·οΈ Generate SHA tag | |
| id: tags | |
| run: | | |
| SHA_SHORT=$(echo "${{ github.sha }}" | cut -c1-7) | |
| echo "sha_short=${SHA_SHORT}" >> $GITHUB_OUTPUT | |
| - name: π― Create multi-arch manifest | |
| run: | | |
| docker buildx imagetools create -t ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.PLATFORMIO_IMAGE_NAME }}:latest \ | |
| -t ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.PLATFORMIO_IMAGE_NAME }}:stable \ | |
| -t ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.PLATFORMIO_IMAGE_NAME }}:pio-${{ matrix.pio_version }} \ | |
| -t ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.PLATFORMIO_IMAGE_NAME }}:sha-${{ steps.tags.outputs.sha_short }} \ | |
| ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.PLATFORMIO_IMAGE_NAME }}:pio-${{ matrix.pio_version }}-linux-amd64 \ | |
| ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.PLATFORMIO_IMAGE_NAME }}:pio-${{ matrix.pio_version }}-linux-arm64 |