Skip to content

Commit 894272e

Browse files
committed
fixes container workflow to use buildx for multi-platform support
1 parent 04ddd45 commit 894272e

File tree

1 file changed

+13
-31
lines changed

1 file changed

+13
-31
lines changed

.github/workflows/build_and_deploy_containers.yml

+13-31
Original file line numberDiff line numberDiff line change
@@ -26,41 +26,23 @@ jobs:
2626
- name: Set up Rust + QEMU
2727
uses: docker/setup-qemu-action@v2
2828
with:
29-
platforms: linux/amd64,linux/arm64 # ✅ Only needed once per buildx host
29+
platforms: linux/amd64,linux/arm64
3030

31-
# Install ARM cross-compiler
32-
- name: Install cross-compilation toolchain
33-
run: |
34-
sudo apt-get update
35-
sudo apt-get install -y gcc-aarch64-linux-gnu
36-
37-
# Install Rust toolchain with both x86_64 and arm64 targets
38-
- name: Set up Rust targets
31+
# Install Rust and cache artifacts
32+
- name: Set up Rust
3933
uses: dtolnay/rust-toolchain@stable
4034
with:
41-
targets: x86_64-unknown-linux-gnu,aarch64-unknown-linux-gnu # ✅ Targets declared here
35+
toolchain: stable
4236

43-
# Cache Rust build artifacts (unique key avoids 409 Conflict errors)
4437
- uses: Swatinem/rust-cache@v2
4538
with:
4639
shared-key: ${{ runner.os }}-cargo-${{ github.sha }}
4740

48-
# Install sea-orm-cli globally
41+
# Install sea-orm-cli globally (if needed for migration or seed)
4942
- name: Install sea-orm-cli
5043
run: cargo install sea-orm-cli
5144

52-
# Configure the Rust linker for arm64 builds
53-
- name: Set linker for cross-compilation
54-
run: |
55-
mkdir -p ~/.cargo
56-
echo '[target.aarch64-unknown-linux-gnu]' >> ~/.cargo/config.toml
57-
echo 'linker = "aarch64-linux-gnu-gcc"' >> ~/.cargo/config.toml
58-
59-
# Build release binaries for ARM64
60-
- name: Build release binaries
61-
run: cargo build --release --workspace --target aarch64-unknown-linux-gnu
62-
63-
# Run tests for x86_64 (native)
45+
# Run tests for x86_64 only (CI feedback)
6446
- name: Run tests
6547
run: cargo test --release
6648

@@ -77,7 +59,7 @@ jobs:
7759
# Checkout source code
7860
- uses: actions/checkout@v4
7961

80-
# Authenticate to GitHub Container Registry
62+
# Docker login to GHCR
8163
- name: Docker login
8264
uses: docker/login-action@v2
8365
with:
@@ -96,7 +78,7 @@ jobs:
9678
echo -e "\033[1;34m🔍 Checking buildx cache BEFORE build...\033[0m"
9779
docker buildx du || echo -e "\033[1;33m⚠️ No cache found yet.\033[0m"
9880
99-
# Compute image name based on branch name and tag as `latest`
81+
# Compute image tag
10082
- name: Determine Image Tags
10183
id: tags
10284
run: |
@@ -105,27 +87,27 @@ jobs:
10587
echo "backend_tags=$IMAGE_NAME:latest" >> $GITHUB_OUTPUT
10688
echo "backend_image_name=$IMAGE_NAME" >> $GITHUB_OUTPUT
10789
108-
# Build and push multi-arch Docker image with GHA cache
90+
# Build and push multi-arch Docker image with cache
10991
- name: Build + Push Backend
11092
id: push_backend
11193
uses: docker/build-push-action@v5
11294
with:
11395
context: .
11496
file: ./Dockerfile
115-
platforms: linux/amd64,linux/arm64 #Declared again for buildx
97+
platforms: linux/amd64,linux/arm64 #Key multi-arch setting
11698
push: true
11799
provenance: true
118100
tags: ${{ steps.tags.outputs.backend_tags }}
119101
cache-from: type=gha
120102
cache-to: type=gha,mode=max
121103

122-
# Show updated Docker cache state
104+
# Show updated cache usage
123105
- name: Show Docker Build Cache (After)
124106
run: |
125107
echo -e "\033[1;34m📦 Checking buildx cache AFTER build...\033[0m"
126108
docker buildx du || echo -e "\033[1;31m❌ Failed to get updated cache info\033[0m"
127109
128-
# Generate SBOM + attestation only on main branch
110+
# Attest build provenance if on main branch
129111
- name: Attest Backend
130112
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
131113
uses: actions/attest-build-provenance@v2
@@ -141,4 +123,4 @@ jobs:
141123
echo " docker pull ${{ steps.tags.outputs.backend_image_name }}:latest"
142124
echo ""
143125
echo -e "\033[1;36m▶️ Run Backend:\033[0m"
144-
echo " docker run --rm -p 8000:8000 ${{ steps.tags.outputs.backend_image_name }}:latest"
126+
echo " docker run --rm --env-file .env -p 8000:8000 ${{ steps.tags.outputs.backend_image_name }}:latest"

0 commit comments

Comments
 (0)