From d08d849f48c5127591ebae44b930ac11f654c4da Mon Sep 17 00:00:00 2001 From: Ismael Casimpan Jr Date: Mon, 4 Apr 2022 11:10:29 +0800 Subject: [PATCH 1/8] Added yml file to docker-compose to auto-up project per 18. --- init.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.sh b/init.sh index 48c8fbe..9774510 100755 --- a/init.sh +++ b/init.sh @@ -82,7 +82,7 @@ if [[ "$(docker-compose -f ${DOCKTIE_DOCKER_COMPOSE_FULLPATH} ps | tail -n +2 | ## else if [[ "$AUTOSTART_PROJECT" = "1" ]]; then - $DOCKTIE_DOCKER_COMPOSE_BIN up -d + $DOCKTIE_DOCKER_COMPOSE_BIN -f $DOCKTIE_DOCKER_COMPOSE_FULLPATH up -d BOOTSTRAP_DOCKTIE else echo "ERROR: ${PROJECT_NAME} container(s) not running." From cb3461ccfaab567105e226e7ef8aed7a5cb78c4e Mon Sep 17 00:00:00 2001 From: Ismael Casimpan Jr Date: Thu, 7 Apr 2022 21:23:54 +0800 Subject: [PATCH 2/8] Exempted 'docktie_cli getx' from docktie env requirement per #27. --- utils/etc/app_defs.conf | 1 + utils/lib/kernel/core.bash.inc | 11 ++-- utils/lib/kernel/module/cli.bash.inc | 58 ++++++++++--------- utils/lib/kernel/module/lib/cli_getx.bash.inc | 2 - 4 files changed, 39 insertions(+), 33 deletions(-) diff --git a/utils/etc/app_defs.conf b/utils/etc/app_defs.conf index c32aea7..c65a716 100644 --- a/utils/etc/app_defs.conf +++ b/utils/etc/app_defs.conf @@ -5,3 +5,4 @@ #~APP_DRUPGUARD_ROOTCONF=$CONF_DIR/drupguard DOCKTIE_UTILS_CONF=$CONF_DIR/docktie/utils DOCKTIE_KERNEL_MODULE_LIB=$LIB_DIR/kernel/module/lib +DOCKTIE_EXT_REPO='https://github.com/docktie/docktie-ext' ## TODO: Make it dynamic diff --git a/utils/lib/kernel/core.bash.inc b/utils/lib/kernel/core.bash.inc index cf9f3b1..1a65fef 100644 --- a/utils/lib/kernel/core.bash.inc +++ b/utils/lib/kernel/core.bash.inc @@ -1,20 +1,21 @@ core() { autoload_functions "kernel/module/cli" + ## To allow exempting 'docktie_cli getx' per https://github.com/docktie/docktie/issues/27 + script_name=$1 + script_subcmd=$2 + shift + ## Environment checking dependent on init.sh being run ... if [[ "$DOCKTIE_INIT" = "true" ]] && [[ -e $DOCKTIE_ENV ]]; then . $DOCKTIE_ENV DOCKER_COMPOSE_BIN="docker-compose -f $DOCKTIE_DOCKER_COMPOSE_FULLPATH" - else + elif [[ "$script_name" != "docktie_cli" ]] || [[ "$script_subcmd" != "getx" ]]; then echo 'ERROR: DockTie needs to be initialized.' exit 1 fi - ## Environment OK, proceed... - script_name=$1 - shift - ## Every util except "docktie_cli" needs a config... SCRIPT_CONF="$DOCKTIE_UTILS_CONF/${script_name}.conf" if [[ "$script_name" != "docktie_cli" ]]; then diff --git a/utils/lib/kernel/module/cli.bash.inc b/utils/lib/kernel/module/cli.bash.inc index 5323530..1e86262 100644 --- a/utils/lib/kernel/module/cli.bash.inc +++ b/utils/lib/kernel/module/cli.bash.inc @@ -3,68 +3,74 @@ cli() { local sub_cmd=${1:-"help"}; shift ## Get 1st parameter (defaults to 'help'). Then, pop-off from $* sub_cmd=${sub_cmd,,} ## ...ensure parameter is lowercase. - DOCKER_COMPOSE_BIN="docker-compose -f $DOCKTIE_DOCKER_COMPOSE_FULLPATH" - - ## TODO: Check for '_' in service names. If it exist, replace it with something else... + ## 'docktie_cli getx' don't need a container to run ... ## - running_services="$($DOCKER_COMPOSE_BIN ps --services --status running | tr '\n' '_')" - exited_services="$( $DOCKER_COMPOSE_BIN ps --services --status exited | tr '\n' '_')" + if [[ "$sub_cmd" != "getx" ]]; then + DOCKER_COMPOSE_BIN="docker-compose -f $DOCKTIE_DOCKER_COMPOSE_FULLPATH" - ## TODO: Check if this will not give false positive for partial match of container name. - ## e.g. 'mysql' MUST NOT return 1 for 'mysql5' - container_running() { - container=$1 + ## TODO: Check for '_' in service names. If it exist, replace it with something else... + ## + running_services="$($DOCKER_COMPOSE_BIN ps --services --status running | tr '\n' '_')" + exited_services="$( $DOCKER_COMPOSE_BIN ps --services --status exited | tr '\n' '_')" - retval=0 - if [[ $container != "" ]]; then - retval=$(echo $running_services | tr "_" "\n" | grep -c ^${container}$) - fi - - echo $retval - } + ## TODO: Check if this will not give false positive for partial match of container name. + ## e.g. 'mysql' MUST NOT return 1 for 'mysql5' + container_running() { + container=$1 + + retval=0 + if [[ $container != "" ]]; then + retval=$(echo $running_services | tr "_" "\n" | grep -c ^${container}$) + fi - lib2include=" - kernel/module/lib/cli_cp - kernel/module/lib/cli_logs - kernel/module/lib/cli_shell - kernel/module/lib/cli_services - kernel/module/lib/cli_help - kernel/module/lib/cli_list - kernel/module/lib/cli_getx - " - autoload_functions "$lib2include" + echo $retval + } + fi + # 'docktie_cli getx' was allowed to run outside docktie environment. + # Therefore, it is imperative for autoload_functions to be called + # Only when needed as below. Otherwise, errors like 'unknown flag: --services' + # are seen + # + local lib_relpath='kernel/module/lib' case $sub_cmd in help) + autoload_functions "${lib_relpath}/cli_help" cli_help $* ;; list) + autoload_functions "${lib_relpath}/cli_list" cli_list $* ;; ## works! shell|sh) + autoload_functions "${lib_relpath}/cli_shell" cli_shell $* ;; ## Default is show all (broken into running and NOT running) ## Other option 'running' & 'not_running' services) + autoload_functions "${lib_relpath}/cli_services" cli_services $* ;; ## works! cp|copy) + autoload_functions "${lib_relpath}/cli_cp" cli_cp $* ;; ## works! logs|log) + autoload_functions "${lib_relpath}/cli_logs" cli_logs $* ;; getx) + autoload_functions "${lib_relpath}/cli_getx" cli_getx $* ;; diff --git a/utils/lib/kernel/module/lib/cli_getx.bash.inc b/utils/lib/kernel/module/lib/cli_getx.bash.inc index 547c11b..2288582 100644 --- a/utils/lib/kernel/module/lib/cli_getx.bash.inc +++ b/utils/lib/kernel/module/lib/cli_getx.bash.inc @@ -27,11 +27,9 @@ cli_getx() { ## Get non-version string tool_name=$(echo $identifier|cut -d'@' -f1) tool_alias=$(echo $tool_name|cut -d'/' -f2) ## tool's main filename only, no brand (e.g. backup.sh) - ## ver_string default to 'stable' IF nothing mentioned [[ "$ver_string" = "$tool_name" ]] && ver_string='stable' - DOCKTIE_EXT_REPO='https://github.com/docktie/docktie-ext' ## TODO: Make it dynamic tool_branch=$(git ls-remote $DOCKTIE_EXT_REPO|grep ${tool_name}/${ver_string}|awk '{print $NF}'|sed 's|^refs/heads/||') if [[ "$tool_branch" != "" ]]; then From 1028563cd990d85f175004111285ef1d6249e936 Mon Sep 17 00:00:00 2001 From: Ismael Casimpan Jr Date: Thu, 7 Apr 2022 21:30:39 +0800 Subject: [PATCH 3/8] Revert "Exempted 'docktie_cli getx' from docktie env requirement per #27." This reverts commit cb3461ccfaab567105e226e7ef8aed7a5cb78c4e. --- utils/etc/app_defs.conf | 1 - utils/lib/kernel/core.bash.inc | 11 ++-- utils/lib/kernel/module/cli.bash.inc | 58 +++++++++---------- utils/lib/kernel/module/lib/cli_getx.bash.inc | 2 + 4 files changed, 33 insertions(+), 39 deletions(-) diff --git a/utils/etc/app_defs.conf b/utils/etc/app_defs.conf index c65a716..c32aea7 100644 --- a/utils/etc/app_defs.conf +++ b/utils/etc/app_defs.conf @@ -5,4 +5,3 @@ #~APP_DRUPGUARD_ROOTCONF=$CONF_DIR/drupguard DOCKTIE_UTILS_CONF=$CONF_DIR/docktie/utils DOCKTIE_KERNEL_MODULE_LIB=$LIB_DIR/kernel/module/lib -DOCKTIE_EXT_REPO='https://github.com/docktie/docktie-ext' ## TODO: Make it dynamic diff --git a/utils/lib/kernel/core.bash.inc b/utils/lib/kernel/core.bash.inc index 1a65fef..cf9f3b1 100644 --- a/utils/lib/kernel/core.bash.inc +++ b/utils/lib/kernel/core.bash.inc @@ -1,21 +1,20 @@ core() { autoload_functions "kernel/module/cli" - ## To allow exempting 'docktie_cli getx' per https://github.com/docktie/docktie/issues/27 - script_name=$1 - script_subcmd=$2 - shift - ## Environment checking dependent on init.sh being run ... if [[ "$DOCKTIE_INIT" = "true" ]] && [[ -e $DOCKTIE_ENV ]]; then . $DOCKTIE_ENV DOCKER_COMPOSE_BIN="docker-compose -f $DOCKTIE_DOCKER_COMPOSE_FULLPATH" - elif [[ "$script_name" != "docktie_cli" ]] || [[ "$script_subcmd" != "getx" ]]; then + else echo 'ERROR: DockTie needs to be initialized.' exit 1 fi + ## Environment OK, proceed... + script_name=$1 + shift + ## Every util except "docktie_cli" needs a config... SCRIPT_CONF="$DOCKTIE_UTILS_CONF/${script_name}.conf" if [[ "$script_name" != "docktie_cli" ]]; then diff --git a/utils/lib/kernel/module/cli.bash.inc b/utils/lib/kernel/module/cli.bash.inc index 1e86262..5323530 100644 --- a/utils/lib/kernel/module/cli.bash.inc +++ b/utils/lib/kernel/module/cli.bash.inc @@ -3,74 +3,68 @@ cli() { local sub_cmd=${1:-"help"}; shift ## Get 1st parameter (defaults to 'help'). Then, pop-off from $* sub_cmd=${sub_cmd,,} ## ...ensure parameter is lowercase. - ## 'docktie_cli getx' don't need a container to run ... - ## - if [[ "$sub_cmd" != "getx" ]]; then - DOCKER_COMPOSE_BIN="docker-compose -f $DOCKTIE_DOCKER_COMPOSE_FULLPATH" + DOCKER_COMPOSE_BIN="docker-compose -f $DOCKTIE_DOCKER_COMPOSE_FULLPATH" - ## TODO: Check for '_' in service names. If it exist, replace it with something else... - ## - running_services="$($DOCKER_COMPOSE_BIN ps --services --status running | tr '\n' '_')" - exited_services="$( $DOCKER_COMPOSE_BIN ps --services --status exited | tr '\n' '_')" + ## TODO: Check for '_' in service names. If it exist, replace it with something else... + ## + running_services="$($DOCKER_COMPOSE_BIN ps --services --status running | tr '\n' '_')" + exited_services="$( $DOCKER_COMPOSE_BIN ps --services --status exited | tr '\n' '_')" - ## TODO: Check if this will not give false positive for partial match of container name. - ## e.g. 'mysql' MUST NOT return 1 for 'mysql5' - container_running() { - container=$1 + ## TODO: Check if this will not give false positive for partial match of container name. + ## e.g. 'mysql' MUST NOT return 1 for 'mysql5' + container_running() { + container=$1 - retval=0 - if [[ $container != "" ]]; then - retval=$(echo $running_services | tr "_" "\n" | grep -c ^${container}$) - fi + retval=0 + if [[ $container != "" ]]; then + retval=$(echo $running_services | tr "_" "\n" | grep -c ^${container}$) + fi + + echo $retval + } - echo $retval - } - fi + lib2include=" + kernel/module/lib/cli_cp + kernel/module/lib/cli_logs + kernel/module/lib/cli_shell + kernel/module/lib/cli_services + kernel/module/lib/cli_help + kernel/module/lib/cli_list + kernel/module/lib/cli_getx + " + autoload_functions "$lib2include" - # 'docktie_cli getx' was allowed to run outside docktie environment. - # Therefore, it is imperative for autoload_functions to be called - # Only when needed as below. Otherwise, errors like 'unknown flag: --services' - # are seen - # - local lib_relpath='kernel/module/lib' case $sub_cmd in help) - autoload_functions "${lib_relpath}/cli_help" cli_help $* ;; list) - autoload_functions "${lib_relpath}/cli_list" cli_list $* ;; ## works! shell|sh) - autoload_functions "${lib_relpath}/cli_shell" cli_shell $* ;; ## Default is show all (broken into running and NOT running) ## Other option 'running' & 'not_running' services) - autoload_functions "${lib_relpath}/cli_services" cli_services $* ;; ## works! cp|copy) - autoload_functions "${lib_relpath}/cli_cp" cli_cp $* ;; ## works! logs|log) - autoload_functions "${lib_relpath}/cli_logs" cli_logs $* ;; getx) - autoload_functions "${lib_relpath}/cli_getx" cli_getx $* ;; diff --git a/utils/lib/kernel/module/lib/cli_getx.bash.inc b/utils/lib/kernel/module/lib/cli_getx.bash.inc index 2288582..547c11b 100644 --- a/utils/lib/kernel/module/lib/cli_getx.bash.inc +++ b/utils/lib/kernel/module/lib/cli_getx.bash.inc @@ -27,9 +27,11 @@ cli_getx() { ## Get non-version string tool_name=$(echo $identifier|cut -d'@' -f1) tool_alias=$(echo $tool_name|cut -d'/' -f2) ## tool's main filename only, no brand (e.g. backup.sh) + ## ver_string default to 'stable' IF nothing mentioned [[ "$ver_string" = "$tool_name" ]] && ver_string='stable' + DOCKTIE_EXT_REPO='https://github.com/docktie/docktie-ext' ## TODO: Make it dynamic tool_branch=$(git ls-remote $DOCKTIE_EXT_REPO|grep ${tool_name}/${ver_string}|awk '{print $NF}'|sed 's|^refs/heads/||') if [[ "$tool_branch" != "" ]]; then From e6e807d8b8110f71f342ffbba6d076df6095b05c Mon Sep 17 00:00:00 2001 From: Ismael Casimpan Jr Date: Thu, 7 Apr 2022 21:23:54 +0800 Subject: [PATCH 4/8] Exempted 'docktie_cli getx' from docktie env requirement per #27. --- utils/etc/app_defs.conf | 1 + utils/lib/kernel/core.bash.inc | 11 ++-- utils/lib/kernel/module/cli.bash.inc | 58 ++++++++++--------- utils/lib/kernel/module/lib/cli_getx.bash.inc | 2 - 4 files changed, 39 insertions(+), 33 deletions(-) diff --git a/utils/etc/app_defs.conf b/utils/etc/app_defs.conf index c32aea7..c65a716 100644 --- a/utils/etc/app_defs.conf +++ b/utils/etc/app_defs.conf @@ -5,3 +5,4 @@ #~APP_DRUPGUARD_ROOTCONF=$CONF_DIR/drupguard DOCKTIE_UTILS_CONF=$CONF_DIR/docktie/utils DOCKTIE_KERNEL_MODULE_LIB=$LIB_DIR/kernel/module/lib +DOCKTIE_EXT_REPO='https://github.com/docktie/docktie-ext' ## TODO: Make it dynamic diff --git a/utils/lib/kernel/core.bash.inc b/utils/lib/kernel/core.bash.inc index cf9f3b1..1a65fef 100644 --- a/utils/lib/kernel/core.bash.inc +++ b/utils/lib/kernel/core.bash.inc @@ -1,20 +1,21 @@ core() { autoload_functions "kernel/module/cli" + ## To allow exempting 'docktie_cli getx' per https://github.com/docktie/docktie/issues/27 + script_name=$1 + script_subcmd=$2 + shift + ## Environment checking dependent on init.sh being run ... if [[ "$DOCKTIE_INIT" = "true" ]] && [[ -e $DOCKTIE_ENV ]]; then . $DOCKTIE_ENV DOCKER_COMPOSE_BIN="docker-compose -f $DOCKTIE_DOCKER_COMPOSE_FULLPATH" - else + elif [[ "$script_name" != "docktie_cli" ]] || [[ "$script_subcmd" != "getx" ]]; then echo 'ERROR: DockTie needs to be initialized.' exit 1 fi - ## Environment OK, proceed... - script_name=$1 - shift - ## Every util except "docktie_cli" needs a config... SCRIPT_CONF="$DOCKTIE_UTILS_CONF/${script_name}.conf" if [[ "$script_name" != "docktie_cli" ]]; then diff --git a/utils/lib/kernel/module/cli.bash.inc b/utils/lib/kernel/module/cli.bash.inc index 5323530..1e86262 100644 --- a/utils/lib/kernel/module/cli.bash.inc +++ b/utils/lib/kernel/module/cli.bash.inc @@ -3,68 +3,74 @@ cli() { local sub_cmd=${1:-"help"}; shift ## Get 1st parameter (defaults to 'help'). Then, pop-off from $* sub_cmd=${sub_cmd,,} ## ...ensure parameter is lowercase. - DOCKER_COMPOSE_BIN="docker-compose -f $DOCKTIE_DOCKER_COMPOSE_FULLPATH" - - ## TODO: Check for '_' in service names. If it exist, replace it with something else... + ## 'docktie_cli getx' don't need a container to run ... ## - running_services="$($DOCKER_COMPOSE_BIN ps --services --status running | tr '\n' '_')" - exited_services="$( $DOCKER_COMPOSE_BIN ps --services --status exited | tr '\n' '_')" + if [[ "$sub_cmd" != "getx" ]]; then + DOCKER_COMPOSE_BIN="docker-compose -f $DOCKTIE_DOCKER_COMPOSE_FULLPATH" - ## TODO: Check if this will not give false positive for partial match of container name. - ## e.g. 'mysql' MUST NOT return 1 for 'mysql5' - container_running() { - container=$1 + ## TODO: Check for '_' in service names. If it exist, replace it with something else... + ## + running_services="$($DOCKER_COMPOSE_BIN ps --services --status running | tr '\n' '_')" + exited_services="$( $DOCKER_COMPOSE_BIN ps --services --status exited | tr '\n' '_')" - retval=0 - if [[ $container != "" ]]; then - retval=$(echo $running_services | tr "_" "\n" | grep -c ^${container}$) - fi - - echo $retval - } + ## TODO: Check if this will not give false positive for partial match of container name. + ## e.g. 'mysql' MUST NOT return 1 for 'mysql5' + container_running() { + container=$1 + + retval=0 + if [[ $container != "" ]]; then + retval=$(echo $running_services | tr "_" "\n" | grep -c ^${container}$) + fi - lib2include=" - kernel/module/lib/cli_cp - kernel/module/lib/cli_logs - kernel/module/lib/cli_shell - kernel/module/lib/cli_services - kernel/module/lib/cli_help - kernel/module/lib/cli_list - kernel/module/lib/cli_getx - " - autoload_functions "$lib2include" + echo $retval + } + fi + # 'docktie_cli getx' was allowed to run outside docktie environment. + # Therefore, it is imperative for autoload_functions to be called + # Only when needed as below. Otherwise, errors like 'unknown flag: --services' + # are seen + # + local lib_relpath='kernel/module/lib' case $sub_cmd in help) + autoload_functions "${lib_relpath}/cli_help" cli_help $* ;; list) + autoload_functions "${lib_relpath}/cli_list" cli_list $* ;; ## works! shell|sh) + autoload_functions "${lib_relpath}/cli_shell" cli_shell $* ;; ## Default is show all (broken into running and NOT running) ## Other option 'running' & 'not_running' services) + autoload_functions "${lib_relpath}/cli_services" cli_services $* ;; ## works! cp|copy) + autoload_functions "${lib_relpath}/cli_cp" cli_cp $* ;; ## works! logs|log) + autoload_functions "${lib_relpath}/cli_logs" cli_logs $* ;; getx) + autoload_functions "${lib_relpath}/cli_getx" cli_getx $* ;; diff --git a/utils/lib/kernel/module/lib/cli_getx.bash.inc b/utils/lib/kernel/module/lib/cli_getx.bash.inc index 547c11b..2288582 100644 --- a/utils/lib/kernel/module/lib/cli_getx.bash.inc +++ b/utils/lib/kernel/module/lib/cli_getx.bash.inc @@ -27,11 +27,9 @@ cli_getx() { ## Get non-version string tool_name=$(echo $identifier|cut -d'@' -f1) tool_alias=$(echo $tool_name|cut -d'/' -f2) ## tool's main filename only, no brand (e.g. backup.sh) - ## ver_string default to 'stable' IF nothing mentioned [[ "$ver_string" = "$tool_name" ]] && ver_string='stable' - DOCKTIE_EXT_REPO='https://github.com/docktie/docktie-ext' ## TODO: Make it dynamic tool_branch=$(git ls-remote $DOCKTIE_EXT_REPO|grep ${tool_name}/${ver_string}|awk '{print $NF}'|sed 's|^refs/heads/||') if [[ "$tool_branch" != "" ]]; then From 1f93b9d124b7c50ac61bf6afd9dea2f5870e66e5 Mon Sep 17 00:00:00 2001 From: Ismael Casimpan Jr Date: Thu, 7 Apr 2022 22:10:59 +0800 Subject: [PATCH 5/8] Fixed missing DOCKTIE_COMMON_PARENTDIR outside docktie env per #27. --- utils/lib/kernel/module/cli.bash.inc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/utils/lib/kernel/module/cli.bash.inc b/utils/lib/kernel/module/cli.bash.inc index 1e86262..13cba94 100644 --- a/utils/lib/kernel/module/cli.bash.inc +++ b/utils/lib/kernel/module/cli.bash.inc @@ -3,6 +3,13 @@ cli() { local sub_cmd=${1:-"help"}; shift ## Get 1st parameter (defaults to 'help'). Then, pop-off from $* sub_cmd=${sub_cmd,,} ## ...ensure parameter is lowercase. + ## DOCKTIE_COMMON_PARENTDIR is usually initialized when ../docktie/init.sh is run. + ## But since `docktie_cli getx` is allowed to run outside docktie_env, we need to + ## define it here + if [[ "$DOCKTIE_COMMON_PARENTDIR" = "" ]]; then + DOCKTIE_COMMON_PARENTDIR=$(dirname $(dirname $TOOL_ROOTDIR)) + fi + ## 'docktie_cli getx' don't need a container to run ... ## if [[ "$sub_cmd" != "getx" ]]; then From d0c54aa391cdf4bfa9eea1148b775ddc232b69ed Mon Sep 17 00:00:00 2001 From: Ismael Casimpan Jr Date: Fri, 29 Apr 2022 23:22:34 +0800 Subject: [PATCH 6/8] Implemented selected services to docker-compose up per #30 and #13. --- conf/env.sample | 6 +++--- init.sh | 3 ++- utils/bin/docker-compose | 10 +++++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/conf/env.sample b/conf/env.sample index 52872e6..6fc4420 100644 --- a/conf/env.sample +++ b/conf/env.sample @@ -32,7 +32,7 @@ DOCKER_CONTAINER_PREFIX=example ## It is OFF by default. Enable it by making its value 1 AUTOSTART_PROJECT=0 -## SERVICES_TO_START - Useful if you're using laradock or other dev environment with a lot of services +## DOCKTIE_SERVICES_TO_START - Useful if you're using laradock or other dev environment with a lot of services ## and you want to just run a few of them. -#~SERVICES_TO_START="nginx php-fpm mysql" -SERVICES_TO_START="" +#~DOCKTIE_SERVICES_TO_START="nginx php-fpm mysql" +DOCKTIE_SERVICES_TO_START="" diff --git a/init.sh b/init.sh index 6ec5ae5..b631046 100755 --- a/init.sh +++ b/init.sh @@ -82,7 +82,8 @@ if [[ "$(docker-compose -f ${DOCKTIE_DOCKER_COMPOSE_FULLPATH} ps | tail -n +2 | ## else if [[ "$AUTOSTART_PROJECT" = "1" ]]; then - $DOCKTIE_DOCKER_COMPOSE_BIN -f $DOCKTIE_DOCKER_COMPOSE_FULLPATH up -d $SERVICES_TO_START + export DOCKTIE_SERVICES_TO_START="$DOCKTIE_SERVICES_TO_START" ## Needed in docker-compose wrapper + $DOCKTIE_DOCKER_COMPOSE_BIN -f $DOCKTIE_DOCKER_COMPOSE_FULLPATH up -d $DOCKTIE_SERVICES_TO_START BOOTSTRAP_DOCKTIE else echo "ERROR: ${PROJECT_NAME} container(s) not running." diff --git a/utils/bin/docker-compose b/utils/bin/docker-compose index 6c54c63..5a694be 100755 --- a/utils/bin/docker-compose +++ b/utils/bin/docker-compose @@ -1,3 +1,11 @@ #!/bin/bash -$DOCKTIE_DOCKER_COMPOSE_BIN -f $DOCKTIE_DOCKER_COMPOSE_FULLPATH $* +COMMON_DOCKER_COMPOSE="$DOCKTIE_DOCKER_COMPOSE_BIN -f $DOCKTIE_DOCKER_COMPOSE_FULLPATH" + +## Make sure to 'up' only services as specificed in conf/*_env file +if [[ "$1" = 'up' ]]; then + shift + $COMMON_DOCKER_COMPOSE up $* $DOCKTIE_SERVICES_TO_START +else + $COMMON_DOCKER_COMPOSE $* +fi From d56e9349f6aa88e3eb5c98e8d8e639f58a085985 Mon Sep 17 00:00:00 2001 From: Ismael Casimpan Jr Date: Thu, 5 May 2022 09:55:47 +0800 Subject: [PATCH 7/8] Fixed bug on PROJECT_ALIAS with dash or underscore per #31. --- init.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/init.sh b/init.sh index b631046..b761f98 100755 --- a/init.sh +++ b/init.sh @@ -15,7 +15,8 @@ fi ## Read project config ## -PROJECT_ALIAS=${1:-"$(basename $(pwd))"} +## Remove underscore or dash from PROJECT_ALIAS per https://github.com/docktie/docktie/issues/31 +PROJECT_ALIAS=${1:-"$(basename $(pwd)|sed 's/[-_]//g')"} CONF_DIR="$DOCKTIE_DIR/conf" ENV_FILE="$CONF_DIR/${PROJECT_ALIAS}_env" From 0c7004214432943f24071d9ab49fc7b4df626d34 Mon Sep 17 00:00:00 2001 From: Ismael Casimpan Jr Date: Fri, 6 May 2022 13:15:52 +0800 Subject: [PATCH 8/8] Added docktie_cli env per #33 --- conf/env.sample | 7 ++++ init.sh | 11 +++++- utils/lib/kernel/module/cli.bash.inc | 4 +++ utils/lib/kernel/module/lib/cli_env.bash.inc | 35 +++++++++++++++++++ utils/lib/kernel/module/lib/cli_help.bash.inc | 1 + 5 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 utils/lib/kernel/module/lib/cli_env.bash.inc diff --git a/conf/env.sample b/conf/env.sample index 6fc4420..98c4a8f 100644 --- a/conf/env.sample +++ b/conf/env.sample @@ -36,3 +36,10 @@ AUTOSTART_PROJECT=0 ## and you want to just run a few of them. #~DOCKTIE_SERVICES_TO_START="nginx php-fpm mysql" DOCKTIE_SERVICES_TO_START="" + +## PROJECT_* - Define environment variables for this project per https://github.com/docktie/docktie/issues/33 +## NOTE: Does not accept yet a shell variable (e.g. $RELATIVE_DOCKERCOMPOSE_DIR cannot be used yet) +## Shown as part of 'docktie_cli env' +## +#~ PROJECT_BACKEND=website/src/backend +#~ PROJECT_FRONTEND=website/src/frontend diff --git a/init.sh b/init.sh index b761f98..f0969cd 100755 --- a/init.sh +++ b/init.sh @@ -17,6 +17,7 @@ fi ## ## Remove underscore or dash from PROJECT_ALIAS per https://github.com/docktie/docktie/issues/31 PROJECT_ALIAS=${1:-"$(basename $(pwd)|sed 's/[-_]//g')"} +REAL_PROJECT_DIRNAME=${1:-"$(basename $(pwd))"} ## TODO: Refactor as it is duplicating $PROJECT_ALIAS CONF_DIR="$DOCKTIE_DIR/conf" ENV_FILE="$CONF_DIR/${PROJECT_ALIAS}_env" @@ -32,7 +33,7 @@ fi export DOCKTIE_ENV="$ENV_FILE" . $DOCKTIE_ENV -export PROJECT_ROOTDIR="${DOCKTIE_COMMON_PARENTDIR}/${PROJECT_ALIAS}" ## for docktie-ext use +export PROJECT_ROOTDIR="${DOCKTIE_COMMON_PARENTDIR}/${REAL_PROJECT_DIRNAME}" ## for docktie-ext use ## Implement https://github.com/icasimpan/docktie/issues/11 ## Add relative custom location of docker-compose.yml per project @@ -66,6 +67,14 @@ BOOTSTRAP_DOCKTIE() { echo export PATH=$TOOLS_DIR:$PATH export DOCKER_CONTAINER_PREFIX=$DOCKER_CONTAINER_PREFIX ## needed in ps1 change visibility done in next line + + ## Add project-specific environment variables to export + ## Per https://github.com/docktie/docktie/issues/33 + for each_env in $(grep -v "^#\|^$\|^PROJECT_NAME" $DOCKTIE_ENV|grep ^PROJECT_); do + ## TODO: Bug - cannot use shell variable in $each_env + export $(echo $each_env|sed "s|\(.*\)=\(.*\)|\1=$PROJECT_ROOTDIR/\2|g") + done + bash --rcfile <(cat $CONF_DIR/ps1_changer) ## Below will run after 'exit' command echo "DockTie Dev Helper exited." diff --git a/utils/lib/kernel/module/cli.bash.inc b/utils/lib/kernel/module/cli.bash.inc index 13cba94..4f53ce3 100644 --- a/utils/lib/kernel/module/cli.bash.inc +++ b/utils/lib/kernel/module/cli.bash.inc @@ -81,6 +81,10 @@ cli() { cli_getx $* ;; + env) + autoload_functions "${lib_relpath}/cli_env" + cli_env $* + ;; *) echo "Oops, unknown 'docktie_cli' sub-command" ;; diff --git a/utils/lib/kernel/module/lib/cli_env.bash.inc b/utils/lib/kernel/module/lib/cli_env.bash.inc new file mode 100644 index 0000000..09b4ea0 --- /dev/null +++ b/utils/lib/kernel/module/lib/cli_env.bash.inc @@ -0,0 +1,35 @@ +##~ Shows shell environment variables +##~ +##~ Usage: docktie_cli env +##~ where is either +##~ project project specific defined in *_env +##~ docktie platform specific defined in init.sh +##~ all shows both project and docktie (default) +##~ +cli_env() { + local env_type=${1:-'all'} + + env_type=${env_type^^} ## Convert to uppercase. NOTE: Bash 4+ specific + + ## validate input. MUST be as defined in help context above + ## + if [[ "$env_type" =~ ALL|PROJECT|DOCKTIE ]]; then + case $env_type in + ALL) + env|grep "^PROJECT\|^DOCKTIE"|sort + ;; + PROJECT) + env|grep "^PROJECT"|sort + ;; + DOCKTIE) + env|grep "^DOCKTIE"|sort + ;; + *) + echo "Oops, something is wrong." + ;; + esac + else + echo "ERROR: Invalid parameter. See 'docktie_cli help env'" + fi + +} ## END: cli_env() diff --git a/utils/lib/kernel/module/lib/cli_help.bash.inc b/utils/lib/kernel/module/lib/cli_help.bash.inc index fef6a9b..c7a5a7e 100644 --- a/utils/lib/kernel/module/lib/cli_help.bash.inc +++ b/utils/lib/kernel/module/lib/cli_help.bash.inc @@ -7,6 +7,7 @@ ##~ services show project service names ##~ shell shell-in to a one of your project containers ##~ list shows all utilities available +##~ env shows relevant environment variables ##~ cli_help() { autoload_functions "get_cmd_helptext"