Files
VoiceRSSSummary/build-docker-image.sh
2025-06-12 09:00:16 +09:00

85 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
# Build Docker image for Voice RSS Summary project
# Usage: ./build-docker-image.sh [tag] [--platform=platform] [build-args...]
IMAGE_NAME="voice-rss-summary"
TAG="latest"
PLATFORM=""
BUILD_ARGS=()
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
--platform=*)
PLATFORM="${1#*=}"
shift
;;
--platform)
PLATFORM="$2"
shift 2
;;
-*)
BUILD_ARGS+=("$1")
shift
;;
*)
if [[ -z "${TAG_SET:-}" ]]; then
TAG="$1"
TAG_SET=true
else
BUILD_ARGS+=("$1")
fi
shift
;;
esac
done
FULL_TAG="${IMAGE_NAME}:${TAG}"
echo "Building Docker image: ${FULL_TAG}"
echo "Build context: $(pwd)"
if [[ -n "$PLATFORM" ]]; then
echo "Target platform: ${PLATFORM}"
fi
# Check if Dockerfile exists
if [[ ! -f "Dockerfile" ]]; then
echo "Error: Dockerfile not found in current directory"
exit 1
fi
# Build with build cache and progress output
DOCKER_CMD=(docker build --tag "${FULL_TAG}" --progress=plain --build-arg BUILDKIT_INLINE_CACHE=1)
# Add platform if specified
if [[ -n "$PLATFORM" ]]; then
DOCKER_CMD+=(--platform "$PLATFORM")
fi
# Add any additional build args
if [[ ${#BUILD_ARGS[@]} -gt 0 ]]; then
DOCKER_CMD+=("${BUILD_ARGS[@]}")
fi
# Add build context
DOCKER_CMD+=(.)
echo "Running: ${DOCKER_CMD[*]}"
"${DOCKER_CMD[@]}"
# Display image info
echo ""
echo "Build completed successfully!"
echo "Image: ${FULL_TAG}"
if [[ -n "$PLATFORM" ]]; then
echo "Platform: ${PLATFORM}"
fi
echo "Size: $(docker images --format 'table {{.Size}}' "${FULL_TAG}" | tail -n +2)"
echo ""
echo "To run the container, use: ./run-docker.sh"
if [[ -n "$PLATFORM" && "$PLATFORM" != "linux/amd64" ]]; then
echo "Note: Cross-platform image built. May need to push to registry for deployment."
fi