-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevelopment.sh
executable file
·230 lines (178 loc) · 6.67 KB
/
development.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")" # Setting the working directory as the script directory
# By default, the tip of the main branch of the jore4-docker-compose-bundle
# repository is used as the commit reference, which determines the version of
# the Docker Compose bundle to download. For debugging purposes, this default
# can be overridden by some other commit reference (e.g., commit SHA or its
# initial substring), which you can pass via the `BUNDLE_REF` environment
# variable.
DOCKER_COMPOSE_BUNDLE_REF=${BUNDLE_REF:-main}
# Define a Docker Compose project name to distinguish
# the docker environment of this project from others
export COMPOSE_PROJECT_NAME=jore3-importer
DOCKER_COMPOSE_CMD="docker compose -f ./docker/docker-compose.yml -f ./docker/docker-compose.testdb-volume.yml -f ./docker/docker-compose.custom.yml"
# if the --no-volume parameter is set, the testdb volume will not be mounted
for i in "$@" ; do
if [[ $i == "--no-volume" ]] ; then
DOCKER_COMPOSE_CMD="docker compose -f ./docker/docker-compose.yml -f ./docker/docker-compose.custom.yml"
break
fi
done
print_usage() {
echo "
Usage: $(basename "$0") <command>
Available commands:
start
Start the dependencies and the dockerized application.
You can control which version of the Docker Compose bundle is downloaded by
passing a commit reference to the jore4-docker-compose-bundle repository via
the BUNDLE_REF environment variable. By default, the latest version is
downloaded.
start:deps
Start the dependencies only.
You can control which version of the Docker Compose bundle is downloaded by
passing a commit reference to the jore4-docker-compose-bundle repository via
the BUNDLE_REF environment variable. By default, the latest version is
downloaded.
generate:jooq
Generate JOOQ classes.
stop
Stop the dependencies and the dockerized application.
remove
Stop and remove the dependencies and the dockerized application.
recreate
Stop, remove and recreate the dependencies, removing all data.
list
List running dependencies.
"
}
# Download Docker Compose bundle from the "jore4-docker-compose-bundle"
# repository. GitHub CLI is required to be installed.
#
# A commit reference is read from global `DOCKER_COMPOSE_BUNDLE_REF` variable,
# which should be set based on the script execution arguments.
download_docker_compose_bundle() {
local commit_ref="$DOCKER_COMPOSE_BUNDLE_REF"
local repo_name="jore4-docker-compose-bundle"
local repo_owner="HSLdevcom"
# Check GitHub CLI availability.
if ! command -v gh &> /dev/null; then
echo "Please install the GitHub CLI (gh) on your machine."
exit 1
fi
# Make sure the user is authenticated to GitHub.
gh auth status || gh auth login
echo "Using the commit reference '${commit_ref}' to fetch a Docker Compose bundle..."
# First, try to find a commit on GitHub that matches the given reference.
# This function exits with an error code if no matching commit is found.
local commit_sha
commit_sha=$(
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"repos/${repo_owner}/${repo_name}/commits/${commit_ref}" \
--jq '.sha'
)
echo "Commit with the following SHA digest was found: ${commit_sha}"
local zip_file="/tmp/${repo_name}.zip"
local unzip_target_dir_prefix="/tmp/${repo_owner}-${repo_name}"
# Remove old temporary directories if any remain.
rm -fr "$unzip_target_dir_prefix"-*
echo "Downloading the JORE4 Docker Compose bundle..."
# Download Docker Compose bundle from the jore4-docker-compose-bundle
# repository as a ZIP file.
gh api "repos/${repo_owner}/${repo_name}/zipball/${commit_sha}" > "$zip_file"
# Extract ZIP file contents to a temporary directory.
unzip -q "$zip_file" -d /tmp
# Clean untracked files from the `docker` directory even if they are
# git-ignored. Exclude the `testdb` directory, which we want to keep.
git clean -fx -e testdb ./docker
echo "Copying JORE4 Docker Compose bundle files to ./docker directory..."
# Copy files from the `docker-compose` directory of the ZIP file to your
# local `docker` directory.
mv "$unzip_target_dir_prefix"-*/docker-compose/* ./docker
# Remove the temporary files and directories created above.
rm -fr "$zip_file" "$unzip_target_dir_prefix"-*
echo "Generating a release version file for the downloaded bundle..."
# Create a release version file containing the SHA digest of the referenced
# commit.
echo "$commit_sha" > ./docker/RELEASE_VERSION.txt
}
start_all() {
$DOCKER_COMPOSE_CMD up --build -d importer-jooq-database importer-test-database jore4-mssqltestdb jore4-hasura jore4-testdb jore4-jore3importer jore4-mapmatchingdb jore4-mapmatching
}
start_deps() {
# Runs the following services:
# importer-jooq-database - The database which contains the information imported and transformed from Jore 3
# importer-test-destination-database - The test database which contains the information imported and transformed from Jore 3
# jore4-mssqltestdb - The Jore 3 MSSQL database which contains the source data which is read by the importer
# jore4-hasura - Hasura. We have to start Hasura because it ensures that db migrations are run to the Jore 4 database.
# jore4-testdb - Jore 4 database. This is the destination database of the import process.
$DOCKER_COMPOSE_CMD up --build -d importer-jooq-database importer-test-database jore4-mssqltestdb jore4-hasura jore4-testdb jore4-mapmatchingdb jore4-mapmatching
}
stop() {
docker compose --project-name "$COMPOSE_PROJECT_NAME" stop
}
remove() {
docker compose --project-name "$COMPOSE_PROJECT_NAME" down
}
wait_for_test_databases_to_be_ready() {
while ! pg_isready -h localhost -p 17000
do
echo "waiting for importer db to spin up"
sleep 2;
done
while ! pg_isready -h localhost -p 6432
do
echo "waiting for Jore 4 db to spin up"
sleep 2;
done
while ! curl --fail http://localhost:3201/healthz --output /dev/null --silent
do
echo "waiting for hasura db migrations to execute"
sleep 2;
done
}
generate_jooq() {
mvn clean generate-sources -Pci
}
### Control flow
COMMAND=${1:-}
if [[ -z $COMMAND ]]; then
print_usage
exit 1
fi
case $COMMAND in
start)
download_docker_compose_bundle
start_all
;;
start:deps)
download_docker_compose_bundle
start_deps
;;
generate:jooq)
wait_for_test_databases_to_be_ready
generate_jooq
;;
stop)
stop
;;
remove)
remove
;;
recreate)
remove
start_deps
;;
list)
$DOCKER_COMPOSE_CMD config --services
;;
*)
echo ""
echo "Unknown command: '${COMMAND}'"
print_usage
exit 1
;;
esac