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>
This commit is contained in:
87
scripts/build-multiarch.sh
Executable file
87
scripts/build-multiarch.sh
Executable file
@@ -0,0 +1,87 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Multi-architecture Docker build script for Adopt-a-Street
|
||||
# Builds and pushes images for AMD64 and ARM64 platforms
|
||||
|
||||
set -e
|
||||
|
||||
# Configuration
|
||||
REGISTRY="gitea-http.taildb3494.ts.net:3000/will/adopt-a-street"
|
||||
BACKEND_IMAGE="${REGISTRY}/backend"
|
||||
FRONTEND_IMAGE="${REGISTRY}/frontend"
|
||||
VERSION=${1:-latest}
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
echo -e "${BLUE}🏗️ Adopt-a-Street Multi-Architecture Docker Build${NC}"
|
||||
echo -e "${BLUE}===============================================${NC}"
|
||||
echo ""
|
||||
|
||||
# Check if we're logged into the registry
|
||||
echo -e "${YELLOW}🔐 Checking registry authentication...${NC}"
|
||||
if ! docker info | grep -q "Username"; then
|
||||
echo -e "${RED}❌ Not logged into Docker registry. Please run: docker login ${REGISTRY}${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Setup multi-architecture builder
|
||||
echo -e "${YELLOW}🔧 Setting up multi-architecture builder...${NC}"
|
||||
./scripts/setup-multiarch-builder.sh
|
||||
|
||||
# Function to build and push image
|
||||
build_image() {
|
||||
local service_name=$1
|
||||
local dockerfile_path=$2
|
||||
local build_context=$3
|
||||
local image_tag=$4
|
||||
|
||||
echo -e "${YELLOW}📦 Building ${service_name} image for AMD64 and ARM64...${NC}"
|
||||
|
||||
# Build and push multi-architecture image
|
||||
docker buildx build \
|
||||
--platform linux/amd64,linux/arm64 \
|
||||
--file "${dockerfile_path}" \
|
||||
--tag "${image_tag}:${VERSION}" \
|
||||
--tag "${image_tag}:latest" \
|
||||
--push \
|
||||
"${build_context}"
|
||||
|
||||
echo -e "${GREEN}✅ ${service_name} image built and pushed successfully!${NC}"
|
||||
echo ""
|
||||
}
|
||||
|
||||
# Build backend
|
||||
echo -e "${BLUE}🔙 Building Backend Image${NC}"
|
||||
build_image "Backend" "backend/Dockerfile" "backend" "${BACKEND_IMAGE}"
|
||||
|
||||
# Build frontend
|
||||
echo -e "${BLUE}🎨 Building Frontend Image${NC}"
|
||||
build_image "Frontend" "frontend/Dockerfile" "frontend" "${FRONTEND_IMAGE}"
|
||||
|
||||
# Verify images
|
||||
echo -e "${YELLOW}🔍 Verifying multi-architecture images...${NC}"
|
||||
echo -e "${BLUE}Backend image manifest:${NC}"
|
||||
docker buildx imagetools inspect "${BACKEND_IMAGE}:${VERSION}"
|
||||
echo ""
|
||||
echo -e "${BLUE}Frontend image manifest:${NC}"
|
||||
docker buildx imagetools inspect "${FRONTEND_IMAGE}:${VERSION}"
|
||||
|
||||
echo -e "${GREEN}🎉 Multi-architecture build completed successfully!${NC}"
|
||||
echo ""
|
||||
echo -e "${BLUE}Images pushed:${NC}"
|
||||
echo " - ${BACKEND_IMAGE}:${VERSION}"
|
||||
echo " - ${FRONTEND_IMAGE}:${VERSION}"
|
||||
echo ""
|
||||
echo -e "${BLUE}To pull on different architectures:${NC}"
|
||||
echo " # AMD64 (x86_64)"
|
||||
echo " docker pull ${BACKEND_IMAGE}:${VERSION}"
|
||||
echo " docker pull ${FRONTEND_IMAGE}:${VERSION}"
|
||||
echo ""
|
||||
echo " # ARM64 (Raspberry Pi)"
|
||||
echo " docker pull ${BACKEND_IMAGE}:${VERSION}"
|
||||
echo " docker pull ${FRONTEND_IMAGE}:${VERSION}"
|
||||
40
scripts/setup-multiarch-builder.sh
Executable file
40
scripts/setup-multiarch-builder.sh
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Multi-architecture Docker BuildKit builder setup script
|
||||
# Sets up buildx for AMD64 and ARM64 platforms
|
||||
|
||||
set -e
|
||||
|
||||
echo "🔧 Setting up multi-architecture Docker BuildKit builder..."
|
||||
|
||||
# Check if docker buildx is available
|
||||
if ! docker buildx version >/dev/null 2>&1; then
|
||||
echo "❌ Docker buildx is not available. Please install Docker BuildKit."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create multi-architecture builder if it doesn't exist
|
||||
BUILDER_NAME="multiarch-builder"
|
||||
if docker buildx ls | grep -q "$BUILDER_NAME"; then
|
||||
echo "✅ Builder '$BUILDER_NAME' already exists"
|
||||
else
|
||||
echo "📦 Creating new multi-architecture builder..."
|
||||
docker buildx create --name "$BUILDER_NAME" --driver docker-container --bootstrap
|
||||
echo "✅ Builder '$BUILDER_NAME' created successfully"
|
||||
fi
|
||||
|
||||
# Use the multi-architecture builder
|
||||
docker buildx use "$BUILDER_NAME"
|
||||
|
||||
# Verify platforms
|
||||
echo "🔍 Verifying supported platforms..."
|
||||
docker buildx inspect --bootstrap
|
||||
|
||||
echo "✅ Multi-architecture builder setup complete!"
|
||||
echo ""
|
||||
echo "Supported platforms:"
|
||||
docker buildx ls | grep "$BUILDER_NAME" -A 1 | grep "PLATFORMS" || echo " - linux/amd64"
|
||||
echo " - linux/arm64"
|
||||
echo ""
|
||||
echo "You can now build multi-architecture images using:"
|
||||
echo " docker buildx build --platform linux/amd64,linux/arm64 -t your-image:tag --push ."
|
||||
128
scripts/verify-multiarch.sh
Executable file
128
scripts/verify-multiarch.sh
Executable file
@@ -0,0 +1,128 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Verification script for multi-architecture Docker images
|
||||
# Tests that images work correctly on different platforms
|
||||
|
||||
set -e
|
||||
|
||||
# Configuration
|
||||
REGISTRY="gitea-http.taildb3494.ts.net:3000/will/adopt-a-street"
|
||||
BACKEND_IMAGE="${REGISTRY}/backend"
|
||||
FRONTEND_IMAGE="${REGISTRY}/frontend"
|
||||
VERSION=${1:-latest}
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
echo -e "${BLUE}🔍 Multi-Architecture Image Verification${NC}"
|
||||
echo -e "${BLUE}======================================${NC}"
|
||||
echo ""
|
||||
|
||||
# Function to inspect image manifest
|
||||
inspect_image() {
|
||||
local image_name=$1
|
||||
local image_tag=$2
|
||||
|
||||
echo -e "${YELLOW}📋 Inspecting ${image_name} manifest...${NC}"
|
||||
docker buildx imagetools inspect "${image_name}:${image_tag}"
|
||||
echo ""
|
||||
}
|
||||
|
||||
# Function to test image pull on specific platform
|
||||
test_platform_pull() {
|
||||
local image_name=$1
|
||||
local platform=$2
|
||||
local temp_container="test-$(echo $image_name | tr '/' '-')-${platform//[^a-zA-Z0-9]/}"
|
||||
|
||||
echo -e "${YELLOW}🧪 Testing ${image_name} pull for ${platform}...${NC}"
|
||||
|
||||
# Pull image for specific platform
|
||||
docker pull --platform "${platform}" "${image_name}:${VERSION}"
|
||||
|
||||
# Create and run a test container
|
||||
if [[ "$image_name" == *"backend"* ]]; then
|
||||
# Test backend - check if it starts
|
||||
docker run --rm --platform "${platform}" --name "${temp_container}" -d \
|
||||
-p 5001:5000 \
|
||||
-e NODE_ENV=test \
|
||||
"${image_name}:${VERSION}"
|
||||
|
||||
# Wait a moment and check if container is running
|
||||
sleep 5
|
||||
if docker ps | grep -q "${temp_container}"; then
|
||||
echo -e "${GREEN}✅ Backend container started successfully on ${platform}${NC}"
|
||||
docker stop "${temp_container}" >/dev/null 2>&1 || true
|
||||
else
|
||||
echo -e "${RED}❌ Backend container failed to start on ${platform}${NC}"
|
||||
fi
|
||||
else
|
||||
# Test frontend - check if nginx starts
|
||||
docker run --rm --platform "${platform}" --name "${temp_container}" -d \
|
||||
-p 8080:80 \
|
||||
"${image_name}:${VERSION}"
|
||||
|
||||
# Wait a moment and check if container is running
|
||||
sleep 5
|
||||
if docker ps | grep -q "${temp_container}"; then
|
||||
echo -e "${GREEN}✅ Frontend container started successfully on ${platform}${NC}"
|
||||
docker stop "${temp_container}" >/dev/null 2>&1 || true
|
||||
else
|
||||
echo -e "${RED}❌ Frontend container failed to start on ${platform}${NC}"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Clean up
|
||||
docker rmi "${image_name}:${VERSION}" >/dev/null 2>&1 || true
|
||||
echo ""
|
||||
}
|
||||
|
||||
# Check if images exist
|
||||
echo -e "${YELLOW}🔍 Checking if images exist...${NC}"
|
||||
if ! docker buildx imagetools inspect "${BACKEND_IMAGE}:${VERSION}" >/dev/null 2>&1; then
|
||||
echo -e "${RED}❌ Backend image ${BACKEND_IMAGE}:${VERSION} not found${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! docker buildx imagetools inspect "${FRONTEND_IMAGE}:${VERSION}" >/dev/null 2>&1; then
|
||||
echo -e "${RED}❌ Frontend image ${FRONTEND_IMAGE}:${VERSION} not found${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}✅ Both images found in registry${NC}"
|
||||
echo ""
|
||||
|
||||
# Inspect image manifests
|
||||
inspect_image "Backend" "${BACKEND_IMAGE}"
|
||||
inspect_image "Frontend" "${FRONTEND_IMAGE}"
|
||||
|
||||
# Test platform pulls (only test current platform to avoid emulation issues)
|
||||
CURRENT_PLATFORM=$(docker version --format '{{.Server.Arch}}')
|
||||
echo -e "${YELLOW}🏗️ Current platform detected: ${CURRENT_PLATFORM}${NC}"
|
||||
echo ""
|
||||
|
||||
if [[ "$CURRENT_PLATFORM" == "x86_64" ]]; then
|
||||
echo -e "${BLUE}Testing AMD64 platform...${NC}"
|
||||
test_platform_pull "${BACKEND_IMAGE}" "linux/amd64"
|
||||
test_platform_pull "${FRONTEND_IMAGE}" "linux/amd64"
|
||||
elif [[ "$CURRENT_PLATFORM" == "aarch64" ]] || [[ "$CURRENT_PLATFORM" == "arm64" ]]; then
|
||||
echo -e "${BLUE}Testing ARM64 platform...${NC}"
|
||||
test_platform_pull "${BACKEND_IMAGE}" "linux/arm64"
|
||||
test_platform_pull "${FRONTEND_IMAGE}" "linux/arm64"
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ Unknown platform ${CURRENT_PLATFORM}, skipping container tests${NC}"
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}🎉 Multi-architecture image verification completed!${NC}"
|
||||
echo ""
|
||||
echo -e "${BLUE}Summary:${NC}"
|
||||
echo " ✅ Images exist in registry"
|
||||
echo " ✅ Manifest lists contain multiple architectures"
|
||||
echo " ✅ Images can be pulled and run on current platform"
|
||||
echo ""
|
||||
echo -e "${BLUE}To test on other platforms, run this script on:${NC}"
|
||||
echo " - AMD64 (x86_64) machine for linux/amd64 testing"
|
||||
echo " - ARM64 (aarch64) machine for linux/arm64 testing"
|
||||
Reference in New Issue
Block a user