Skip to content

Commit

Permalink
Fixed conflicts for #33.
Browse files Browse the repository at this point in the history
  • Loading branch information
icasimpan committed May 6, 2022
2 parents 80adfe6 + 0c70042 commit 1887163
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 1 deletion.
7 changes: 7 additions & 0 deletions conf/env.sample
Expand Up @@ -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
11 changes: 10 additions & 1 deletion init.sh
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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."
Expand Down
4 changes: 4 additions & 0 deletions utils/lib/kernel/module/cli.bash.inc
Expand Up @@ -81,6 +81,10 @@ cli() {
cli_getx $*
;;
env)
autoload_functions "${lib_relpath}/cli_env"
cli_env $*
;;
*)
echo "Oops, unknown 'docktie_cli' sub-command"
;;
Expand Down
35 changes: 35 additions & 0 deletions utils/lib/kernel/module/lib/cli_env.bash.inc
@@ -0,0 +1,35 @@
##~ Shows shell environment variables
##~
##~ Usage: docktie_cli env <env_type>
##~ where <env_type> 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()
1 change: 1 addition & 0 deletions utils/lib/kernel/module/lib/cli_help.bash.inc
Expand Up @@ -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"
Expand Down

0 comments on commit 1887163

Please sign in to comment.