forked from weam-ai/weam
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
61 lines (52 loc) · 1.93 KB
/
Copy pathbuild.sh
File metadata and controls
61 lines (52 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
# 🧰 Universal Docker Build Script (Cross-Platform + Compose v1/v2 Compatible)
echo "🔍 Detecting Operating System..."
case "$(uname -s)" in
Linux*) OS="Linux/Ubuntu" ;;
Darwin*) OS="macOS" ;;
MINGW*|MSYS*|CYGWIN*) OS="Windows (Git Bash/WSL)" ;;
*) echo "❌ Unsupported OS"; exit 1 ;;
esac
echo "✅ OS Detected: $OS"
echo "🔍 Checking Docker Compose version..."
if command -v docker-compose &> /dev/null; then
COMPOSE_CMD="docker-compose" # v1
elif docker compose version &> /dev/null; then
COMPOSE_CMD="docker compose" # v2
else
echo "❌ Docker Compose not found. Please install Docker Compose v1 or v2."
exit 1
fi
echo "✅ Docker Compose Command: $COMPOSE_CMD"
# Step 1: Build base image
echo "🚧 Step 1/5: Building base image (pybase_docker)..."
$COMPOSE_CMD build --no-cache pybase_docker || { echo "❌ Failed to build pybase_docker"; exit 1; }
echo "✅ pybase_docker image built successfully."
# Step 2: Load .env
echo "📄 Step 2/5: Loading environment variables..."
if [ ! -f .env ]; then
echo "❌ .env file not found!"
exit 1
fi
set -e
set -a
source .env
set +a
echo "✅ Environment variables loaded."
# Step 3: Determine build target
echo "🛠️ Step 3/5: Determining target environment..."
TARGET="production"
[ "$NEXT_PUBLIC_APP_ENVIRONMENT" == "development" ] && TARGET="development"
echo "✅ Target selected: $TARGET"
# Step 4: Convert .env keys into --build-arg
echo "⚙️ Step 4/5: Preparing build arguments..."
BUILD_ARGS=$(grep -v '^#' .env | sed '/^\s*$/d' | awk -F= '{print "--build-arg " $1}' | xargs)
echo "✅ Build arguments prepared."
# Step 5: Build final frontend image
echo "🚀 Step 5/5: Building frontend Docker image (weamai-app)..."
docker build $BUILD_ARGS \
--target=$TARGET \
-f ./nextjs/Dockerfile \
-t weamai-app:latest \
./nextjs --no-cache || { echo "❌ Docker build failed"; exit 1; }
echo "🎉 Build complete: weamai-app:latest"