-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
Β·170 lines (144 loc) Β· 6 KB
/
deploy.sh
File metadata and controls
executable file
Β·170 lines (144 loc) Β· 6 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/bin/bash
# BikeButler Deployment Script
# Converted from docker-compose.yml for servers without docker-compose
set -e # Exit on any error
echo "π Starting BikeButler deployment..."
# Configuration (from docker-compose.yml)
IMAGE_NAME="bikebutler"
CONTAINER_NAME="bikebutler"
PORT_MAPPING="8675:5000"
# Check if .env file exists
if [ ! -f .env ]; then
echo "β Error: .env file not found!"
echo " Please create a .env file with your environment variables."
exit 1
fi
# Extract build args from .env file (safely handle missing variables and quotes)
echo "π Checking environment variables..."
# Function to extract value and remove surrounding quotes
extract_env_value() {
local key=$1
local value=$(grep "^${key}=" .env 2>/dev/null | cut -d '=' -f2-)
# Remove surrounding single or double quotes
value=$(echo "$value" | sed 's/^["'"'"']//' | sed 's/["'"'"']$//')
echo "$value"
}
MAPBOX_TOKEN=$(extract_env_value "NUXT_PUBLIC_MAPBOX_TOKEN")
GOOGLE_MAPS_PUBLIC_KEY=$(extract_env_value "NUXT_PUBLIC_GOOGLE_MAPS_API_KEY")
GTAG_ID=$(extract_env_value "NUXT_PUBLIC_GTAG_ID")
# Debug: Show what we found (without revealing the full keys)
if [ -n "$MAPBOX_TOKEN" ]; then
echo "β
Found NUXT_PUBLIC_MAPBOX_TOKEN (${#MAPBOX_TOKEN} characters)"
else
echo "β NUXT_PUBLIC_MAPBOX_TOKEN not found in .env"
fi
if [ -n "$GOOGLE_MAPS_PUBLIC_KEY" ]; then
echo "β
Found NUXT_PUBLIC_GOOGLE_MAPS_API_KEY (${#GOOGLE_MAPS_PUBLIC_KEY} characters)"
echo " Key starts with: ${GOOGLE_MAPS_PUBLIC_KEY:0:10}..."
# Check if the original value had quotes
ORIGINAL_GOOGLE=$(grep "^NUXT_PUBLIC_GOOGLE_MAPS_API_KEY=" .env | cut -d '=' -f2-)
if [[ "$ORIGINAL_GOOGLE" == \"*\" ]] || [[ "$ORIGINAL_GOOGLE" == \'*\' ]]; then
echo " βΉοΈ Removed surrounding quotes from Google Maps key"
fi
else
echo "β NUXT_PUBLIC_GOOGLE_MAPS_API_KEY not found in .env"
fi
if [ -n "$GTAG_ID" ]; then
echo "β
Found NUXT_PUBLIC_GTAG_ID ($GTAG_ID)"
else
echo "β οΈ NUXT_PUBLIC_GTAG_ID not found in .env (Google Analytics will be disabled)"
fi
# Show .env file format for debugging
echo "π Current .env file contains these NUXT_PUBLIC variables:"
grep "^NUXT_PUBLIC" .env | sed 's/=.*/=***/' || echo " No NUXT_PUBLIC variables found"
# Stop and remove existing container if it exists
echo "π Stopping existing container..."
docker stop $CONTAINER_NAME 2>/dev/null || true
docker rm $CONTAINER_NAME 2>/dev/null || true
# Remove old image to force rebuild (optional - comment out if you want to keep old images)
# docker rmi $IMAGE_NAME:latest 2>/dev/null || true
# Build the image with build args (matching docker-compose.yml build section)
echo "π¨ Building Docker image..."
echo " Passing build args:"
echo " - NUXT_PUBLIC_MAPBOX_TOKEN: ${MAPBOX_TOKEN:+SET (${#MAPBOX_TOKEN} chars)}${MAPBOX_TOKEN:+}${MAPBOX_TOKEN:-NOT SET}"
echo " - NUXT_PUBLIC_GOOGLE_MAPS_API_KEY: ${GOOGLE_MAPS_PUBLIC_KEY:+SET (${#GOOGLE_MAPS_PUBLIC_KEY} chars)}${GOOGLE_MAPS_PUBLIC_KEY:-NOT SET}"
docker build \
--build-arg NUXT_PUBLIC_MAPBOX_TOKEN="$MAPBOX_TOKEN" \
--build-arg NUXT_PUBLIC_GOOGLE_MAPS_API_KEY="$GOOGLE_MAPS_PUBLIC_KEY" \
--build-arg NUXT_PUBLIC_GTAG_ID="$GTAG_ID" \
-t $IMAGE_NAME:latest .
# --no-cache
if [ $? -ne 0 ]; then
echo "β Docker build failed!"
exit 1
fi
echo "β
Build completed successfully!"
# Run the container with all settings from docker-compose.yml
echo "π’ Starting container..."
docker run -d \
--name $CONTAINER_NAME \
-p $PORT_MAPPING \
--memory=10g \
--memory-swap=10g \
--env-file .env \
-v "$(pwd)/backend/Bikeability/routing/flask_api/data/pano_thumbnails:/app/Bikeability/routing/flask_api/data/pano_thumbnails:ro" \
-e GUNICORN_WORKERS=2\
-e GUNICORN_TIMEOUT=120 \
-e LOG_LEVEL=info \
--restart unless-stopped \
--health-cmd "curl -f http://localhost:5000/api/health" \
--health-interval=60s \
--health-timeout=10s \
--health-retries=3 \
--health-start-period=60s \
$IMAGE_NAME:latest
# Wait a moment for container to start
echo "β³ Waiting for container to start..."
sleep 5
# Check if container is running
if docker ps --filter "name=$CONTAINER_NAME" --filter "status=running" | grep -q $CONTAINER_NAME; then
echo "β
BikeButler container is running!"
# Wait for health check
echo "β³ Waiting for health check to pass..."
for i in {1..20}; do
HEALTH_STATUS=$(docker inspect --format='{{.State.Health.Status}}' $CONTAINER_NAME 2>/dev/null || echo "none")
case $HEALTH_STATUS in
"healthy")
echo "β
Application is healthy and ready!"
break
;;
"unhealthy")
echo "β Health check failed!"
docker logs --tail 20 $CONTAINER_NAME
exit 1
;;
"starting"|"none")
echo " Health check attempt $i/20..."
sleep 10
;;
esac
if [ $i -eq 20 ]; then
echo "β οΈ Health check timeout, but container is running"
echo " Check logs if there are issues: docker logs $CONTAINER_NAME"
fi
done
echo ""
echo "π Deployment completed successfully!"
echo "π Application should be available at: http://your-server:8675"
echo ""
echo "Useful commands:"
echo " π View logs: docker logs $CONTAINER_NAME"
echo " π Follow logs: docker logs -f $CONTAINER_NAME"
echo " π Check status: docker ps | grep $CONTAINER_NAME"
echo " π Stop container: docker stop $CONTAINER_NAME"
echo " ποΈ Remove container: docker rm $CONTAINER_NAME"
echo " π Restart container: docker restart $CONTAINER_NAME"
else
echo "β Container failed to start!"
echo "π Container logs:"
docker logs $CONTAINER_NAME 2>/dev/null || echo "No logs available"
echo ""
echo "π Container status:"
docker ps -a --filter "name=$CONTAINER_NAME"
exit 1
fi