-
Notifications
You must be signed in to change notification settings - Fork 6
/
setup.sh
executable file
·95 lines (89 loc) · 3.05 KB
/
setup.sh
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
#!/usr/bin/env bash
# Copyright © 2023 Intel Corporation
#
# SPDX-License-Identifier: Apache License 2.0
set -e
set -o pipefail
export COMPOSE_PROJECT_NAME=sigopt-server
sigopt_server_version="git:$(git rev-parse HEAD)"
export sigopt_server_version
echo "Preparing submodules..."
git submodule init
git submodule update
echo "Submodules are ready."
echo "Checking docker..."
if docker ps -q >/dev/null; then
echo "Docker is running."
else
echo "Could not connect to Docker! It might not be running or you might not have permission to access the Docker socket."
exit 1
fi
echo "Building docker images..."
if docker compose --file=docker-compose.yml build --progress=quiet api createdb nginx qworker qworker-analytics web-server; then
echo "Finished building docker images."
else
echo "Failed to build docker images. This is most likely because of a disk space error with your docker allocation. You can try running: docker system prune -a to clear up space."
exit 1
fi
MINIO_ROOT_PASSWORD="$(./tools/secure/generate_random_string.sh)"
export MINIO_ROOT_PASSWORD
echo "Initializing configuration directory..."
if docker compose --file=docker-compose.yml run -i --rm init-config; then
echo "Configuration directory initialized."
else
echo "Failed to initialize the configuration directory"
exit 1
fi
echo "Generating root certificate and key..."
if ./tools/tls/generate_root_ca.sh; then
echo "Root certificate at artifacts/tls/root-ca.crt"
else
echo "Failed to generate root certificate!"
exit 1
fi
CA_PATH="$(pwd)/artifacts/tls/root-ca.crt"
export SIGOPT_API_VERIFY_SSL_CERTS=$CA_PATH
export NODE_EXTRA_CA_CERTS=$CA_PATH
echo "Generating leaf certificate and key..."
if ./tools/tls/generate_san_cert.sh; then
echo "Leaf certificate and key at artifacts/tls/tls.*"
shred -u ./artifacts/tls/root-ca.key
rm -f artifacts/tls/root-ca.srl
else
echo "Failed to generate leaf certificate!"
exit 1
fi
echo "Starting required services..."
docker compose --file=docker-compose.yml stop minio &>/dev/null || true
if docker compose --file=docker-compose.yml up --detach minio postgres redis; then
echo "Required services have started."
else
echo "Failed to start required services!"
exit 1
fi
USER_PASSWORD="$(./tools/secure/generate_random_string.sh 16)"
echo "Initializing database..."
if docker compose --file=docker-compose.yml run --rm createdb --drop-tables --user-password="$USER_PASSWORD"; then
echo "Database ready."
else
echo "Failed to initialize database!"
exit 1
fi
echo "Initializing file storage..."
if docker compose --file=docker-compose.yml run --rm init-minio-filestorage; then
echo "File storage ready."
else
echo "Failed to initialize file storage!"
exit 1
fi
echo "Initializing session storage..."
if docker compose --file=docker-compose.yml run --rm init-minio-cookiejar; then
echo "Session storage ready."
else
echo "Failed to initialize session storage!"
exit 1
fi
echo "Setup complete. You are now ready to start SigOpt Server with ./start.sh"
echo "First time log in credentials:"
echo " email: [email protected]"
echo " password: $USER_PASSWORD"