-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup_devenv.sh
83 lines (68 loc) · 3.35 KB
/
setup_devenv.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
#!/bin/bash
check_result () {
___RESULT=$?
if [ $___RESULT -ne 0 ]; then
echo $1
exit 1
fi
}
if [ -f ".env" ]; then
echo "detected .env loading it"
source .env
check_result "failed to load .env file"
echo "success"
else
echo "no .env found, using default"
fi
function retry {
local n=1
local max=3
local delay=15
while true; do
"$@" && break || {
if [[ $n -lt $max ]]; then
((n++))
echo "Command failed. Attempt $n/$max..."
sleep $delay;
else
echo "WARN: The command has failed after $n attempts. It might be fine if you already have a devenv running on this machine and simply wanted to upgrade."
fi
}
done
}
function _ensure_bucket {
BUCKET_EXISTS=$(docker compose exec -T awscli bash -c "AWS_ACCESS_KEY_ID=skipper-test AWS_SECRET_ACCESS_KEY=WMH37f3R8RZyN2CMycWGV3EwuMpxGKhG8NBKaswD6hfFPUrmhg9b6PjfyD8RW4AV3JuRLDTa8JRvTWRYASs5xbwB9qHyTW7BZ6V59FPTytb7jvZ4VsnmbrY4WRSVCS9C aws --region eu-west-1 --endpoint-url http://nfcomposes3:6044 s3api head-bucket --bucket $1 2>&1")
if [ -z "$BUCKET_EXISTS" ]; then
echo "Bucket $1 already exists"
else
echo "$bucket does not already exist."
docker compose exec -T awscli bash -c "AWS_ACCESS_KEY_ID=skipper-test AWS_SECRET_ACCESS_KEY=WMH37f3R8RZyN2CMycWGV3EwuMpxGKhG8NBKaswD6hfFPUrmhg9b6PjfyD8RW4AV3JuRLDTa8JRvTWRYASs5xbwB9qHyTW7BZ6V59FPTytb7jvZ4VsnmbrY4WRSVCS9C aws --region eu-west-1 --endpoint-url http://nfcomposes3:6044 s3 mb s3://$1"
if [ $? -ne 0 ]; then
echo "failed to create bucket $1"
return 1
fi
fi
}
function ensure_bucket {
retry _ensure_bucket $1
}
export COMPOSE_PROJECT_NAME=$(whoami)_skipper
COMPOSE_PROJECT_NAME=$(whoami)_skipper CONTAINER_USER_ID=$(id -u) CONTAINER_GROUP_ID=$(id -g) docker compose build
check_result "failed to run docker compose build"
COMPOSE_PROJECT_NAME=$(whoami)_skipper CONTAINER_USER_ID=$(id -u) CONTAINER_GROUP_ID=$(id -g) docker compose up -d
check_result "failed to run docker compose up -d"
# installing dependencies for skipper
COMPOSE_PROJECT_NAME=$(whoami)_skipper CONTAINER_USER_ID=$(id -u) CONTAINER_GROUP_ID=$(id -g) docker compose exec -T neuroforge_skipper_base_dev bash -c 'cd /neuroforge/skipper/ && exec bash create_venv.sh'
check_result "failed to setup venv in skipper"
# running migrations and static collection
COMPOSE_PROJECT_NAME=$(whoami)_skipper CONTAINER_USER_ID=$(id -u) CONTAINER_GROUP_ID=$(id -g) docker compose exec -T neuroforge_skipper_base_dev bash -c 'cd /neuroforge/skipper/ && exec python3 -m pipenv run python3 manage.py migrate'
check_result "failed to run migrations in skipper"
ensure_bucket 'skipper-static'
check_result "failed to create skipper-static s3 bucket"
ensure_bucket 'skipper-media'
check_result "failed to create skipper-media s3 bucket"
COMPOSE_PROJECT_NAME=$(whoami)_skipper CONTAINER_USER_ID=$(id -u) CONTAINER_GROUP_ID=$(id -g) docker compose exec -T neuroforge_skipper_base_dev bash -c 'cd /neuroforge/skipper/ && exec python3 -m pipenv run python3 manage.py collectstatic --noinput'
check_result "failed to run collectstatic in skipper"
# setup users
COMPOSE_PROJECT_NAME=$(whoami)_skipper CONTAINER_USER_ID=$(id -u) CONTAINER_GROUP_ID=$(id -g) docker compose exec -T neuroforge_skipper_base_dev bash -c 'cd /neuroforge/skipper/ && exec bash test_setup.sh'
check_result "failed to run test_setup in skipper"