#!/usr/bin/env bash # Build and push multi-arch container images # Supports both Podman and Docker set -e # Configuration MANIFEST=git.hannover.ccc.de/lubiana/cheekylist AMD=${MANIFEST}:amd64 ARM=${MANIFEST}:arm64 # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Detect container runtime CONTAINER_CMD="" if command -v podman &> /dev/null; then CONTAINER_CMD="podman" elif command -v docker &> /dev/null; then CONTAINER_CMD="docker" else echo -e "${RED}❌ Neither Podman nor Docker found. Please install one of them.${NC}" exit 1 fi echo -e "${BLUE}🚀 Building multi-arch images with ${CONTAINER_CMD}...${NC}" # Check if runtime is available if ! $CONTAINER_CMD info > /dev/null 2>&1; then echo -e "${RED}❌ ${CONTAINER_CMD} is not running or not properly configured.${NC}" if [ "$CONTAINER_CMD" = "podman" ]; then echo -e "${YELLOW}💡 Try running: podman machine start${NC}" else echo -e "${YELLOW}💡 Please start Docker Desktop${NC}" fi exit 1 fi # Handle manifest differently for Docker vs Podman if [ "$CONTAINER_CMD" = "docker" ]; then # Docker uses buildx for multi-arch builds if ! docker buildx version > /dev/null 2>&1; then echo -e "${RED}❌ Docker buildx not found. Please update Docker.${NC}" exit 1 fi # Create or use existing buildx instance BUILDER_NAME="gocheck-builder" if ! docker buildx ls | grep -q "$BUILDER_NAME"; then echo -e "${YELLOW}📦 Creating buildx instance...${NC}" docker buildx create --name "$BUILDER_NAME" --use else docker buildx use "$BUILDER_NAME" fi # Build and push multi-arch image echo -e "${YELLOW}📦 Building and pushing multi-arch image...${NC}" docker buildx build \ --platform linux/amd64,linux/arm64 \ --tag "$MANIFEST:latest" \ --tag "$MANIFEST:$(date +%Y%m%d)" \ --push \ -f Containerfile \ . echo -e "${GREEN}✅ Multi-arch image pushed to $MANIFEST${NC}" else # Podman approach # Remove existing manifest if it exists $CONTAINER_CMD manifest exists $MANIFEST 2>/dev/null && $CONTAINER_CMD manifest rm $MANIFEST # Create new manifest echo -e "${YELLOW}📦 Creating manifest...${NC}" $CONTAINER_CMD manifest create $MANIFEST # Build AMD64 echo -e "${YELLOW}📦 Building AMD64 image...${NC}" $CONTAINER_CMD build --arch=amd64 -t $AMD -f Containerfile . # Build ARM64 echo -e "${YELLOW}📦 Building ARM64 image...${NC}" $CONTAINER_CMD build --arch=arm64 -t $ARM -f Containerfile . # Add to manifest echo -e "${YELLOW}📦 Adding images to manifest...${NC}" $CONTAINER_CMD manifest add $MANIFEST $AMD $CONTAINER_CMD manifest add $MANIFEST $ARM # Push manifest echo -e "${YELLOW}📦 Pushing manifest...${NC}" $CONTAINER_CMD manifest push $MANIFEST # Also tag and push as latest $CONTAINER_CMD tag $MANIFEST $MANIFEST:latest $CONTAINER_CMD manifest push $MANIFEST:latest # Tag with date DATE_TAG=$MANIFEST:$(date +%Y%m%d) $CONTAINER_CMD tag $MANIFEST $DATE_TAG $CONTAINER_CMD manifest push $DATE_TAG echo -e "${GREEN}✅ Multi-arch manifest pushed to $MANIFEST${NC}" fi echo -e "${GREEN}✅ Build and push completed successfully!${NC}" echo -e "${BLUE}📋 Images available at:${NC}" echo -e " - ${MANIFEST}:latest" echo -e " - ${MANIFEST}:$(date +%Y%m%d)"