This commit is contained in:
Phuoc Nguyen
2025-10-10 17:41:07 +07:00
parent 8c34460889
commit 7319f260d8
2 changed files with 36 additions and 14 deletions

View File

@@ -18,7 +18,7 @@ COPY . .
RUN npm run build RUN npm run build
# Stage 2: Production # Stage 2: Production
FROM node:18-alpine AS production FROM node:22-alpine AS production
WORKDIR /app WORKDIR /app

View File

@@ -1,7 +1,8 @@
#!/bin/bash #!/bin/bash
# Build and Push Docker Image Script # Build and Push Multi-Platform Docker Image Script
# This script builds the Docker image and pushes it to a registry # This script builds the Docker image for multiple platforms (Linux amd64, arm64)
# and pushes it to a registry
set -e # Exit on error set -e # Exit on error
@@ -11,17 +12,38 @@ REGISTRY="renolation" # Change this to your Docker Hub username or registry URL
VERSION="latest" VERSION="latest"
FULL_IMAGE="${REGISTRY}/${IMAGE_NAME}:${VERSION}" FULL_IMAGE="${REGISTRY}/${IMAGE_NAME}:${VERSION}"
echo "🏗️ Building Docker image..." # Colors for output
docker build -t ${IMAGE_NAME}:${VERSION} . GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo "🏷️ Tagging image for registry..." echo -e "${BLUE}🔧 Setting up Docker Buildx...${NC}"
docker tag ${IMAGE_NAME}:${VERSION} ${FULL_IMAGE} # 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 "📤 Pushing image to registry..." echo -e "${BLUE}🏗️ Building multi-platform Docker image...${NC}"
docker push ${FULL_IMAGE} echo -e "${YELLOW} Platforms: linux/amd64, linux/arm64${NC}"
echo -e "${YELLOW} Image: ${FULL_IMAGE}${NC}"
echo "✅ Successfully built and pushed: ${FULL_IMAGE}"
echo "" echo ""
echo "To use this image on another server, run:"
# 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 pull ${FULL_IMAGE}"
echo " docker-compose -f docker-compose.prod.yml up -d" 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}"