-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinit.sh
More file actions
executable file
·126 lines (113 loc) · 5.24 KB
/
Copy pathinit.sh
File metadata and controls
executable file
·126 lines (113 loc) · 5.24 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
#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
BLUE='\033[0;34m'
NOCOLOR='\033[0m'
VINKJE="${GREEN}✔${NOCOLOR}"
CWD=$(dirname $0)
manageurl=https://manage.dev.openconext.local/manage/api/internal/
set -e
# Bootstrapping engineblock means initialising the database
printf "\n"
# Check that engine and mariadb are already running; containers must be started via ./start-dev-env.sh first
engine_running=$(docker compose ps -q --status running engine mariadb | wc -l)
if [[ "$engine_running" -lt 2 ]]; then
if [[ "${GITHUB_ACTIONS}" == "true" ]]; then
docker compose up -d engine mariadb
echo -e "${ORANGE}Bringing up the EB production container for migrations${NOCOLOR}"
else
echo -e "${RED}ERROR: engine and/or mariadb are not running.${NOCOLOR}"
echo -e "${ORANGE}Please start the environment first by running:${NOCOLOR}"
echo -e " ${GREEN}./start-dev-env.sh${NOCOLOR}"
echo -e "Then re-run this script once the containers are up."
exit 1
fi
fi
echo -e "${ORANGE}Using the currently running engine container for migrations${NOCOLOR}"
docker compose exec engine timeout 300 bash -c 'while [[ "$(curl -k -s -o /dev/null -w ''%{http_code}'' localhost/internal/info)" != "200" ]]; do sleep 5; done' || false
echo
### Uncomment block below after EB 7.0 becomes the prod image
#echo -e "${ORANGE}Initializing EB database$NOCOLOR ${VINKJE}"
#echo
#echo "Ensure database is created"
#cmd='docker compose exec engine /var/www/html/bin/console doctrine:database:create --env=prod --if-not-exists --no-interaction'
#${cmd}
#cmd='docker compose exec engine /var/www/html/bin/console doctrine:database:create --env=ci --if-not-exists --no-interaction'
#${cmd} 2>/dev/null || true
#
#echo "Running database migrations"
#cmd='docker compose exec engine /var/www/html/bin/console doctrine:migrations:migrate --no-interaction'
#${cmd}
### ENDBLOCK
### Remove block below after EB 7.0 becomes the prod image
if [[ "${GITHUB_ACTIONS}" == "true" ]]; then
echo "Checking if the database is already present"
if ! docker compose exec engine /var/www/html/bin/console doctrine:schema:validate -q --skip-mapping --env=prod > /dev/null 2>&1
then
echo "Creating the database schema"
docker compose exec engine /var/www/html/bin/console doctrine:schema:update --force -q
fi
else
echo "Running database migrations"
cmd='docker compose exec engine /var/www/html/bin/console doctrine:database:create --env=prod --if-not-exists --no-interaction'
${cmd}
cmd='docker compose exec engine /var/www/html/bin/console doctrine:database:create --env=ci --if-not-exists --no-interaction'
${cmd} 2>/dev/null || true
cmd='docker compose exec engine /var/www/html/bin/console doctrine:migrations:migrate --no-interaction'
${cmd}
fi
### ENDBLOCK
echo "Clearing the cache"
docker compose exec engine /var/www/html/bin/console cache:clear -n --env=prod
docker compose exec engine chown -R www-data:www-data /var/www/html/var/cache/
echo -ne "Waiting for EB to be healthy..."
until [ "$(docker inspect -f {{.State.Health.Status}} $(docker compose ps -q engine))" == "healthy" ]
do
echo -n "."
sleep 0.5;
done
echo -e " ${VINKJE}"
if [[ "${GITHUB_ACTIONS}" == "true" ]]; then
echo
echo -e "${ORANGE}Bring up the core containers${NOCOLOR} ${VINKJE}"
echo
docker compose --profile oidc up -d --wait
echo
fi
echo -e "${ORANGE}Adding the manage entities${NOCOLOR} ${VINKJE}"
printf "\n"
for i in "$CWD"/*.json; do
entityid=$(grep '"entityid":' "$i" | awk -F'"' '{print $4}')
type=$(grep '"type":' "$i" | awk -F'"' '{print $4}')
url="$manageurl/search/$type"
json_body="{\"entityid\":\"$entityid\",\"REQUESTED_ATTRIBUTES\":[\"entityid\"],\"LOGICAL_OPERATOR_IS_AND\":true}"
set +e
command="docker compose exec managegui curl --fail-with-body -s -u sysadmin:secret -k -X POST -H \"Content-Type: application/json\" -d '$json_body' \"$url\""
a=$(docker compose exec managegui curl --fail-with-body -s -u sysadmin:secret -k -X POST -H "Content-Type: application/json" -d "$json_body" "$url")
if [[ $? -ne 0 ]]; then
echo -e "${RED}Error while adding $entityid to manage${NOCOLOR}"
echo $command
echo $a
exit 1
fi
set -e
filename=$(basename $i)
if [[ $a == "[]" ]]; then
echo "$entityid not found, adding"
docker compose exec managegui curl -s -k -u sysadmin:secret -H 'Content-Type: application/json' -d @/config/scripts/"$filename" -XPOST "$manageurl"/metadata >/dev/null
else
echo "$entityid already present, skipping"
fi
done
printf "\n"
echo -e "${ORANGE}Send a PUSH in Manage, which pushes the entities to EngineBlock and OIDCNG ${VINKJE}"
docker compose exec managegui curl -q -s -k -u sysadmin:secret $manageurl/push >/dev/null
printf "\n"
echo -e "${BLUE}Please add the following line to your /etc/hosts: ${VINKJE}"
printf "\n"
echo "127.0.0.1 engine.dev.openconext.local manage.dev.openconext.local profile.dev.openconext.local engine-api.dev.openconext.local mujina-idp.dev.openconext.local profile.dev.openconext.local connect.dev.openconext.local teams.dev.openconext.local voot.dev.openconext.local invite.dev.openconext.local welcome.dev.openconext.local"
printf "\n"
echo "You can now login. If you want to bring the environment down, use the command below"
echo "./stop-dev-env.sh"
printf "\n"