@@ -8,8 +8,70 @@ cd "${WD}"
88
99DOCKER_COMPOSE_CMD=" docker compose -f ./docker/docker-compose.yml -f ./docker/docker-compose.custom.yml"
1010
11- function download_docker_compose_bundle {
12- curl https://raw.githubusercontent.com/HSLdevcom/jore4-tools/main/docker/download-docker-bundle.sh | bash
11+ # Download Docker Compose bundle from the "jore4-docker-compose-bundle"
12+ # repository. GitHub CLI is required to be installed.
13+ #
14+ # A commit reference can be given as an argument. It can contain, for example,
15+ # only a substring of an actual SHA digest.
16+ download_docker_compose_bundle () {
17+ local commit_ref=" ${1:- main} "
18+
19+ local repo_name=" jore4-docker-compose-bundle"
20+ local repo_owner=" HSLdevcom"
21+
22+ # Check GitHub CLI availability.
23+ if ! command -v gh & > /dev/null; then
24+ echo " Please install the GitHub CLI (gh) on your machine."
25+ exit 1
26+ fi
27+
28+ # Make sure the user is authenticated to GitHub.
29+ gh auth status || gh auth login
30+
31+ echo " Using the commit reference '${commit_ref} ' to fetch a Docker Compose bundle..."
32+
33+ # First, try to find a commit on GitHub that matches the given reference.
34+ # This function exits with an error code if no matching commit is found.
35+ local commit_sha
36+ commit_sha=$(
37+ gh api \
38+ -H " Accept: application/vnd.github+json" \
39+ -H " X-GitHub-Api-Version: 2022-11-28" \
40+ " repos/${repo_owner} /${repo_name} /commits/${commit_ref} " \
41+ --jq ' .sha'
42+ )
43+
44+ echo " Commit with the following SHA digest was found: ${commit_sha} "
45+
46+ local zip_file=" /tmp/${repo_name} .zip"
47+ local unzip_target_dir_prefix=" /tmp/${repo_owner} -${repo_name} "
48+
49+ # Remove old temporary directories if any remain.
50+ rm -fr " $unzip_target_dir_prefix " -*
51+
52+ echo " Downloading the JORE4 Docker Compose bundle..."
53+
54+ # Download the latest Docker Compose bundle from the
55+ # jore4-docker-compose-bundle repository as a ZIP file and extract its
56+ # contents to a temporary directory.
57+ gh api " repos/${repo_owner} /${repo_name} /zipball/${commit_sha} " > " $zip_file " \
58+ && unzip -q " $zip_file " -d /tmp
59+
60+ # Clean untracked files from `docker` directory even if they are git-ignored.
61+ git clean -fx ./docker
62+
63+ # Copy files from the `docker-compose` directory of the ZIP file to your
64+ # local `docker` directory.
65+ mv " $unzip_target_dir_prefix " -* /docker-compose/* ./docker
66+
67+ # Remove the temporary files and directories created above.
68+ rm -fr " $zip_file " " $unzip_target_dir_prefix " -*
69+
70+ echo " Generating a release version file for the downloaded bundle..."
71+
72+ # Create a release version file containing the SHA digest of the referenced
73+ # commit.
74+ echo " $commit_sha " > ./docker/RELEASE_VERSION.txt
1375}
1476
1577function start {
@@ -63,9 +125,13 @@ if [[ -z $COMMAND ]]; then
63125 exit 1
64126fi
65127
128+ # Shift other arguments after the command so that we can refer to them later
129+ # with "$@".
130+ shift
131+
66132case $COMMAND in
67133 start)
68- download_docker_compose_bundle
134+ download_docker_compose_bundle " $@ "
69135 start
70136 ;;
71137
0 commit comments