Files
retail-nest/build-and-push.sh
Phuoc Nguyen 7319f260d8 22
2025-10-10 17:41:07 +07:00

50 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
# Build and Push Multi-Platform Docker Image Script
# This script builds the Docker image for multiple platforms (Linux amd64, arm64)
# and pushes it to a registry
set -e # Exit on error
# Configuration
IMAGE_NAME="retail-backend"
REGISTRY="renolation" # Change this to your Docker Hub username or registry URL
VERSION="latest"
FULL_IMAGE="${REGISTRY}/${IMAGE_NAME}:${VERSION}"
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${BLUE}🔧 Setting up Docker Buildx...${NC}"
# Create and use a new builder instance that supports multi-platform builds
docker buildx create --use --name multiplatform-builder --driver docker-container --bootstrap 2>/dev/null || docker buildx use multiplatform-builder
echo -e "${BLUE}🏗️ Building multi-platform Docker image...${NC}"
echo -e "${YELLOW} Platforms: linux/amd64, linux/arm64${NC}"
echo -e "${YELLOW} Image: ${FULL_IMAGE}${NC}"
echo ""
# Build and push for multiple platforms
docker buildx build \
--platform linux/amd64,linux/arm64 \
--tag ${FULL_IMAGE} \
--push \
.
echo ""
echo -e "${GREEN}✅ Successfully built and pushed multi-platform image: ${FULL_IMAGE}${NC}"
echo ""
echo -e "${BLUE}📦 Image supports:${NC}"
echo " - Linux AMD64 (x86_64) - Most cloud servers, VPS"
echo " - Linux ARM64 (aarch64) - AWS Graviton, Raspberry Pi, Apple Silicon"
echo ""
echo -e "${BLUE}📝 To use this image on another server, run:${NC}"
echo " docker pull ${FULL_IMAGE}"
echo " docker-compose -f docker-compose.prod.yml up -d"
echo ""
echo -e "${BLUE}🔍 To inspect the image:${NC}"
echo " docker buildx imagetools inspect ${FULL_IMAGE}"