diff --git a/CHANGELOG.md b/CHANGELOG.md index 60427f4..d7d38c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +#Version 3.1.0 +## Enhancements +- Clean up of code, moved more stuff into functions +- `dc_completion` also needs to adhere to the new env files + +## Bug fixes +- Forgot a call to create_env_file function + # Version 3.0.2 ## Bug fix - Forgot to remove `dev` from version diff --git a/build-files/CHANGELOG.md b/build-files/CHANGELOG.md index d31e526..0bb7095 100644 --- a/build-files/CHANGELOG.md +++ b/build-files/CHANGELOG.md @@ -1,3 +1,7 @@ -# Version 3.0.2 -## Bug fix -- Forgot to remove `dev` from version +#Version 3.1.0 +## Enhancements +- Clean up of code, moved more stuff into functions +- `dc_completion` also needs to adhere to the new env files + +## Bug fixes +- Forgot a call to create_env_file function diff --git a/dc b/dc index eba6231..f03252a 100755 --- a/dc +++ b/dc @@ -6,7 +6,7 @@ set -m # VERSION -export DC_VERSION=v3.0.2 +export DC_VERSION=v3.1.0 ###### VARIABLES if [[ -z "${DC_DIR}" ]]; then @@ -21,8 +21,10 @@ export DC_CMD="docker compose" export DC_CMD_INIT="${DC_CMD} --env-file ${ENV}" export TMP_DIR="/tmp/dc_stack_services" # COLORS -export RED='\033[0;31m' export BLUE='\033[0;34m' +export GREEN='\033[0;32m' +export RED='\033[0;31m' +export YELLOW='\033[0;33m' export NC='\033[0m' # No Color # Verbosity if [[ ${DC_VERSION} =~ "dev" ]]; then @@ -35,12 +37,54 @@ fi ################################################## # HELPER FUNCTIONS # ################################################## +########################### +# VERBOSITY # +########################### +# Verbosity for stack_names +function verbose_stack(){ + STACK=$1 + STACK_NAME=$2 + SERVICE_NAME=$3 + if [ "${VERBOSE}" = true ]; then + printf "STACK is %b%s%b \n" "${YELLOW}" "${STACK}" "${NC}" + printf "STACK_NAME is %b%s%b \n" "${YELLOW}" "${STACK_NAME}" "${NC}" + if [ -n "${SERVICE_NAME}" ]; then + printf "SERVICE_NAME is %b%s%b \n" "${YELLOW}" "${SERVICE_NAME}" "${NC}" + printf "Found %b%s%b in %b%s%b \n" "${YELLOW}" "${SERVICE}" "${NC}" "${YELLOW}" "${STACK}" "${NC}" + fi + fi +} + +function verbose_message(){ + MSG=$1 + if [ "${VERBOSE}" = true ]; then + printf "%b%s%b \n" "${GREEN}" "${MSG}" "${NC}" + fi +} + +########################### +# DC COMMAND CREATION # +########################### +function dc_cmd_create(){ + unset DC_CMD_PARAM + DC_CMD_PARAM=$1 + DC_COMMAND="${DC_CMD_INIT} --env-file ${STACK}/${STACK_NAME}.env" + DC_CMD_CMB="${DC_COMMAND} ${DC_CMD_PARAM}" + if [ "${VERBOSE}" = true ]; then + printf "DC_COMMAND is %b%s%b \n" "${RED}" "${DC_COMMAND}" "${NC}" + printf "DC_CMD_PARAM is %b%s%b \n" "${RED}" "${DC_CMD_PARAM}" "${NC}" + printf "Combined command is %b%s%b \n" "${RED}" "${DC_CMD_CMB}" "${NC}" + fi + ${DC_CMD_CMB} +} + +########################### +# TMP FILES # +########################### # TMP_DIR STACK SERVICES function tmp_dir_stack_files(){ if [ ! -d "${TMP_DIR}" ]; then - if [ "${VERBOSE}" = true ]; then - printf "%s not found. Creating... \n" "${TMP_DIR}" - fi + verbose_message "${TMP_DIR} not found. Creating..." mkdir -p ${TMP_DIR} fi } @@ -51,35 +95,20 @@ function tmp_stack_files_age(){ for STACK in $(find "${DC_DIR}" -name docker-compose.yml -printf '%h \n' | sort -u); do STACK_NAME=$(basename "${STACK}") - if [ "${VERBOSE}" = true ]; then - printf "STACK is %s \n" "${STACK}" - printf "STACK_NAME is %s \n" "${STACK_NAME}" - fi - DC_COMMAND="${DC_CMD_INIT} --env-file ${STACK}/${STACK_NAME}.env" + verbose_stack "${STACK}" "${STACK_NAME}" + DC_CMD_PARAM_TMP="config --services > ${TMP_DIR}/${STACK_NAME}" if [ -f "${TMP_DIR}"/"${STACK_NAME}" ]; then - if [ "${VERBOSE}" = true ]; then - printf "File %s/%s exists, checking age \n" "${TMP_DIR}" "${STACK_NAME}" - fi + verbose_message "File ${TMP_DIR}/${STACK_NAME} exists, checking age" if [ "$(find ${TMP_DIR}/"${STACK_NAME}" -mmin +30)" ]; then - if [ "${VERBOSE}" = true ]; then - printf "File is too old, refreshing \n" - fi + verbose_message "File is too old, refreshing" cd "${STACK}" || { echo "cd failed"; exit 1; } - if [ "${VERBOSE}" = true ]; then - printf "DC_COMMAND is %s \n" "${DC_COMMAND}" - fi - ${DC_COMMAND} config --services > "${TMP_DIR}"/"${STACK_NAME}" + dc_cmd_create "${DC_CMD_PARAM_TMP}" > /dev/null cd - > /dev/null || { echo "cd failed"; exit 1; } fi else - if [ "${VERBOSE}" = true ]; then - printf "File does not exist, creating \n" - fi + verbose_message "File does not exist, creating" cd "${STACK}" || { echo "cd failed"; exit 1; } - if [ "${VERBOSE}" = true ]; then - printf "DC_COMMAND is %s \n" "${DC_COMMAND}" - fi - ${DC_COMMAND} config --services > "${TMP_DIR}"/"${STACK_NAME}" + dc_cmd_create "${DC_CMD_PARAM}" > /dev/null cd - > /dev/null || { echo "cd failed"; exit 1; } fi done @@ -89,10 +118,7 @@ function tmp_stack_files_age(){ function create_env_file() { STACK=$1 STACK_NAME=$2 - if [ "${VERBOSE}" = true ]; then - printf "STACK is %s \n" "${STACK}" - printf "STACK_NAME is %s \n" "${STACK_NAME}" - fi + verbose_stack "${STACK}" "${STACK_NAME}" if [ ! -f "${STACK}/${STACK_NAME}.env" ]; then printf "%s.env does not exist \n" "${STACK_NAME}" if [ "${ALLOW_ENV_CREATE}" = true ]; then @@ -164,17 +190,12 @@ function list(){ for STACK in $(find "${DC_DIR}" -name docker-compose.yml -printf '%h\n' | sort -u); do STACK_NAME=$(basename "${STACK}") - if [ "${VERBOSE}" = true ]; then - printf "STACK is %s \n" "${STACK}" - printf "STACK_NAME is %s \n" "${STACK_NAME}" - fi - DC_COMMAND="${DC_CMD_INIT} --env-file ${STACK}/${STACK_NAME}.env" - printf "Stack %b%s%b contains services: \n" "${RED}" "${STACK_NAME}" "${NC}" + DC_CMD_PARAM="config --services | tee ${TMP_DIR}/${STACK_NAME}" + verbose_stack "${STACK}" "${STACK_NAME}" + create_env_file "${STACK}" "${STACK_NAME}" cd "${STACK}" || { echo "cd failed"; exit 1; } - if [ "${VERBOSE}" = true ]; then - printf "DC_COMMAND is %s \n" "${DC_COMMAND}" - fi - ${DC_COMMAND} config --services | tee ${TMP_DIR}/"${STACK_NAME}" + printf "Stack %b%s%b contains services: \n" "${RED}" "${STACK_NAME}" "${NC}" + dc_cmd_create "${DC_CMD_PARAM}" cd - > /dev/null || { echo "cd failed"; exit 1; } printf "=================================== \n" done @@ -316,6 +337,7 @@ function update(){ ################################################## # UP function up(){ + DC_CMD_PARAM="up -d" if [ -z "$1" ]; then printf "No argument provided, please use the name of a stack or all \n" elif [ "$1" == "all" ]; then @@ -323,15 +345,11 @@ function up(){ for STACK in $(find "${DC_DIR}" -name docker-compose.yml -printf '%h\n' | sort -u); do STACK_NAME=$(basename "${STACK}") + verbose_stack "${STACK}" "${STACK_NAME}" printf "\n%s:\n" "${STACK_NAME}" cd "${STACK}" || { echo "cd failed"; exit 1; } create_env_file "${STACK}" "${STACK_NAME}" - DC_COMMAND="${DC_CMD_INIT} --env-file ${STACK}/${STACK_NAME}.env" - if [ "${VERBOSE}" = true ]; then - printf "DC_COMMAND is %s \n" "${DC_COMMAND}" - printf "Full command is %s up -d \n" "${DC_COMMAND}" - fi - ${DC_COMMAND} up -d + dc_cmd_create "${DC_CMD_PARAM}" cd - > /dev/null || { echo "cd failed"; exit 1; } done else @@ -339,15 +357,11 @@ function up(){ do STACK="${DC_DIR}/${STACK_NAME}" if [ -d "${STACK}" ]; then + verbose_stack "${STACK}" "${STACK_NAME}" printf "Bringing up stack %s \n" "${STACK_NAME}" cd "${STACK}" || { echo "cd failed"; exit 1; } create_env_file "${STACK}" "${STACK_NAME}" - DC_COMMAND="${DC_CMD_INIT} --env-file ${STACK}/${STACK_NAME}.env" - if [ "${VERBOSE}" = true ]; then - printf "DC_COMMAND is %s \n" "${DC_COMMAND}" - printf "Full command is %s up -d \n" "${DC_COMMAND}" - fi - ${DC_COMMAND} up -d + dc_cmd_create "${DC_CMD_PARAM}" cd - > /dev/null || { echo "cd failed"; exit 1; } else printf "Stack %s does not exist. Did you type the name correctly? \n" "${STACK_NAME}" @@ -358,6 +372,7 @@ function up(){ # DOWN function down(){ + DC_CMD_PARAM="down" if [ -z "$1" ]; then printf "No argument provided, please use the name of a stack or all \n" elif [ "$1" == "all" ]; then @@ -365,15 +380,11 @@ function down(){ for STACK in $(find "${DC_DIR}" -name docker-compose.yml -printf '%h\n' | sort -ur); do STACK_NAME=$(basename "${STACK}") + verbose_stack "${STACK}" "${STACK_NAME}" printf "\n%s:\n" "${STACK_NAME}" cd "${STACK}" || { echo "cd failed"; exit 1; } create_env_file "${STACK}" "${STACK_NAME}" - DC_COMMAND="${DC_CMD_INIT} --env-file ${STACK}/${STACK_NAME}.env" - if [ "${VERBOSE}" = true ]; then - printf "DC_COMMAND is %s \n" "${DC_COMMAND}" - printf "Full command is %s down \n" "${DC_COMMAND}" - fi - ${DC_COMMAND} down + dc_cmd_create "${DC_CMD_PARAM}" cd - > /dev/null || { echo "cd failed"; exit 1; } done else @@ -384,12 +395,7 @@ function down(){ printf "Bringing down stack %s \n" "${STACK_NAME}" cd "${STACK}" || { echo "cd failed"; exit 1; } create_env_file "${STACK}" "${STACK_NAME}" - DC_COMMAND="${DC_CMD_INIT} --env-file ${STACK}/${STACK_NAME}.env" - if [ "${VERBOSE}" = true ]; then - printf "DC_COMMAND is %s \n" "${DC_COMMAND}" - printf "Full command is %s down \n" "${DC_COMMAND}" - fi - ${DC_COMMAND} down + dc_cmd_create "${DC_CMD_PARAM}" cd - > /dev/null || { echo "cd failed"; exit 1; } else printf "Stack %s does not exist. Did you type the name correctly? \n" "${STACK_NAME}" @@ -398,10 +404,12 @@ function down(){ fi } -# RESTART-STACK +### RESTART-STACK ## HARD # RESTART-STACK function restart-stack-hard(){ + DC_CMD_PARAM_DOWN="down" + DC_CMD_PARAM_UP="up -d" if [ -z "$1" ]; then printf "No argument provided, please use the name of a stack or all \n" elif [ "$1" == "all" ]; then @@ -409,20 +417,12 @@ function restart-stack-hard(){ for STACK in $(find "${DC_DIR}" -name docker-compose.yml -printf '%h\n' | sort -u); do STACK_NAME=$(basename "${STACK}") - if [ "${VERBOSE}" = true ]; then - printf "STACK is %s \n" "${STACK}" - printf "STACK_NAME is %s \n" "${STACK_NAME}" - fi + verbose_stack "${STACK}" "${STACK_NAME}" create_env_file "${STACK}" "${STACK_NAME}" - DC_COMMAND="${DC_CMD_INIT} --env-file ${STACK}/${STACK_NAME}.env" - if [ "${VERBOSE}" = true ]; then - printf "DC_COMMAND is %s \n" "${DC_COMMAND}" - printf "Full command is %s down; %s up -d \n" "${DC_COMMAND}" "${DC_COMMAND}" - fi printf "\n%s:\n" "${STACK_NAME}" cd "${STACK}" || { echo "cd failed"; exit 1; } - ${DC_COMMAND} down - ${DC_COMMAND} up -d + dc_cmd_create "${DC_CMD_PARAM_DOWN}" + dc_cmd_create "${DC_CMD_PARAM_UP}" cd - > /dev/null || { echo "cd failed"; exit 1; } done else @@ -430,21 +430,13 @@ function restart-stack-hard(){ do STACK="${DC_DIR}/${STACK_NAME}" STACK_NAME=$(basename "${STACK}") - if [ "${VERBOSE}" = true ]; then - printf "STACK is %s \n" "${STACK}" - printf "STACK_NAME is %s \n" "${STACK_NAME}" - fi + verbose_stack "${STACK}" "${STACK_NAME}" if [ -d "${STACK}" ]; then create_env_file "${STACK}" "${STACK_NAME}" - DC_COMMAND="${DC_CMD_INIT} --env-file ${STACK}/${STACK_NAME}.env" - if [ "${VERBOSE}" = true ]; then - printf "DC_COMMAND is %s \n" "${DC_COMMAND}" - printf "Full command is %s down; %s up -d \n" "${DC_COMMAND}" "${DC_COMMAND}" - fi printf "Restarting stack %s \n" "${STACK_NAME}" cd "${STACK}" || { echo "cd failed"; exit 1; } - ${DC_COMMAND} down - ${DC_COMMAND} up -d + dc_cmd_create "${DC_CMD_PARAM_DOWN}" + dc_cmd_create "${DC_CMD_PARAM_UP}" cd - > /dev/null || { echo "cd failed"; exit 1; } else printf "Stack %s does not exist. Did you type the name correctly? \n" "${STACK_NAME}" @@ -455,6 +447,7 @@ function restart-stack-hard(){ ## SOFT function restart-stack-soft(){ + DC_CMD_PARAM="restart" if [ -z "$1" ]; then printf "No argument provided, please use the name of a stack or all \n" elif [ "$1" == "all" ]; then @@ -462,19 +455,11 @@ function restart-stack-soft(){ for STACK in $(find "${DC_DIR}" -name docker-compose.yml -printf '%h\n' | sort -u); do STACK_NAME=$(basename "${STACK}") - if [ "${VERBOSE}" = true ]; then - printf "STACK is %s \n" "${STACK}" - printf "STACK_NAME is %s \n" "${STACK_NAME}" - fi + verbose_stack "${STACK}" "${STACK_NAME}" create_env_file "${STACK}" "${STACK_NAME}" - DC_COMMAND="${DC_CMD_INIT} --env-file ${STACK}/${STACK_NAME}.env" - if [ "${VERBOSE}" = true ]; then - printf "DC_COMMAND is %s \n" "${DC_COMMAND}" - printf "Full command is %s restart \n" "${DC_COMMAND}" - fi printf "\n%s:\n" "${STACK_NAME}" cd "${STACK}" || { echo "cd failed"; exit 1; } - ${DC_COMMAND} restart + dc_cmd_create "${DC_CMD_PARAM}" cd - > /dev/null || { echo "cd failed"; exit 1; } done else @@ -482,20 +467,12 @@ function restart-stack-soft(){ do STACK="${DC_DIR}/${STACK_NAME}" STACK_NAME=$(basename "${STACK}") - if [ "${VERBOSE}" = true ]; then - printf "STACK is %s \n" "${STACK}" - printf "STACK_NAME is %s \n" "${STACK_NAME}" - fi + verbose_stack "${STACK}" "${STACK_NAME}" if [ -d "${STACK}" ]; then create_env_file "${STACK}" "${STACK_NAME}" - DC_COMMAND="${DC_CMD_INIT} --env-file ${STACK}/${STACK_NAME}.env" - if [ "${VERBOSE}" = true ]; then - printf "DC_COMMAND is %s \n" "${DC_COMMAND}" - printf "Full command is %s restart \n" "${DC_COMMAND}" - fi printf "Restarting stack %s \n" "${STACK_NAME}" cd "${STACK}" || { echo "cd failed"; exit 1; } - ${DC_COMMAND} restart + dc_cmd_create "${DC_CMD_PARAM}" cd - > /dev/null || { echo "cd failed"; exit 1; } else printf "Stack %s does not exist. Did you type the name correctly? \n" "${STACK_NAME}" @@ -506,6 +483,7 @@ function restart-stack-soft(){ # LOGS-STACK function logs-stack(){ + DC_CMD_PARAM="logs --tail=100 -f" if [ -z "$1" ]; then printf "No argument provided, please provide the name(s) of a stack(s) \n" else @@ -513,20 +491,12 @@ function logs-stack(){ do STACK="${DC_DIR}/${STACK_NAME}" STACK_NAME=$(basename "${STACK}") - if [ "${VERBOSE}" = true ]; then - printf "STACK is %s \n" "${STACK}" - printf "STACK_NAME is %s \n" "${STACK_NAME}" - fi + verbose_stack "${STACK}" "${STACK_NAME}" if [ -d "${STACK}" ]; then + create_env_file "${STACK}" "${STACK_NAME}" printf "Showing logs for stack %s \n" "${STACK_NAME}" cd "${STACK}" || { echo "cd failed"; exit 1; } - create_env_file "${STACK}" "${STACK_NAME}" - DC_COMMAND="${DC_CMD_INIT} --env-file ${STACK}/${STACK_NAME}.env" - if [ "${VERBOSE}" = true ]; then - printf "DC_COMMAND is %s \n" "${DC_COMMAND}" - printf "Full command is %s logs --tail=100 -f \n" "${DC_COMMAND}" - fi - ${DC_COMMAND} logs --tail=100 -f + dc_cmd_create "${DC_CMD_PARAM}" cd - > /dev/null || { echo "cd failed"; exit 1; } else printf "Stack %s does not exist. Did you type the name correctly? \n" "${STACK}" @@ -550,22 +520,14 @@ function start(){ tmp_stack_files_age for SERVICE in "$@"; do + DC_CMD_PARAM="up -d ${SERVICE}" if grep -r -q -x "${SERVICE}" "${TMP_DIR}"; then STACK_NAME=$(basename "$(grep -r -x "${SERVICE}" "${TMP_DIR}" | cut -d : -f 1 )") STACK="${DC_DIR}/${STACK_NAME}" - if [ "${VERBOSE}" = true ]; then - printf "STACK is %s \n" "${STACK}" - printf "STACK_NAME is %s \n" "${STACK_NAME}" - printf "Found %s in %s \n" "${SERVICE}" "${STACK}" - fi + verbose_stack "${STACK}" "${STACK_NAME}" "${SERVICE}" cd "${STACK}" || { echo "cd failed"; exit 1; } create_env_file "${STACK}" "${STACK_NAME}" - DC_COMMAND="${DC_CMD_INIT} --env-file ${STACK}/${STACK_NAME}.env" - if [ "${VERBOSE}" = true ]; then - printf "DC_COMMAND is %s \n" "${DC_COMMAND}" - printf "Full command is %s up -d %s \n" "${DC_COMMAND}" "${SERVICE}" - fi - ${DC_COMMAND} up -d "${SERVICE}" + dc_cmd_create "${DC_CMD_PARAM}" cd - > /dev/null || { echo "cd failed"; exit 1; } else printf "ERROR: Service %s was not found in any of the stacks. Does it show up when you run %bdc list%b? \n" "${SERVICE}" "${RED}" "${NC}" @@ -584,23 +546,16 @@ function stop(){ tmp_stack_files_age for SERVICE in "$@"; do + DC_CMD_PARAM="stop ${SERVICE}" + DC_CMD_PARAM_RM="rm -f ${SERVICE}" if grep -r -q -x "${SERVICE}" ${TMP_DIR}; then STACK_NAME=$(basename "$(grep -r -x "${SERVICE}" "${TMP_DIR}" | cut -d : -f 1 )") STACK="${DC_DIR}/${STACK_NAME}" - if [ "${VERBOSE}" = true ]; then - printf "STACK is %s \n" "${STACK}" - printf "STACK_NAME is %s \n" "${STACK_NAME}" - printf "Found %s in %s \n" "${SERVICE}" "${STACK}" - fi + verbose_stack "${STACK}" "${STACK_NAME}" "${SERVICE}" cd "${STACK}" || { echo "cd failed"; exit 1; } create_env_file "${STACK}" "${STACK_NAME}" - DC_COMMAND="${DC_CMD_INIT} --env-file ${STACK}/${STACK_NAME}.env" - if [ "${VERBOSE}" = true ]; then - printf "DC_COMMAND is %s \n" "${DC_COMMAND}" - printf "Full command is %s stop %s; %s rm -f %s \n" "${DC_COMMAND}" "${SERVICE}" "${DC_COMMAND}" "${SERVICE}" - fi - ${DC_COMMAND} stop "${SERVICE}" - ${DC_COMMAND} rm -f "${SERVICE}" + dc_cmd_create "${DC_CMD_PARAM}" + dc_cmd_create "${DC_CMD_PARAM_RM}" cd - > /dev/null || { echo "cd failed"; exit 1; } else printf "ERROR: Service %s was not found in any of the stacks. Does it show up when you run %bdc list%b? \n" "${SERVICE}" "${RED}" "${NC}" @@ -630,23 +585,14 @@ function pull(){ tmp_stack_files_age for SERVICE in "$@"; do + DC_CMD_PARAM="pull ${SERVICE}" if grep -r -q -x "${SERVICE}" "${TMP_DIR}"; then STACK_NAME=$(basename "$(grep -r -x "${SERVICE}" "${TMP_DIR}" | cut -d : -f 1 )") STACK="${DC_DIR}/${STACK_NAME}" - if [ "${VERBOSE}" = true ]; then - printf "STACK is %s \n" "${STACK}" - printf "STACK_NAME is %s \n" "${STACK_NAME}" - printf "Found %s in %s \n" "${SERVICE}" "${STACK}" - fi + verbose_stack "${STACK}" "${STACK_NAME}" "${SERVICE}" cd "${STACK}" || { echo "cd failed"; exit 1; } create_env_file "${STACK}" "${STACK_NAME}" - DC_COMMAND="${DC_CMD_INIT} --env-file ${STACK}/${STACK_NAME}.env" - if [ "${VERBOSE}" = true ]; then - printf "DC_COMMAND is %s \n" "${DC_COMMAND}" - printf "Full command is %s pull %s \n" "${DC_COMMAND}" "${SERVICE}" - fi - printf "Running command: %s pull %s \n" "${DC_COMMAND}" "${SERVICE}" - ${DC_COMMAND} pull "${SERVICE}" + dc_cmd_create "${DC_CMD_PARAM}" cd - > /dev/null || { echo "cd failed"; exit 1; } else printf "ERROR: Service %s was not found in any of the stacks. Does it show up when you run %bdc list%b? \n" "${SERVICE}" "${RED}" "${NC}" @@ -675,22 +621,14 @@ function logs(){ tmp_stack_files_age for SERVICE in "$@"; do + DC_CMD_PARAM="logs --tail=100 -f ${SERVICE}" if grep -r -q -x "${SERVICE}" "${TMP_DIR}"; then STACK_NAME=$(basename "$(grep -r -x "${SERVICE}" "${TMP_DIR}" | cut -d : -f 1 )") STACK="${DC_DIR}/${STACK_NAME}" - if [ "${VERBOSE}" = true ]; then - printf "STACK is %s \n" "${STACK}" - printf "STACK_NAME is %s \n" "${STACK_NAME}" - printf "Found %s in %s \n" "${SERVICE}" "${STACK}" - fi + verbose_stack "${STACK}" "${STACK_NAME}" "${SERVICE}" cd "${STACK}" || { echo "cd failed"; exit 1; } create_env_file "${STACK}" "${STACK_NAME}" - DC_COMMAND="${DC_CMD_INIT} --env-file ${STACK}/${STACK_NAME}.env" - if [ "${VERBOSE}" = true ]; then - printf "DC_COMMAND is %s \n" "${DC_COMMAND}" - printf "Full command is %s logs --tail=100 -f %s \n" "${DC_COMMAND}" "${SERVICE}" - fi - ${DC_COMMAND} logs --tail=100 -f "${SERVICE}" & + dc_cmd_create "${DC_CMD_PARAM}" & if [ -z "$WAIT_PIDS" ] then export WAIT_PIDS="$!" diff --git a/dc-completion b/dc-completion index d7404f0..4bd66a6 100755 --- a/dc-completion +++ b/dc-completion @@ -2,7 +2,7 @@ # Copyright (C) 2022 - 2023 Ben Hählen # This is the completion file for `dc` ############## -# Version 3.0.1 +# Version 3.1.0 ############## _dc_completions() { @@ -37,10 +37,12 @@ _dc_completions() # We might need to create the tmp-files, so reusing the command from dc, however, this is duplicating stuff, which is not nice, but for a MVP, it works for STACK in $(find "${DC_DIR}" -name docker-compose.yml -printf '%h\n' | sort -u); do + STACK_NAME=$(echo "${STACK}" | rev | cut -d / -f 1 | rev) ENV="${DC_DIR}/.env" - DC_COMMAND="${DC_CMD} --env-file ${ENV}" + DC_CMD_INIT="${DC_CMD} --env-file ${ENV}" + DC_COMMAND="${DC_CMD_INIT} --env-file ${STACK}/${STACK_NAME}.env" + # echo "${DC_COMMAND}" TMP_DIR="/tmp/dc_stack_services" - STACK_NAME=$(echo "${STACK}" | rev | cut -d / -f 1 | rev) if [ ! -d "${TMP_DIR}" ]; then # echo "${TMP_DIR} not found. Creating..." mkdir -p ${TMP_DIR} @@ -50,12 +52,14 @@ _dc_completions() if [ "$(find ${TMP_DIR}/"${STACK_NAME}" -mmin +30)" ]; then # echo "File is too old, refreshing" cd "${STACK}" || { echo "cd failed"; exit 1; } + # echo "${DC_COMMAND}" ${DC_COMMAND} config --services > ${TMP_DIR}/"${STACK_NAME}" cd - > /dev/null || { echo "cd failed"; exit 1; } fi else # echo "File does not exist, creating" cd "${STACK}" || { echo "cd failed"; exit 1; } + # echo "${DC_COMMAND}" ${DC_COMMAND} config --services > ${TMP_DIR}/"${STACK_NAME}" cd - > /dev/null || { echo "cd failed"; exit 1; } fi