-
Notifications
You must be signed in to change notification settings - Fork 7
/
localdev.sh
executable file
·125 lines (96 loc) · 3.23 KB
/
localdev.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
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
#!/bin/bash -e
# Takes down any running docker compose in this project, then prunes volumes,
# and starts again with new volumes
manage_docker_volumes() {
docker_prefix="docker compose"
echo "Stopping existing Docker containers..."
${docker_prefix} down
echo "Pruning volumes related to this Docker Compose setup..."
docker volume prune -f --filter "label=com.docker.compose.project=$(${docker_prefix} config --services)"
echo "Starting Docker containers with new volumes..."
${docker_prefix} up -d
}
wait_for_service() {
local start_time
local end_time
local current_time
local response
start_time=$(date +%s)
end_time=$((start_time + 30))
while true; do
current_time=$(date +%s)
if [ $current_time -ge $end_time ]; then
echo "Global timeout reached. Service did not become available within 30 seconds."
return 1
fi
if response=$(curl -s -o /dev/null -w "%{http_code}" --max-time 2 http://localhost:8080/auth); then
if [ "$response" -eq 200 ]; then
echo "Service is now available!"
return 0
fi
fi
echo "Service not yet available. Retrying in 2 seconds..."
sleep 2
done
}
echo "Using docker build kit"
echo "export DOCKER_BUILDKIT=1"
export DOCKER_BUILDKIT=1
echo "checking npm install"
echo "> npm --version"
npm --version
echo "checking docker install"
echo "> docker --version"
docker --version
echo "checking uuidgen install"
echo "> uuidgen"
uuidgen
# install dependencies
echo "Installing monorepo dependencies"
echo "> npm install"
npm install
# create .env files
echo "> cp ./.env.dist ./.env"
cp ./.env.dist ./.env
echo "> cp ./api/.env.dist ./api/.env"
cp ./api/.env.dist ./api/.env
echo "> cp ./app/.env.dist ./app/.env"
cp ./app/.env.dist ./app/.env
# create local keys
echo "Generating local keys"
echo "> npm run generate-local-keys"
npm run generate-local-keys
echo "Building docker files using docker compose"
echo "> ./scripts/devbuild.sh"
./scripts/devbuild.sh
echo "Starting docker service..."
manage_docker_volumes
echo "Waiting for service to become available at http://localhost:8080..."
# Call the function and capture its return status
if wait_for_service; then
echo "Continuing with the rest of the script..."
# Add your additional commands here
else
echo "Failed to connect to the service. Exiting."
exit 1
fi
echo "Initialising database"
echo "> npm run initdb"
npm run initdb
echo "Service is setup, to load notebooks and templates follow the below steps"
cat << EOF
This script requires authentication, so you need to get a user token for the admin
user. First, connect to the conductor instance on http://localhost:8080/ or whichever
port you have configured. Login using the local 'admin' user and password.
Now, from the Conductor home page (http://localhost:8080/) scroll down to "Copy
Bearer Token to Clipboard". Paste this value into your .env file as the
value of USER_TOKEN.
Then run:
$> npm run load-notebooks
And:
$> npm run load-templates
EOF
echo "Services running:"
echo "API (live reloading /api): http://localhost:8080"
echo "App (live reloading /app): http://localhost:3000"
echo "CouchDB: http://localhost:5984/_utils"