Build and Push Container Image #38
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 Push Container Image | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version tag (e.g. v1.17.0). Leave empty to tag only with SHA + latest.' | |
| required: false | |
| type: string | |
| tinycode_ref: | |
| description: 'tinycode git ref to build (branch, tag, or SHA). Default: main' | |
| required: false | |
| default: 'main' | |
| type: string | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: bjohns/tinycode-container | |
| jobs: | |
| build-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@06116385d9baf250c9f4dcb4858b16962ea869c3 # v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4 | |
| - name: Log in to GHCR | |
| uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Check Quay.io credentials | |
| id: quay | |
| run: | | |
| if [ -n "$QUAY_USER" ] && [ -n "$QUAY_PASS" ]; then | |
| echo "available=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "available=false" >> "$GITHUB_OUTPUT" | |
| echo "::notice::Quay.io credentials not configured — skipping Quay push" | |
| fi | |
| env: | |
| QUAY_USER: ${{ secrets.QUAY_USERNAME }} | |
| QUAY_PASS: ${{ secrets.QUAY_PASSWORD }} | |
| - name: Login to Quay.io | |
| if: steps.quay.outputs.available == 'true' | |
| uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4 | |
| with: | |
| registry: quay.io | |
| username: ${{ secrets.QUAY_USERNAME }} | |
| password: ${{ secrets.QUAY_PASSWORD }} | |
| - name: Compute image tags | |
| id: tags | |
| run: | | |
| TAGS="${REGISTRY}/${IMAGE_NAME}:${GITHUB_SHA}" | |
| TAGS="${TAGS},${REGISTRY}/${IMAGE_NAME}:latest" | |
| if [ -n "$VERSION" ]; then | |
| TAGS="${TAGS},${REGISTRY}/${IMAGE_NAME}:${VERSION}" | |
| fi | |
| if [ "$QUAY_AVAILABLE" = "true" ]; then | |
| TAGS="${TAGS},quay.io/${IMAGE_NAME}:${GITHUB_SHA}" | |
| TAGS="${TAGS},quay.io/${IMAGE_NAME}:latest" | |
| if [ -n "$VERSION" ]; then | |
| TAGS="${TAGS},quay.io/${IMAGE_NAME}:${VERSION}" | |
| fi | |
| fi | |
| echo "tags=${TAGS}" >> "$GITHUB_OUTPUT" | |
| env: | |
| VERSION: ${{ inputs.version }} | |
| QUAY_AVAILABLE: ${{ steps.quay.outputs.available }} | |
| - name: Build and push multi-arch image | |
| uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7 | |
| with: | |
| context: . | |
| file: ContainerFile | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| build-args: | | |
| TINYCODE_REF=${{ inputs.tinycode_ref || 'main' }} | |
| tags: ${{ steps.tags.outputs.tags }} | |
| secrets: | | |
| github_token=${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }} | |
| - name: Smoke test (amd64) | |
| run: | | |
| docker run --rm --platform linux/amd64 --entrypoint tinycode \ | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} --version | |
| - name: Smoke test (arm64) | |
| run: | | |
| docker run --rm --platform linux/arm64 --entrypoint tinycode \ | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} --version |