Skip to content

Commit

Permalink
Update scripting to support docker compose plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Purg committed Sep 6, 2023
1 parent b058fd0 commit 7e9c109
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 16 deletions.
13 changes: 7 additions & 6 deletions angel-docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#
set -e
SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)"

# source common functionalities
. "${SCRIPT_DIR}/scripts/common.bash"

pushd "$SCRIPT_DIR"

function usage()
Expand All @@ -19,11 +23,6 @@ Options:
"
}

function log()
{
>&2 echo "$@"
}

# Option parsing
dc_forward_params=()
while [[ $# -gt 0 ]]
Expand Down Expand Up @@ -88,7 +87,9 @@ then
log "Forwarding to docker-compose: ${dc_forward_params[@]}"
fi

docker-compose \
get_docker_compose_cmd DC_CMD

"${DC_CMD[@]}" \
--env-file "$SCRIPT_DIR"/docker/.env \
-f "$SCRIPT_DIR"/docker/docker-compose.yml \
--profile build-only \
Expand Down
10 changes: 8 additions & 2 deletions angel-docker-pull.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#
set -e
SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)"

# source common functionalities
. "${SCRIPT_DIR}/scripts/common.bash"

pushd "$SCRIPT_DIR"

function usage()
Expand Down Expand Up @@ -36,10 +40,12 @@ done
if [[ "${#dc_forward_params[@]}" -gt 0 ]]
then
# shellcheck disable=SC2145
echo "Forwarding to docker-compose: ${dc_forward_params[@]}"
log "Forwarding to docker-compose: ${dc_forward_params[@]}"
fi

docker-compose \
get_docker_compose_cmd DC_CMD

"${DC_CMD[@]}" \
--env-file "$SCRIPT_DIR"/docker/.env \
-f "$SCRIPT_DIR"/docker/docker-compose.yml \
--profile build-only \
Expand Down
10 changes: 8 additions & 2 deletions angel-docker-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#
set -e
SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)"

# source common functionalities
. "${SCRIPT_DIR}/scripts/common.bash"

pushd "$SCRIPT_DIR"

function usage()
Expand Down Expand Up @@ -36,10 +40,12 @@ done
if [[ "${#dc_forward_params[@]}" -gt 0 ]]
then
# shellcheck disable=SC2145
echo "Forwarding to docker-compose: ${dc_forward_params[@]}"
log "Forwarding to docker-compose: ${dc_forward_params[@]}"
fi

docker-compose \
get_docker_compose_cmd DC_CMD

"${DC_CMD[@]}" \
--env-file "$SCRIPT_DIR"/docker/.env \
-f "$SCRIPT_DIR"/docker/docker-compose.yml \
--profile build-only \
Expand Down
12 changes: 6 additions & 6 deletions angel-workspace-shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# source common functionalities
. "${SCRIPT_DIR}/scripts/common.bash"

DEFAULT_SERVICE_NAME="workspace-shell-dev-gpu"

function usage()
Expand All @@ -29,11 +32,6 @@ Options:
"
}

function log()
{
>&2 echo "$@"
}

# Option parsing
passthrough_args=()
while [[ $# -gt 0 ]]
Expand Down Expand Up @@ -102,8 +100,10 @@ else
"
fi

get_docker_compose_cmd DC_CMD

set +e
docker-compose \
"${DC_CMD[@]}" \
--env-file "$ENV_FILE" \
-f "$SCRIPT_DIR"/docker/docker-compose.yml \
run --rm \
Expand Down
46 changes: 46 additions & 0 deletions scripts/common.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Common functions and definitions for use in bash scripts.


# Logging function to output strings to STDERR.
function log()
{
>&2 echo "$@"
}


# Define to a variable of the given name an array composed of the appropriate
# CLI arguments to invoke docker compose for the current system, if able at
# all.
#
# If a docker compose tool cannot be identified, this function returns code 1.
#
# This should generally be called like:
# get_docker_compose_cmd DC_CMD
# Which results in "DC_CMD" being defined as an array in the calling context,
# viewable like:
# echo "${DC_CMD[@]}"
#
function get_docker_compose_cmd()
{
EXPORT_VAR_NAME="$1"
if [[ -z "$EXPORT_VAR_NAME" ]]
then
log "[ERROR] No export variable name provided as the first positional argument."
return 1
fi
# Check for v1 docker-compose tool, otherwise try to make use of v2
# docker-compose plugin
if ( command -v docker-compose >/dev/null 2>&1 )
then
log "[INFO] Using v1 docker-compose python tool"
EVAL_STR="${EXPORT_VAR_NAME}=( docker-compose )"
elif ( docker compose >/dev/null 2>&1 )
then
log "[INFO] Using v2 docker compose plugin"
EVAL_STR="${EXPORT_VAR_NAME}=( docker compose )"
else
log "[ERROR] No docker compose functionality found on the system."
return 1
fi
eval "${EVAL_STR}"
}

0 comments on commit 7e9c109

Please sign in to comment.