Docker Compiler - RP2040 #2
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: Docker Compiler - RP2040 | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| # Run every Saturday at 00:00 UTC | |
| - cron: '0 0 * * 6' | |
| env: | |
| BASE_IMAGE: niteris/fastled-compiler-base | |
| jobs: | |
| credentials: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| docker_username: ${{ steps.credentials.outputs.docker_username }} | |
| docker_password: ${{ steps.credentials.outputs.docker_password }} | |
| registry_base: ${{ steps.credentials.outputs.registry_base }} | |
| steps: | |
| - name: Output encoded credentials | |
| id: credentials | |
| env: | |
| docker_username: niteris | |
| docker_password: ${{ secrets.DOCKER_PASSWORD }} | |
| registry_base: ${{ env.BASE_IMAGE }} | |
| run: | | |
| echo "docker_username=$(echo -n "niteris" | base64 -w0 | base64 -w0)" >> $GITHUB_OUTPUT | |
| echo "docker_password=$(echo $docker_password | base64 -w0 | base64 -w0)" >> $GITHUB_OUTPUT | |
| echo "registry_base=$(echo $registry_base | base64 -w0 | base64 -w0)" >> $GITHUB_OUTPUT | |
| build-rp: | |
| name: 🔨 Build RP2040 [${{ matrix.arch.platform }}] | |
| needs: credentials | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| arch: | |
| - runs_on: ubuntu-24.04 | |
| platform: linux/amd64 | |
| - runs_on: ubuntu-24.04-arm | |
| platform: linux/arm64 | |
| runs-on: ${{ matrix.arch.runs_on }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install uv | |
| run: | | |
| curl -LsSf https://astral.sh/uv/install.sh | sh | |
| echo "$HOME/.cargo/bin" >> $GITHUB_PATH | |
| - name: Get platform configuration | |
| id: config | |
| run: | | |
| boards=$(uv run python3 -c " | |
| from ci.docker_utils.build_platforms import get_boards_for_platform, get_docker_image_name | |
| platform = 'rp' | |
| boards = get_boards_for_platform(platform) | |
| image = get_docker_image_name(platform) | |
| print(f'boards={\",\".join(boards)}') | |
| print(f'image={image}') | |
| ") | |
| echo "$boards" >> $GITHUB_OUTPUT | |
| - name: Decode credentials | |
| id: decode | |
| run: | | |
| username=$(echo "${{ needs.credentials.outputs.docker_username }}" | base64 -d | base64 -d) | |
| password=$(echo "${{ needs.credentials.outputs.docker_password }}" | base64 -d | base64 -d) | |
| echo "::add-mask::$username" | |
| echo "::add-mask::$password" | |
| echo "username=$username" >> $GITHUB_OUTPUT | |
| echo "password=$password" >> $GITHUB_OUTPUT | |
| - name: Prepare | |
| run: | | |
| platform=${{ matrix.arch.platform }} | |
| echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV | |
| - name: Display target Docker image | |
| run: | | |
| echo "================================" | |
| echo "Building Docker image for platform: RP2040" | |
| echo "Boards: ${{ steps.config.outputs.boards }}" | |
| echo "Image: ${{ steps.config.outputs.image }}" | |
| echo "Architecture: ${{ matrix.arch.platform }}" | |
| echo "================================" | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ steps.decode.outputs.username }} | |
| password: ${{ steps.decode.outputs.password }} | |
| - name: Docker meta | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ steps.config.outputs.image }} | |
| tags: type=raw,value=latest,enable={{is_default_branch}} | |
| - name: Build and push by digest | |
| id: build | |
| uses: docker/build-push-action@v6 | |
| with: | |
| platforms: ${{ matrix.arch.platform }} | |
| context: . | |
| file: ./ci/docker_utils/Dockerfile.template | |
| labels: ${{ steps.meta.outputs.labels }} | |
| outputs: type=image,name=${{ steps.config.outputs.image }},push-by-digest=true,name-canonical=true,push=true | |
| build-args: | | |
| PLATFORMS=${{ steps.config.outputs.boards }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max,compression=zstd | |
| - name: Export digest | |
| run: | | |
| mkdir -p /tmp/digests | |
| digest="${{ steps.build.outputs.digest }}" | |
| touch "/tmp/digests/${digest#sha256:}" | |
| - name: Upload digest | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: digests-rp-${{ env.PLATFORM_PAIR }} | |
| path: /tmp/digests/* | |
| if-no-files-found: error | |
| retention-days: 1 | |
| merge-rp: | |
| name: 📦 Merge RP2040 | |
| needs: build-rp | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Install uv | |
| run: | | |
| curl -LsSf https://astral.sh/uv/install.sh | sh | |
| echo "$HOME/.cargo/bin" >> $GITHUB_PATH | |
| - name: Get platform image name | |
| id: config | |
| run: | | |
| image=$(uv run python3 -c " | |
| from ci.docker_utils.build_platforms import get_docker_image_name | |
| print(get_docker_image_name('rp')) | |
| ") | |
| echo "image=$image" >> $GITHUB_OUTPUT | |
| - name: Download digests for RP2040 | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: /tmp/digests | |
| pattern: digests-rp-* | |
| merge-multiple: true | |
| - name: Verify digests were downloaded | |
| run: | | |
| if [ ! -d /tmp/digests ] || [ -z "$(ls -A /tmp/digests)" ]; then | |
| echo "ERROR: No digests found for RP2040! Build jobs likely failed." | |
| exit 1 | |
| fi | |
| echo "Found digests for RP2040:" | |
| ls -la /tmp/digests/ | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Docker meta | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ steps.config.outputs.image }} | |
| tags: type=raw,value=latest | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: niteris | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Create manifest list and push | |
| working-directory: /tmp/digests | |
| run: | | |
| docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ | |
| $(printf '${{ steps.config.outputs.image }}@sha256:%s ' *) | |
| - name: Inspect image | |
| run: | | |
| docker buildx imagetools inspect ${{ steps.config.outputs.image }}:latest | |
| - name: Report success | |
| run: | | |
| echo "✅ Successfully merged and pushed multi-arch image for RP2040" | |
| echo " Image: ${{ steps.config.outputs.image }}:latest" |