forked from verifywise-ai/verifywise
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·91 lines (77 loc) · 2.96 KB
/
install.sh
File metadata and controls
executable file
·91 lines (77 loc) · 2.96 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
#!/bin/bash
# Function to detect whether to use `docker-compose` or `docker compose`
detect_docker_compose() {
if command -v docker-compose &> /dev/null; then
DOCKER_COMPOSE_CMD="docker-compose"
elif docker compose version &> /dev/null; then
DOCKER_COMPOSE_CMD="docker compose"
else
echo "Error: Neither 'docker-compose' nor 'docker compose' is available. Please install Docker Compose."
exit 1
fi
}
# Function to check and download Docker Compose files
check_and_download_compose_files() {
if [ ! -f "docker-compose.yml" ]; then
echo "docker-compose.yml not found. Downloading..."
curl -fS --output docker-compose.yml https://raw.githubusercontent.com/bluewave-labs/verifywise/develop/docker-compose.yml
if [ $? -ne 0 ]; then
echo "Error: Failed to download docker-compose.yml. Please check your internet connection or the URL."
exit 1
fi
fi
if [ ! -f "docker-compose.prod.yml" ]; then
echo "docker-compose.prod.yml not found. Downloading..."
curl -fS --output docker-compose.prod.yml https://raw.githubusercontent.com/bluewave-labs/verifywise/develop/docker-compose.prod.yml
if [ $? -ne 0 ]; then
echo "Error: Failed to download docker-compose.prod.yml. Please check your internet connection or the URL."
exit 1
fi
fi
}
# Function to read environment variables from .env file
load_env() {
ENV_FILE=$1
if [ -f $ENV_FILE ]; then
export $(cat $ENV_FILE | grep -v '#' | awk '/=/ {print $1}')
else
echo "Error: $ENV_FILE file not found"
exit 1
fi
}
wait_for_postgres() {
echo "Waiting for PostgreSQL to be ready..."
# Get the PostgreSQL container ID
PG_CONTAINER=$($DOCKER_COMPOSE_CMD ps | grep postgresdb | grep Up | awk '{print $1}')
# Wait for PostgreSQL to be ready to accept connections
if [ -z "$PG_CONTAINER" ]; then
echo "Error: PostgreSQL container not found or not running. Please ensure the container name matches 'postgresdb' in your docker-compose.yml file."
exit 1
fi
until docker exec $PG_CONTAINER pg_isready; do
echo "PostgreSQL is unavailable - sleeping"
sleep 1
done
echo "PostgreSQL is ready!"
}
# Main script
main() {
detect_docker_compose
ENVIRONMENT=${1:-prod}
echo "Running in $ENVIRONMENT mode"
# Check and download Docker Compose files if needed
check_and_download_compose_files
# Start Docker Compose
echo "Starting Docker Compose..."
if [ $ENVIRONMENT == "dev" ]; then
load_env .env.dev
$DOCKER_COMPOSE_CMD -f docker-compose.yml -f docker-compose.override.yml --env-file .env.dev up --build -d
else
load_env .env.prod
$DOCKER_COMPOSE_CMD -f docker-compose.yml -f docker-compose.prod.yml --env-file .env.prod up -d
fi
# Keep containers running in foreground
$DOCKER_COMPOSE_CMD logs -f
}
# Run main function
main $1