@@ -16,6 +16,7 @@ apps=()
1616gpu_type=none
1717quiet=false
1818headless=false
19+ debug=false
1920
2021function main {
2122 parse_cli SCRIPT_ARGV
@@ -55,6 +56,10 @@ function main {
5556 done
5657 set +o allexport
5758
59+ if [ " $debug " = " true" ]; then
60+ print_debug_info
61+ fi
62+
5863 echo_stderr " Running docker compose..."
5964 if [ " ${# SCRIPT_ARGV} " -gt 0 ]; then
6065 eval " $( get_compose_cmd) ${SCRIPT_ARGV[*]} "
@@ -80,6 +85,9 @@ function usage() {
8085 echo_stderr " -a, --app <app name>"
8186 echo_stderr " Specify an application to launch. Can be used multiple times."
8287 echo_stderr
88+ echo_stderr " -d, --debug"
89+ echo_stderr " Print some extra debugging information before running Docker commands."
90+ echo_stderr
8391 echo_stderr " -e, --env-file <file>"
8492 echo_stderr " Specify an additional file of environment varibles to load before launching 'docker compose'."
8593 echo_stderr
@@ -102,6 +110,12 @@ function usage() {
102110# Parse the command line args we were given
103111function parse_cli {
104112 local -n argv=$1
113+
114+ if [ " ${# argv} " -eq 0 ]; then
115+ usage
116+ exit 1
117+ fi
118+
105119 local idx=0
106120 while [ " $idx " -le " ${# argv[@]} " ]; do
107121 case " ${argv[$idx]} " in
@@ -113,6 +127,9 @@ function parse_cli {
113127 apps+=(" ${argv[$idx+1]} " )
114128 idx=$(( idx + 1 ))
115129 ;;
130+ -d|--debug)
131+ debug=true
132+ ;;
116133 -e|--env-file)
117134 launch_env+=(" ${argv[$idx+1]} " )
118135 idx=$(( idx + 1 ))
@@ -156,6 +173,47 @@ function echo_stderr() {
156173 [ " $quiet " != " true" ] && echo " $txt " >&2
157174}
158175
176+
177+
178+ # Print out some extra debugging info. Currently, this is the list of
179+ # environment variables we're loading, plus the transformed contents of each
180+ # compose file.
181+ function print_debug_info() {
182+ local variable_re=' ^[[:space:]]*([[:alpha:]][[:alnum:]_]*)='
183+
184+ # Print out the environment variables
185+ echo_stderr " Loading environment variables:"
186+ for env_file in " ${launch_env[@]} " ; do
187+ local full_file=" $SCRIPT_DIR /$env_file "
188+ if [ -f " $full_file " ]; then
189+ while IFS= read -r line; do
190+ if [[ $line =~ $variable_re ]]; then
191+ echo_stderr " - ${line} (from $env_file )"
192+ fi
193+ done < " $full_file "
194+ fi
195+ done
196+ echo_stderr
197+
198+ # Print out each transformed file
199+ for file in " ${compose_files[@]} " ; do
200+ if [ -f " $file " ]; then
201+ echo_stderr " Transformed file: $file "
202+ echo_stderr " $( transform_file " $file " ) "
203+ echo_stderr
204+ fi
205+ done
206+
207+ for app in " ${apps[@]} " ; do
208+ app_file=" compose/$app .yml"
209+ if [ -f " $app_file " ]; then
210+ echo_stderr " Transformed file: $app_file "
211+ echo_stderr " $( transform_file " $app_file " ) "
212+ echo_stderr
213+ fi
214+ done
215+ }
216+
159217# read the given text line by line and add the given padding string to the
160218# front of each line.
161219function pad_lines() {
@@ -267,13 +325,18 @@ function get_compose_cmd() {
267325function check_compose_version {
268326 local min_version installed_version
269327 local compose_re=' version v?([[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+)'
270- if [[ " $( docker-compose --version) " =~ $compose_re ]]; then
328+ if [[ " $( docker compose version) " =~ $compose_re ]]; then
329+ if [ " $debug " = " true" ]; then
330+ echo_stderr " Found Docker Compose version ${BASH_REMATCH[1]} "
331+ fi
332+
271333 local IFS=.
272334 # shellcheck disable=2086
273335 printf -v installed_version %08d ${BASH_REMATCH[1]}
274336 printf -v min_version %08d $MIN_COMPOSE_VERSION
275337 test " $installed_version " \> $min_version
276338 else
339+ echo_stderr " Docker Compose was not found. Please install Docker Compose version $MIN_COMPOSE_VERSION or newer."
277340 false
278341 fi
279342}
0 commit comments