-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·172 lines (149 loc) · 6.2 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·172 lines (149 loc) · 6.2 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
#!/bin/bash
# verify_checksum() {
# local file=$1
# local expected_checksum=$2
# if command -v sha256sum &> /dev/null; then
# echo "$expected_checksum $file" | sha256sum -c -
# elif command -v shasum &> /dev/null; then
# echo "$expected_checksum $file" | shasum -a 256 -c -
# else
# echo "Error: Neither sha256sum nor shasum found. Cannot verify checksums."
# exit 1
# fi
# }
# 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/verifywise-ai/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.yml" ]; then
# echo "docker-compose.yml not found. Downloading..."
# curl -fSL --output docker-compose.yml https://raw.githubusercontent.com/verifywise-ai/verifywise/develop/docker-compose.yml
# if [ $? -ne 0 ]; then
# echo "Error: Failed to download docker-compose.yml."
# exit 1
# fi
# # Extract checksum for docker-compose.yml
# COMPOSE_CHECKSUM=$(grep "docker-compose.yml" checksums.sha256 | awk '{print $1}')
# echo "Verifying docker-compose.yml..."
# verify_checksum "docker-compose.yml" "$COMPOSE_CHECKSUM" || exit 1
# 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/verifywise-ai/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
# if [ ! -f "docker-compose.prod.yml" ]; then
# echo "docker-compose.prod.yml not found. Downloading..."
# curl -fSL --output docker-compose.prod.yml https://raw.githubusercontent.com/verifywise-ai/verifywise/develop/docker-compose.prod.yml
# if [ $? -ne 0 ]; then
# echo "Error: Failed to download docker-compose.prod.yml."
# exit 1
# fi
# # Extract checksum for docker-compose.prod.yml
# PROD_CHECKSUM=$(grep "docker-compose.prod.yml" checksums.sha256 | awk '{print $1}')
# echo "Verifying docker-compose.prod.yml..."
# verify_checksum "docker-compose.prod.yml" "$PROD_CHECKSUM" || exit 1
# fi
}
# Secrets that must be set (non-empty) before any container starts.
# Keep in sync with the blanked values in .env.dev / .env.prod.
REQUIRED_SECRETS="DB_PASSWORD SUPERADMIN_PASSWORD JWT_SECRET REFRESH_TOKEN_SECRET ENCRYPTION_ALGORITHM ENCRYPTION_PASSWORD AI_GATEWAY_INTERNAL_KEY"
# Function to verify all required secrets are set before starting Docker
check_required_secrets() {
ENV_FILE=$1
if [ ! -f "$ENV_FILE" ]; then
echo "Error: $ENV_FILE file not found"
exit 1
fi
MISSING=""
for KEY in $REQUIRED_SECRETS; do
# Last assignment for KEY, stripped of inline comment, surrounding whitespace and quotes
VALUE=$(grep -E "^[[:space:]]*${KEY}=" "$ENV_FILE" | tail -n1 \
| sed -E "s/^[[:space:]]*${KEY}=//; s/[[:space:]]+#.*$//; s/^[[:space:]]+//; s/[[:space:]]+$//; s/^[\"']//; s/[\"']$//")
if [ -z "$VALUE" ]; then
MISSING="$MISSING $KEY"
fi
done
if [ -n "$MISSING" ]; then
echo "Error: the following required secrets are not set in $ENV_FILE:"
for KEY in $MISSING; do
echo " - $KEY"
done
echo ""
echo "Set them (see the comments in $ENV_FILE for how to generate each value) and re-run."
echo "Aborting: no Docker services were started."
exit 1
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
# Verify required secrets are set BEFORE starting any container
if [ $ENVIRONMENT == "dev" ]; then
check_required_secrets .env.dev
else
check_required_secrets .env.prod
fi
# 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