-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
62 lines (52 loc) · 1.73 KB
/
deploy.sh
File metadata and controls
62 lines (52 loc) · 1.73 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
62
#!/bin/bash
# --- Configuration ---
APP_NAME="codestream-api"
PORT=80 # Expose on port 80 (HTTP default)
# ---------------------
echo "🚀 Starting Deployment for $APP_NAME..."
# 1. Install Docker if not present
if ! command -v docker &> /dev/null; then
echo "📦 Docker not found. Installing..."
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
rm get-docker.sh
else
echo "✅ Docker is already installed."
fi
# 2. Pull latest code (Assumes this script is run inside the repo)
echo "Ep Pulling latest changes from git..."
git pull
# 3. Check for .env file
if [ ! -f .env ]; then
echo "⚠️ WARNING: .env file not found!"
echo " Please create a .env file with REDIS_URL before running."
echo " Example: echo 'REDIS_URL=redis://...' > .env"
exit 1
fi
# 4. Build Docker Image
echo "cz Building Docker Image..."
# We build from the root context because it's a monorepo
docker build -f apps/api/Dockerfile -t $APP_NAME .
# 5. Stop & Remove Old Container
if [ "$(docker ps -q -f name=$APP_NAME)" ]; then
echo "vz Stopping existing container..."
docker stop $APP_NAME
fi
if [ "$(docker ps -aq -f name=$APP_NAME)" ]; then
echo "ox Removing old container..."
docker rm $APP_NAME
fi
# 6. Run New Container
echo "cz Starting new container..."
# -v /var/run/docker.sock:/var/run/docker.sock : Critical for "Docker-in-Docker" capability
# --network host : Optional, but mapping ports is usually safer.
docker run -d \
--name $APP_NAME \
--restart unless-stopped \
-p $PORT:4000 \
-v /var/run/docker.sock:/var/run/docker.sock \
--env-file .env \
$APP_NAME
echo "✅ Deployment Complete!"
echo " API is running on port $PORT"
echo " View logs with: docker logs -f $APP_NAME"