forked from entur/tiamat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevelopment.sh
executable file
·186 lines (140 loc) · 4.39 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
#!/usr/bin/env bash
set -euo pipefail
# allow running from any working directory
WD=$(dirname "$0")
cd "${WD}"
DOCKER_COMPOSE_CMD="docker compose -f ./docker/docker-compose.yml -f ./docker/docker-compose.custom.yml"
# Download Docker Compose bundle from the "jore4-docker-compose-bundle"
# repository. GitHub CLI is required to be installed.
#
# A commit reference can be given as an argument. It can contain, for example,
# only a substring of an actual SHA digest.
download_docker_compose_bundle() {
local commit_ref="${1:-main}"
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 the latest Docker Compose bundle from the
# jore4-docker-compose-bundle repository as a ZIP file and extract its
# contents to a temporary directory.
gh api "repos/${repo_owner}/${repo_name}/zipball/${commit_sha}" > "$zip_file" \
&& unzip -q "$zip_file" -d /tmp
# Clean untracked files from `docker` directory even if they are git-ignored.
git clean -fx ./docker
# 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
}
function start {
$DOCKER_COMPOSE_CMD up --build -d jore4-tiamat jore4-testdb
}
function start_dependencies {
$DOCKER_COMPOSE_CMD up -d jore4-testdb
}
function stop_all {
$DOCKER_COMPOSE_CMD stop
}
function remove_all {
$DOCKER_COMPOSE_CMD down
}
function build {
mvn clean package spring-boot:repackage
}
function run_tests {
mvn test
}
function print_usage {
echo "
Usage $(basename "$0") <command>
build
Build the project locally
start [<commit SHA>]
Start Tiamat service in Docker container.
Optionally, you can pass an SHA digest as an argument (or its initial
substring) to point to a commit (of the jore4-docker-compose-bundle
repository), which specifies the Docker Compose bundle version to fetch. By
default, the tip of the main branch is used.
start:deps [<commit SHA>]
Start the dependencies of jore4-tiamat.
Optionally, you can pass an SHA digest as an argument (or its initial
substring) to point to a commit (of the jore4-docker-compose-bundle
repository), which specifies the Docker Compose bundle version to fetch. By
default, the tip of the main branch is used.
stop
Stop Tiamat Docker container and all dependencies
remove
Stop and remove Tiamat Docker container and all dependencies
test
Run tests locally
help
Show this usage information
"
}
COMMAND=${1:-}
if [[ -z $COMMAND ]]; then
print_usage
exit 1
fi
# Shift other arguments after the command so that we can refer to them later
# with "$@".
shift
case $COMMAND in
start)
download_docker_compose_bundle "$@"
start
;;
start:deps)
download_docker_compose_bundle "$@"
start_dependencies
;;
stop)
stop_all
;;
remove)
remove_all
;;
help)
usage
;;
build)
build
;;
test)
run_tests
;;
*)
echo ""
echo "Unknown command: '${COMMAND}'"
print_usage
exit 1
;;
esac