118 platform production release deployment from GitHub #23
Workflow file for this run
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 Non-Production Images | |
# Builds the backend source into binary containers for the current branch and pushes to the GitHub Container Registry. | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
types: [opened, synchronize, reopened] | |
workflow_dispatch: | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build_test_run: | |
runs-on: ubuntu-22.04 | |
steps: | |
# Checkout code | |
- uses: actions/checkout@v4 | |
# Enable QEMU for multi-arch builds (arm64 on x86) | |
- name: Set up Rust + QEMU | |
uses: docker/setup-qemu-action@v2 | |
with: | |
platforms: linux/amd64,linux/arm64 | |
# Install Rust and cache artifacts | |
- name: Set up Rust | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
toolchain: stable | |
- uses: Swatinem/rust-cache@v2 | |
with: | |
shared-key: ${{ runner.os }}-cargo-${{ github.sha }} | |
# Install sea-orm-cli globally (if needed for migration or seed) | |
- name: Install sea-orm-cli | |
run: cargo install sea-orm-cli | |
# Run tests for x86_64 only (CI feedback) | |
- name: Run tests | |
run: cargo test --release | |
build_and_push_docker: | |
runs-on: ubuntu-22.04 | |
needs: build_test_run | |
permissions: | |
contents: read | |
packages: write | |
attestations: write | |
id-token: write | |
steps: | |
# Checkout source code | |
- uses: actions/checkout@v4 | |
# Docker login to GHCR | |
- name: Docker login | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# Set up Docker Buildx for multi-platform builds | |
- uses: docker/setup-buildx-action@v3 | |
with: | |
install: true | |
# Show current Docker cache usage | |
- name: Show Docker Build Cache (Before) | |
run: | | |
echo -e "\033[1;34m🔍 Checking buildx cache BEFORE build...\033[0m" | |
docker buildx du || echo -e "\033[1;33m⚠️ No cache found yet.\033[0m" | |
# Compute image tag | |
- name: Determine Image Tags | |
id: tags | |
run: | | |
BRANCH_NAME=${GITHUB_HEAD_REF:-${GITHUB_REF##*/}} | |
IMAGE_NAME="${{ env.REGISTRY }}/${{ github.repository }}/${BRANCH_NAME}" | |
echo "backend_tags=$IMAGE_NAME:latest" >> $GITHUB_OUTPUT | |
echo "backend_image_name=$IMAGE_NAME" >> $GITHUB_OUTPUT | |
# Build and push multi-arch Docker image with cache | |
- name: Build + Push Backend | |
id: push_backend | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./Dockerfile | |
platforms: linux/amd64,linux/arm64 # ✅ Key multi-arch setting | |
push: true | |
provenance: true | |
tags: ${{ steps.tags.outputs.backend_tags }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
# Show updated cache usage | |
- name: Show Docker Build Cache (After) | |
run: | | |
echo -e "\033[1;34m📦 Checking buildx cache AFTER build...\033[0m" | |
docker buildx du || echo -e "\033[1;31m❌ Failed to get updated cache info\033[0m" | |
# Attest build provenance if on main branch | |
- name: Attest Backend | |
if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
uses: actions/attest-build-provenance@v2 | |
with: | |
subject-name: ${{ steps.tags.outputs.backend_image_name }} | |
subject-digest: ${{ steps.push_backend.outputs.digest }} | |
push-to-registry: true | |
# Output how to pull and run the pushed image | |
- name: Print Usage Instructions | |
run: | | |
echo -e "\033[1;32m✅ Backend Image Pushed:\033[0m" | |
echo " docker pull ${{ steps.tags.outputs.backend_image_name }}:latest" | |
echo "" | |
echo -e "\033[1;36m▶️ Run Backend:\033[0m" | |
echo " docker run --rm --env-file .env -p 8000:8000 ${{ steps.tags.outputs.backend_image_name }}:latest" |