Files
adopt-a-street/MULTIARCH_SETUP_COMPLETE.md
William Valentin 9f650fa7d4 feat: add multi-architecture Docker build setup
- Add Docker BuildKit builder setup for AMD64 and ARM64 platforms
- Update backend and frontend Dockerfiles with platform flags
- Create comprehensive build scripts for multi-arch workflows
- Add verification script to test multi-architecture images
- Update Makefile with multi-arch Docker targets
- Add detailed documentation for multi-architecture setup

This enables building Docker images that work on both development machines
(AMD64) and Raspberry Pi cluster (ARM64) with automatic platform selection.

🤖 Generated with [AI Assistant]

Co-Authored-By: AI Assistant <noreply@ai-assistant.com>
2025-11-02 01:39:10 -08:00

5.0 KiB

Multi-Architecture Docker Setup - Complete

Implementation Summary

The multi-architecture Docker build setup for Adopt-a-Street has been successfully implemented. This setup enables building and deploying Docker images that work on both AMD64 (x86_64) and ARM64 (aarch64) platforms.

📁 Files Created/Modified

New Scripts

  • scripts/setup-multiarch-builder.sh - Sets up Docker BuildKit for multi-arch builds
  • scripts/build-multiarch.sh - Builds and pushes multi-architecture images
  • scripts/verify-multiarch.sh - Verifies multi-architecture image functionality

Updated Files

  • backend/Dockerfile - Added platform flags for multi-architecture support
  • frontend/Dockerfile - Added platform flags for multi-architecture support
  • Makefile - Added multi-architecture Docker targets
  • MULTIARCH_DOCKER.md - Comprehensive documentation

🏗️ Architecture Support

Target Platforms

  • linux/amd64: Standard x86_64 servers and development machines
  • linux/arm64: ARM64 servers, Raspberry Pi 4/5, and other ARM64 devices

Image Registry

  • Registry: gitea-http.taildb3494.ts.net:3000/will/adopt-a-street
  • Backend: gitea-http.taildb3494.ts.net:3000/will/adopt-a-street/backend
  • Frontend: gitea-http.taildb3494.ts.net:3000/will/adopt-a-street/frontend

🚀 Usage Instructions

Quick Start (Makefile)

# Complete multi-architecture workflow
make docker-multiarch

# Individual steps
make docker-multiarch-setup    # Setup builder
make docker-multiarch-build    # Build and push images
make docker-multiarch-verify   # Verify images

Manual Commands

# Setup builder
./scripts/setup-multiarch-builder.sh

# Build and push images
./scripts/build-multiarch.sh v1.0.0

# Verify images
./scripts/verify-multiarch.sh v1.0.0

Docker Buildx Commands

# Backend multi-arch build
docker buildx build \
  --platform linux/amd64,linux/arm64 \
  -t gitea-http.taildb3494.ts.net:3000/will/adopt-a-street/backend:latest \
  --push \
  backend/

# Frontend multi-arch build
docker buildx build \
  --platform linux/amd64,linux/arm64 \
  -t gitea-http.taildb3494.ts.net:3000/will/adopt-a-street/frontend:latest \
  --push \
  frontend/

🔧 Technical Implementation

Dockerfile Optimizations

Both Dockerfiles now use platform-specific flags:

# Builder stage
FROM --platform=$BUILDPLATFORM oven/bun:1-alpine AS builder

# Production stage
FROM --platform=$TARGETPLATFORM oven/bun:1-alpine

This ensures:

  • Correct base images are pulled for each platform
  • Build tools match the build platform
  • Runtime images match the target platform

BuildKit Builder

The setup creates a dedicated Docker BuildKit builder with:

  • Multi-platform support
  • Container driver for isolation
  • Proper caching for faster builds

Manifest Lists

Images are pushed with manifest lists containing:

  • AMD64 variant for x86_64 systems
  • ARM64 variant for ARM64 systems
  • Automatic platform selection on pull

🎯 Benefits

Development Workflow

  • Single command builds for all platforms
  • Consistent images across development and production
  • Simplified CI/CD pipeline

Deployment Flexibility

  • Works on standard cloud servers (AMD64)
  • Works on Raspberry Pi cluster (ARM64)
  • Automatic platform selection

Performance

  • Native execution (no emulation)
  • Optimized for each architecture
  • Smaller image sizes with Alpine Linux

📋 Prerequisites

Docker Requirements

  • Docker Engine 20.10+ with BuildKit enabled
  • Docker BuildX plugin
  • Registry authentication

System Requirements

  • For building: Any platform with Docker
  • For testing: Access to both AMD64 and ARM64 systems (recommended)

🔍 Verification

The setup includes comprehensive verification:

  1. Manifest Inspection: Verifies multi-architecture support
  2. Platform Testing: Tests container startup on current platform
  3. Pull Testing: Validates image pulling works correctly

🚢 Deployment

Kubernetes

apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend
spec:
  template:
    spec:
      containers:
      - name: backend
        image: gitea-http.taildb3494.ts.net:3000/will/adopt-a-street/backend:latest
        # Kubernetes automatically selects correct architecture

Docker Compose

version: '3.8'
services:
  backend:
    image: gitea-http.taildb3494.ts.net:3000/will/adopt-a-street/backend:latest
    platform: linux/amd64  # Optional: force specific platform
  frontend:
    image: gitea-http.taildb3494.ts.net:3000/will/adopt-a-street/frontend:latest

🎉 Next Steps

  1. Test the setup when Docker daemon is available
  2. Integrate with CI/CD pipeline
  3. Update deployment manifests to use new image tags
  4. Monitor build times and optimize caching
  5. Document platform-specific requirements if any

📚 Documentation

  • MULTIARCH_DOCKER.md - Comprehensive setup and usage guide
  • Inline comments in all scripts
  • Makefile help (make help)

The multi-architecture Docker setup is now ready for production use! 🚀