Skip to content

Commit 7e9c109

Browse files
committed
Update scripting to support docker compose plugin
1 parent b058fd0 commit 7e9c109

5 files changed

+75
-16
lines changed

angel-docker-build.sh

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#
55
set -e
66
SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)"
7+
8+
# source common functionalities
9+
. "${SCRIPT_DIR}/scripts/common.bash"
10+
711
pushd "$SCRIPT_DIR"
812

913
function usage()
@@ -19,11 +23,6 @@ Options:
1923
"
2024
}
2125

22-
function log()
23-
{
24-
>&2 echo "$@"
25-
}
26-
2726
# Option parsing
2827
dc_forward_params=()
2928
while [[ $# -gt 0 ]]
@@ -88,7 +87,9 @@ then
8887
log "Forwarding to docker-compose: ${dc_forward_params[@]}"
8988
fi
9089

91-
docker-compose \
90+
get_docker_compose_cmd DC_CMD
91+
92+
"${DC_CMD[@]}" \
9293
--env-file "$SCRIPT_DIR"/docker/.env \
9394
-f "$SCRIPT_DIR"/docker/docker-compose.yml \
9495
--profile build-only \

angel-docker-pull.sh

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#
55
set -e
66
SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)"
7+
8+
# source common functionalities
9+
. "${SCRIPT_DIR}/scripts/common.bash"
10+
711
pushd "$SCRIPT_DIR"
812

913
function usage()
@@ -36,10 +40,12 @@ done
3640
if [[ "${#dc_forward_params[@]}" -gt 0 ]]
3741
then
3842
# shellcheck disable=SC2145
39-
echo "Forwarding to docker-compose: ${dc_forward_params[@]}"
43+
log "Forwarding to docker-compose: ${dc_forward_params[@]}"
4044
fi
4145

42-
docker-compose \
46+
get_docker_compose_cmd DC_CMD
47+
48+
"${DC_CMD[@]}" \
4349
--env-file "$SCRIPT_DIR"/docker/.env \
4450
-f "$SCRIPT_DIR"/docker/docker-compose.yml \
4551
--profile build-only \

angel-docker-push.sh

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#
55
set -e
66
SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)"
7+
8+
# source common functionalities
9+
. "${SCRIPT_DIR}/scripts/common.bash"
10+
711
pushd "$SCRIPT_DIR"
812

913
function usage()
@@ -36,10 +40,12 @@ done
3640
if [[ "${#dc_forward_params[@]}" -gt 0 ]]
3741
then
3842
# shellcheck disable=SC2145
39-
echo "Forwarding to docker-compose: ${dc_forward_params[@]}"
43+
log "Forwarding to docker-compose: ${dc_forward_params[@]}"
4044
fi
4145

42-
docker-compose \
46+
get_docker_compose_cmd DC_CMD
47+
48+
"${DC_CMD[@]}" \
4349
--env-file "$SCRIPT_DIR"/docker/.env \
4450
-f "$SCRIPT_DIR"/docker/docker-compose.yml \
4551
--profile build-only \

angel-workspace-shell.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
set -e
66
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
77

8+
# source common functionalities
9+
. "${SCRIPT_DIR}/scripts/common.bash"
10+
811
DEFAULT_SERVICE_NAME="workspace-shell-dev-gpu"
912

1013
function usage()
@@ -29,11 +32,6 @@ Options:
2932
"
3033
}
3134

32-
function log()
33-
{
34-
>&2 echo "$@"
35-
}
36-
3735
# Option parsing
3836
passthrough_args=()
3937
while [[ $# -gt 0 ]]
@@ -102,8 +100,10 @@ else
102100
"
103101
fi
104102

103+
get_docker_compose_cmd DC_CMD
104+
105105
set +e
106-
docker-compose \
106+
"${DC_CMD[@]}" \
107107
--env-file "$ENV_FILE" \
108108
-f "$SCRIPT_DIR"/docker/docker-compose.yml \
109109
run --rm \

scripts/common.bash

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Common functions and definitions for use in bash scripts.
2+
3+
4+
# Logging function to output strings to STDERR.
5+
function log()
6+
{
7+
>&2 echo "$@"
8+
}
9+
10+
11+
# Define to a variable of the given name an array composed of the appropriate
12+
# CLI arguments to invoke docker compose for the current system, if able at
13+
# all.
14+
#
15+
# If a docker compose tool cannot be identified, this function returns code 1.
16+
#
17+
# This should generally be called like:
18+
# get_docker_compose_cmd DC_CMD
19+
# Which results in "DC_CMD" being defined as an array in the calling context,
20+
# viewable like:
21+
# echo "${DC_CMD[@]}"
22+
#
23+
function get_docker_compose_cmd()
24+
{
25+
EXPORT_VAR_NAME="$1"
26+
if [[ -z "$EXPORT_VAR_NAME" ]]
27+
then
28+
log "[ERROR] No export variable name provided as the first positional argument."
29+
return 1
30+
fi
31+
# Check for v1 docker-compose tool, otherwise try to make use of v2
32+
# docker-compose plugin
33+
if ( command -v docker-compose >/dev/null 2>&1 )
34+
then
35+
log "[INFO] Using v1 docker-compose python tool"
36+
EVAL_STR="${EXPORT_VAR_NAME}=( docker-compose )"
37+
elif ( docker compose >/dev/null 2>&1 )
38+
then
39+
log "[INFO] Using v2 docker compose plugin"
40+
EVAL_STR="${EXPORT_VAR_NAME}=( docker compose )"
41+
else
42+
log "[ERROR] No docker compose functionality found on the system."
43+
return 1
44+
fi
45+
eval "${EVAL_STR}"
46+
}

0 commit comments

Comments
 (0)