forked from podly-pure-podcasts/podly_pure_podcasts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_podly_docker.sh
More file actions
executable file
·271 lines (250 loc) · 8.67 KB
/
Copy pathrun_podly_docker.sh
File metadata and controls
executable file
·271 lines (250 loc) · 8.67 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/bin/bash
# Colors for output
YELLOW='\033[1;33m'
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
# Central configuration defaults
CUDA_VERSION="12.4.1"
ROCM_VERSION="6.4"
CPU_BASE_IMAGE="python:3.11-slim"
GPU_NVIDIA_BASE_IMAGE="nvidia/cuda:${CUDA_VERSION}-cudnn-devel-ubuntu22.04"
GPU_ROCM_BASE_IMAGE="rocm/dev-ubuntu-22.04:${ROCM_VERSION}-complete"
# Read server URL from config.yml if it exists
SERVER_URL=""
if [ -f "config/config.yml" ]; then
SERVER_URL=$(grep "^server:" config/config.yml | cut -d' ' -f2- | tr -d ' ')
if [ -n "$SERVER_URL" ]; then
# Remove http:// or https:// prefix to get just the hostname
CLEAN_URL=$(echo "$SERVER_URL" | sed 's|^https\?://||')
export VITE_API_URL="http://${CLEAN_URL}:5001"
echo -e "${GREEN}Using server URL from config.yml: ${VITE_API_URL}${NC}"
fi
fi
# Check dependencies
echo -e "${YELLOW}Checking dependencies...${NC}"
if ! command -v docker &> /dev/null; then
echo -e "${RED}Docker not found. Please install Docker first.${NC}"
exit 1
fi
if ! docker compose version &> /dev/null; then
echo -e "${RED}Docker Compose not found. Please install Docker Compose V2.${NC}"
exit 1
fi
# Default values
BUILD_ONLY=false
TEST_BUILD=false
FORCE_CPU=false
FORCE_GPU=false
DETACHED=false
PRODUCTION_MODE=true
REBUILD=false
BRANCH_SUFFIX="main"
LITE_BUILD=false
# Detect NVIDIA GPU
NVIDIA_GPU_AVAILABLE=false
if command -v nvidia-smi &> /dev/null && nvidia-smi &> /dev/null; then
NVIDIA_GPU_AVAILABLE=true
echo -e "${GREEN}NVIDIA GPU detected.${NC}"
fi
# Detect ROCM GPU
AMD_GPU_AVAILABLE=false
if command -v rocm-smi &> /dev/null && rocm-smi &> /dev/null; then
AMD_GPU_AVAILABLE=true
echo -e "${GREEN}ROCM GPU detected.${NC}"
fi
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--build)
BUILD_ONLY=true
;;
--test-build)
TEST_BUILD=true
;;
--gpu)
FORCE_GPU=true
;;
--cpu)
FORCE_CPU=true
;;
--cuda=*)
CUDA_VERSION="${1#*=}"
GPU_NVIDIA_BASE_IMAGE="nvidia/cuda:${CUDA_VERSION}-cudnn-devel-ubuntu22.04"
;;
--rocm=*)
ROCM_VERSION="${1#*=}"
GPU_ROCM_BASE_IMAGE="rocm/dev-ubuntu-22.04:${ROCM_VERSION}-complete"
;;
-d|--detach|-b|--background)
DETACHED=true
;;
--dev)
REBUILD=true
PRODUCTION_MODE=false
;;
--rebuild)
REBUILD=true
;;
--production)
PRODUCTION_MODE=true
;;
--branch=*)
BRANCH_NAME="${1#*=}"
BRANCH_SUFFIX="${BRANCH_NAME}"
;;
--lite)
LITE_BUILD=true
;;
-h|--help)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --build Build containers only (don't start)"
echo " --test-build Test build with no cache"
echo " --gpu Force GPU mode"
echo " --cpu Force CPU mode"
echo " --cuda=VERSION Specify CUDA version"
echo " --rocm=VERSION Specify ROCM version"
echo " -d, --detach Run in detached/background mode"
echo " -b, --background Alias for --detach"
echo " --dev Development mode (rebuild containers)"
echo " --rebuild Rebuild containers before starting"
echo " --production Use published images (default)"
echo " --branch=BRANCH Use specific branch images"
echo " --lite Build without Whisper (smaller image, remote transcription only)"
echo " -h, --help Show this help message"
exit 0
;;
*)
echo "Unknown argument: $1"
echo "Usage: $0 [--build] [--test-build] [--gpu] [--cpu] [--cuda=VERSION] [--rocm=VERSION] [-d|--detach] [-b|--background] [--dev] [--rebuild] [--production] [--branch=BRANCH_NAME] [--lite] [-h|--help]"
exit 1
;;
esac
shift
done
# Determine if GPU should be used based on availability and flags
USE_GPU=false
USE_GPU_NVIDIA=false
USE_GPU_AMD=false
if [ "$FORCE_CPU" = true ]; then
USE_GPU=false
echo -e "${YELLOW}Forcing CPU mode${NC}"
elif [ "$FORCE_GPU" = true ]; then
if [ "$NVIDIA_GPU_AVAILABLE" = true ]; then
USE_GPU=true
USE_GPU_NVIDIA=true
echo -e "${YELLOW}Forcing GPU mode (NVIDIA detected)${NC}"
elif [ "$AMD_GPU_AVAILABLE" = true ]; then
USE_GPU=true
USE_GPU_AMD=true
echo -e "${YELLOW}Forcing GPU mode (AMD detected)${NC}"
else
echo -e "${RED}Error: GPU requested but no compatible GPU detected. Please install NVIDIA or AMD GPU drivers.${NC}"
exit 1
fi
elif [ "$NVIDIA_GPU_AVAILABLE" = true ]; then
USE_GPU=true
USE_GPU_NVIDIA=true
echo -e "${YELLOW}Using GPU mode (auto-detected)${NC}"
elif [ "${AMD_GPU_AVAILABLE}" = true ]; then
USE_GPU=true
USE_GPU_AMD=true
echo -e "${YELLOW}Using GPU mode (auto-detected)${NC}"
else
echo -e "${YELLOW}Using CPU mode (no GPU detected)${NC}"
fi
# Set base image and CUDA environment
if [ "$USE_GPU_NVIDIA" = true ]; then
BASE_IMAGE="$GPU_NVIDIA_BASE_IMAGE"
CUDA_VISIBLE_DEVICES=0
elif [ "${USE_GPU_AMD}" = true ]; then
BASE_IMAGE="${GPU_ROCM_BASE_IMAGE}"
CUDA_VISIBLE_DEVICES=0
else
BASE_IMAGE="$CPU_BASE_IMAGE"
CUDA_VISIBLE_DEVICES=-1
fi
# Get current user's UID and GID
export PUID=$(id -u)
export PGID=$(id -g)
export BASE_IMAGE
export CUDA_VERSION
export ROCM_VERSION
export CUDA_VISIBLE_DEVICES
export USE_GPU
export USE_GPU_NVIDIA
export USE_GPU_AMD
export LITE_BUILD
# Surface authentication/session configuration warnings
REQUIRE_AUTH_LOWER=$(printf '%s' "${REQUIRE_AUTH:-false}" | tr '[:upper:]' '[:lower:]')
if [ "$REQUIRE_AUTH_LOWER" = "true" ]; then
if [ -z "${PODLY_SECRET_KEY}" ]; then
echo -e "${YELLOW}Warning: REQUIRE_AUTH is true but PODLY_SECRET_KEY is not set. Sessions will be reset on every restart.${NC}"
fi
fi
# Setup Docker Compose configuration
if [ "$PRODUCTION_MODE" = true ]; then
COMPOSE_FILES="-f compose.yml"
# Set branch tag based on GPU detection and branch
if [ "$LITE_BUILD" = true ] && [ "$USE_GPU" = true ]; then
echo -e "${RED}Error: --lite cannot be combined with GPU builds. Use --cpu or drop --lite.${NC}"
exit 1
fi
if [ "$LITE_BUILD" = true ]; then
BRANCH="${BRANCH_SUFFIX}-lite"
elif [ "$USE_GPU_NVIDIA" = true ]; then
BRANCH="${BRANCH_SUFFIX}-gpu-nvidia"
elif [ "$USE_GPU_AMD" = true ]; then
BRANCH="${BRANCH_SUFFIX}-gpu-amd"
else
BRANCH="${BRANCH_SUFFIX}-latest"
fi
export BRANCH
echo -e "${YELLOW}Production mode - using published images${NC}"
echo -e "${YELLOW} Branch tag: ${BRANCH}${NC}"
if [ "$BRANCH_SUFFIX" != "main" ]; then
echo -e "${GREEN}Using custom branch: ${BRANCH_SUFFIX}${NC}"
fi
else
COMPOSE_FILES="-f compose.dev.cpu.yml"
if [ "$USE_GPU_NVIDIA" = true ]; then
COMPOSE_FILES="$COMPOSE_FILES -f compose.dev.nvidia.yml"
fi
if [ "$USE_GPU_AMD" = true ]; then
COMPOSE_FILES="$COMPOSE_FILES -f compose.dev.rocm.yml"
fi
if [ "$REBUILD" = true ]; then
echo -e "${YELLOW}Rebuild mode - will rebuild containers before starting${NC}"
fi
if [ "$LITE_BUILD" = true ]; then
echo -e "${YELLOW}Lite mode - building without Whisper (remote transcription only)${NC}"
fi
fi
# Execute appropriate Docker Compose command
if [ "$BUILD_ONLY" = true ]; then
echo -e "${YELLOW}Building containers only...${NC}"
docker compose $COMPOSE_FILES build
echo -e "${GREEN}Build completed successfully.${NC}"
elif [ "$TEST_BUILD" = true ]; then
echo -e "${YELLOW}Testing build with no cache...${NC}"
docker compose $COMPOSE_FILES build --no-cache
echo -e "${GREEN}Test build completed successfully.${NC}"
else
# Handle development rebuild
if [ "$REBUILD" = true ]; then
echo -e "${YELLOW}Rebuilding containers...${NC}"
docker compose $COMPOSE_FILES build
fi
if [ "$DETACHED" = true ]; then
echo -e "${YELLOW}Starting Podly in detached mode...${NC}"
docker compose $COMPOSE_FILES up -d
echo -e "${GREEN}Podly is running in the background.${NC}"
echo -e "${GREEN}Application: http://localhost:5001${NC}"
else
echo -e "${YELLOW}Starting Podly...${NC}"
echo -e "${GREEN}Application will be available at: http://localhost:5001${NC}"
docker compose $COMPOSE_FILES up
fi
fi