Create build-platform.yml #1
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 Platform Image | ||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| platform: | ||
| required: true | ||
| type: string | ||
| description: 'Platform to build (linux/amd64 or linux/arm64)' | ||
| image_name: | ||
| required: true | ||
| type: string | ||
| description: 'Image name' | ||
| version: | ||
| required: true | ||
| type: string | ||
| description: 'Version tag' | ||
| secrets: | ||
| GITHUB_TOKEN: | ||
| required: true | ||
| env: | ||
| REGISTRY: ghcr.io | ||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 45 | ||
| permissions: | ||
| contents: read | ||
| packages: write | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| - name: Set up QEMU (for ARM builds) | ||
| if: inputs.platform == 'linux/arm64' | ||
| uses: docker/setup-qemu-action@v3 | ||
| - 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.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Set platform suffix | ||
| id: platform | ||
| run: | | ||
| PLATFORM_SUFFIX=$(echo "${{ inputs.platform }}" | sed 's|linux/||') | ||
| echo "suffix=$PLATFORM_SUFFIX" >> $GITHUB_OUTPUT | ||
| - name: Build and push | ||
| uses: docker/build-push-action@v5 | ||
| with: | ||
| context: . | ||
| platforms: ${{ inputs.platform }} | ||
| push: true | ||
| tags: ${{ env.REGISTRY }}/${{ inputs.image_name }}:${{ inputs.version }}-${{ steps.platform.outputs.suffix }} | ||
| cache-from: type=gha,scope=${{ steps.platform.outputs.suffix }} | ||
| cache-to: type=gha,mode=max,scope=${{ steps.platform.outputs.suffix }} | ||
| labels: | | ||
| org.opencontainers.image.source=https://github.com/${{ github.repository }} | ||
| org.opencontainers.image.version=${{ inputs.version }} | ||
| - name: Build complete | ||
| run: | | ||
| echo "✅ Built ${{ inputs.platform }} image: ${{ env.REGISTRY }}/${{ inputs.image_name }}:${{ inputs.version }}-${{ steps.platform.outputs.suffix }}" | ||