feat: Enable multi-platform Docker builds and dynamic image tagging
- Detect host architecture to set build platform - Support multi-platform builds when MULTI_PLATFORM=1 or CONTAINER_REGISTRY is set - Dynamically set image tag based on registry and platform - Pull pushed images for local validation - Update all docker run and inspect commands to use dynamic image tag
This commit is contained in:
@@ -230,6 +230,8 @@ main() {
|
|||||||
|
|
||||||
# Handle status only
|
# Handle status only
|
||||||
if [[ "$status_only" == true ]]; then
|
if [[ "$status_only" == true ]]; then
|
||||||
|
load_env "$env_file"
|
||||||
|
NAMESPACE="${NAMESPACE:-rxminder}"
|
||||||
show_status
|
show_status
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ print_success "Environment files exist"
|
|||||||
|
|
||||||
# Validate environment consistency
|
# Validate environment consistency
|
||||||
print_status "2. Checking environment variable consistency..."
|
print_status "2. Checking environment variable consistency..."
|
||||||
./validate-env.sh
|
./scripts/validate-env.sh
|
||||||
|
|
||||||
print_status "3. Setting up Docker Buildx..."
|
print_status "3. Setting up Docker Buildx..."
|
||||||
|
|
||||||
@@ -80,9 +80,35 @@ docker buildx use meds-builder
|
|||||||
|
|
||||||
print_status "4. Building multi-platform Docker image with buildx..."
|
print_status "4. Building multi-platform Docker image with buildx..."
|
||||||
|
|
||||||
# Build the image with buildx for multiple platforms
|
# Determine host platform
|
||||||
|
HOST_ARCH="$(uname -m)"
|
||||||
|
case "$HOST_ARCH" in
|
||||||
|
x86_64) HOST_PLATFORM="linux/amd64" ;;
|
||||||
|
aarch64|arm64) HOST_PLATFORM="linux/arm64" ;;
|
||||||
|
*) HOST_PLATFORM="linux/amd64" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Decide build strategy:
|
||||||
|
# Enable multi-platform (push) if MULTI_PLATFORM=1 or CONTAINER_REGISTRY is set
|
||||||
|
if [[ "${MULTI_PLATFORM:-0}" == "1" || -n "${CONTAINER_REGISTRY:-}" ]]; then
|
||||||
|
BUILD_PLATFORMS="linux/amd64,linux/arm64"
|
||||||
|
EXPORT_MODE="--push"
|
||||||
|
# If CONTAINER_REGISTRY provided, ensure trailing slash
|
||||||
|
if [[ -n "${CONTAINER_REGISTRY:-}" && "${CONTAINER_REGISTRY}" != */ ]]; then
|
||||||
|
CONTAINER_REGISTRY="${CONTAINER_REGISTRY}/"
|
||||||
|
fi
|
||||||
|
IMAGE_TAG="${IMAGE_TAG:-${CONTAINER_REGISTRY:-}meds-validation:latest}"
|
||||||
|
print_status "Multi-platform build enabled (platforms: $BUILD_PLATFORMS) -> push $IMAGE_TAG"
|
||||||
|
else
|
||||||
|
BUILD_PLATFORMS="$HOST_PLATFORM"
|
||||||
|
EXPORT_MODE="--load"
|
||||||
|
IMAGE_TAG="${IMAGE_TAG:-meds-validation}"
|
||||||
|
print_status "Single-platform build ($BUILD_PLATFORMS) -> load locally as $IMAGE_TAG"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Perform build
|
||||||
docker buildx build --no-cache \
|
docker buildx build --no-cache \
|
||||||
--platform linux/amd64,linux/arm64 \
|
--platform "$BUILD_PLATFORMS" \
|
||||||
--build-arg COUCHDB_USER="${COUCHDB_USER:-admin}" \
|
--build-arg COUCHDB_USER="${COUCHDB_USER:-admin}" \
|
||||||
--build-arg COUCHDB_PASSWORD="${COUCHDB_PASSWORD:-change-this-secure-password}" \
|
--build-arg COUCHDB_PASSWORD="${COUCHDB_PASSWORD:-change-this-secure-password}" \
|
||||||
--build-arg VITE_COUCHDB_URL="${VITE_COUCHDB_URL:-http://localhost:5984}" \
|
--build-arg VITE_COUCHDB_URL="${VITE_COUCHDB_URL:-http://localhost:5984}" \
|
||||||
@@ -95,10 +121,16 @@ docker buildx build --no-cache \
|
|||||||
--build-arg MAILGUN_DOMAIN="${MAILGUN_DOMAIN:-}" \
|
--build-arg MAILGUN_DOMAIN="${MAILGUN_DOMAIN:-}" \
|
||||||
--build-arg MAILGUN_FROM_EMAIL="${MAILGUN_FROM_EMAIL:-}" \
|
--build-arg MAILGUN_FROM_EMAIL="${MAILGUN_FROM_EMAIL:-}" \
|
||||||
--build-arg NODE_ENV="${NODE_ENV:-production}" \
|
--build-arg NODE_ENV="${NODE_ENV:-production}" \
|
||||||
-t meds-validation \
|
-t "$IMAGE_TAG" \
|
||||||
--load \
|
$EXPORT_MODE \
|
||||||
.
|
.
|
||||||
|
|
||||||
|
# If we pushed (multi-platform), pull the host-specific image for local tests
|
||||||
|
if [[ "$EXPORT_MODE" == "--push" ]]; then
|
||||||
|
print_status "Pulling image $IMAGE_TAG for local validation..."
|
||||||
|
docker pull "$IMAGE_TAG"
|
||||||
|
fi
|
||||||
|
|
||||||
print_success "Docker image built successfully"
|
print_success "Docker image built successfully"
|
||||||
|
|
||||||
print_status "5. Testing container startup and health..."
|
print_status "5. Testing container startup and health..."
|
||||||
@@ -107,7 +139,7 @@ print_status "5. Testing container startup and health..."
|
|||||||
docker run --rm -d \
|
docker run --rm -d \
|
||||||
-p 8083:80 \
|
-p 8083:80 \
|
||||||
--name meds-validation-test \
|
--name meds-validation-test \
|
||||||
meds-validation
|
"$IMAGE_TAG"
|
||||||
|
|
||||||
# Wait for container to start
|
# Wait for container to start
|
||||||
sleep 5
|
sleep 5
|
||||||
@@ -176,13 +208,13 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
print_status "9. Checking image size..."
|
print_status "9. Checking image size..."
|
||||||
IMAGE_SIZE=$(docker image inspect meds-validation --format='{{.Size}}' | numfmt --to=iec)
|
IMAGE_SIZE=$(docker image inspect "$IMAGE_TAG" --format='{{.Size}}' | numfmt --to=iec)
|
||||||
print_success "Image size: $IMAGE_SIZE"
|
print_success "Image size: $IMAGE_SIZE"
|
||||||
|
|
||||||
print_status "10. Validating security configuration..."
|
print_status "10. Validating security configuration..."
|
||||||
|
|
||||||
# Check if image runs as non-root
|
# Check if image runs as non-root
|
||||||
USER_INFO=$(docker run --rm meds-validation whoami)
|
USER_INFO=$(docker run --rm "$IMAGE_TAG" whoami)
|
||||||
if [[ "$USER_INFO" != "root" ]]; then
|
if [[ "$USER_INFO" != "root" ]]; then
|
||||||
print_success "Container runs as non-root user: $USER_INFO"
|
print_success "Container runs as non-root user: $USER_INFO"
|
||||||
else
|
else
|
||||||
@@ -190,7 +222,7 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Check nginx configuration
|
# Check nginx configuration
|
||||||
if docker run --rm meds-validation nginx -t 2>/dev/null; then
|
if docker run --rm "$IMAGE_TAG" nginx -t 2>/dev/null; then
|
||||||
print_success "Nginx configuration is valid"
|
print_success "Nginx configuration is valid"
|
||||||
else
|
else
|
||||||
print_error "Nginx configuration has issues"
|
print_error "Nginx configuration has issues"
|
||||||
|
|||||||
Reference in New Issue
Block a user