forked from UniqueNetwork/unique-chain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.envrc
51 lines (45 loc) · 1.54 KB
/
.envrc
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
#!/bin/sh
# Load .envrc from parent directories
source_up_if_exists
# Load .envrc-dev
source_env_if_exists .envrc-dev
# Common variables from .env
dotenv
RED='\033[0;31m'
GREEN='\033[0;32m'
RESET='\033[0m'
dep_not_found=false
function check_bdk {
if ! has $1; then
echo -e "${RED}$1 not found (wanted for beadeker discovery)${RESET}"
dep_not_found=true
fi
}
if ! diff .githooks/pre-commit .git/hooks/pre-commit >/dev/null; then
echo -e "${RED}Hooks are updated, run make git-hooks${RESET}"
fi
watch_file .baedeker/.bdk-env/discover.env
if test -f .baedeker/.bdk-env/discover.env; then
check_bdk baedeker
check_bdk docker
check_bdk jq
if $dep_not_found; then
echo -e "${RED}Not performing bdk discovery${RESET}"
exit 0
fi
echo -e "${GREEN}Baedeker env updated${RESET}"
nginx_id=$(docker compose -f .baedeker/.bdk-env/docker-compose.yml ps --format=json | jq -s 'flatten' | jq -r '.[] | select(.Service == "nginx") | .ID' -e)
if ! [ $? -eq 0 ]; then
echo -e "${RED}Nginx container not found${RESET}"
exit 0
fi
nginx_ip=$(docker inspect $nginx_id | jq -r -e '.[0].NetworkSettings.Networks[].IPAddress')
if ! [ $? -eq 0 ]; then
echo -e "${RED}Nginx container network misconfigured?${RESET}"
exit 0
fi
tmpenv=$(mktemp)
cat .baedeker/.bdk-env/discover.env | sed "s|BALANCER_URL|$nginx_ip|g" > $tmpenv
dotenv $tmpenv
echo -e "${GREEN}Enjoy your baedeker networks at $(echo $BDK_BALANCER || sed "s|BALANCER_URL|$nginx_ip|g")${RESET}"
fi