Skip to content

Commit

Permalink
Merge pull request #56 from brhahlen/dev
Browse files Browse the repository at this point in the history
3.0.1
  • Loading branch information
brhahlen authored Sep 1, 2023
2 parents 4333ffd + 6daeb30 commit 53d4d68
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Version 3.0.1
## Enhancement
- When any of \<stackname\>.env files is not found, `dc` will ask you if it is allowed to create the file(s) for you

# Version 3.0.0
## BREAKING CHANGE
- Added the use of a stack specific environment file in the `dc` command, next to the "normal" `.env` file that is used by `dc`. It is possible to use empty \<stackname\>.env files, as that will be accepted. Backwards compatibility might be put in later.
Expand Down
11 changes: 3 additions & 8 deletions build-files/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# Version 3.0.0
## BREAKING CHANGE
- Added the use of a stack specific environment file in the `dc` command, next to the "normal" `.env` file that is used by `dc`. It is possible to use empty \<stackname\>.env files, as that will be accepted. Backwards compatibility might be put in later.

## Enhancements
- `list` will now call the proper function
- Development versions will have verbosity enabled by default (that's just for me)
- Major rework to make things more consistent
# Version 3.0.1
## Enhancement
- When any of \<stackname\>.env files is not found, `dc` will ask you if it is allowed to create the file(s) for you
54 changes: 52 additions & 2 deletions dc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
set -m

# VERSION
export DC_VERSION=v3.0.0
export DC_VERSION=v3.0.1-dev

###### VARIABLES
if [[ -z "${DC_DIR}" ]]; then
Expand Down Expand Up @@ -85,6 +85,43 @@ function tmp_stack_files_age(){
done
}

# CREATE ENV FILES
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
if [ ! -f "${STACK}/${STACK_NAME}.env" ]; then
printf "%s.env does not exist \n" "${STACK_NAME}"
if [ "${ALLOW_ENV_CREATE}" = true ]; then
printf "Creating %s.env \n" "${STACK_NAME}"
touch "${STACK}/${STACK_NAME}.env"
else
printf "No prior authorization given for creation of .env files \n"
while true; do
read -r -p "Do you want to proceed? (y/n) " yn
case $yn in
[yY] )
printf "Creating %s.env \n" "${STACK_NAME}"
touch "${STACK}/${STACK_NAME}.env"
export ALLOW_ENV_CREATE=true
break
;;
[nN] )
printf "Not creating .env files, will exit \n"
exit
;;
* )
printf "Invalid response"
;;
esac
done
fi
fi
}

##################################################
# USAGE AND LIST #
##################################################
Expand Down Expand Up @@ -288,6 +325,7 @@ function up(){
STACK_NAME=$(basename "${STACK}")
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}"
Expand All @@ -303,6 +341,7 @@ function up(){
if [ -d "${STACK}" ]; then
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}"
Expand All @@ -328,6 +367,7 @@ function down(){
STACK_NAME=$(basename "${STACK}")
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}"
Expand All @@ -343,6 +383,7 @@ function down(){
if [ -d "${STACK}" ]; then
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}"
Expand Down Expand Up @@ -372,10 +413,11 @@ function restart-stack-hard(){
printf "STACK is %s \n" "${STACK}"
printf "STACK_NAME is %s \n" "${STACK_NAME}"
fi
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}"
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; }
Expand All @@ -393,6 +435,7 @@ function restart-stack-hard(){
printf "STACK_NAME is %s \n" "${STACK_NAME}"
fi
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}"
Expand Down Expand Up @@ -423,6 +466,7 @@ function restart-stack-soft(){
printf "STACK is %s \n" "${STACK}"
printf "STACK_NAME is %s \n" "${STACK_NAME}"
fi
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}"
Expand All @@ -443,6 +487,7 @@ function restart-stack-soft(){
printf "STACK_NAME is %s \n" "${STACK_NAME}"
fi
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}"
Expand Down Expand Up @@ -475,6 +520,7 @@ function logs-stack(){
if [ -d "${STACK}" ]; then
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}"
Expand Down Expand Up @@ -513,6 +559,7 @@ function start(){
printf "Found %s in %s \n" "${SERVICE}" "${STACK}"
fi
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}"
Expand Down Expand Up @@ -546,6 +593,7 @@ function stop(){
printf "Found %s in %s \n" "${SERVICE}" "${STACK}"
fi
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}"
Expand Down Expand Up @@ -591,6 +639,7 @@ function pull(){
printf "Found %s in %s \n" "${SERVICE}" "${STACK}"
fi
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}"
Expand Down Expand Up @@ -635,6 +684,7 @@ function logs(){
printf "Found %s in %s \n" "${SERVICE}" "${STACK}"
fi
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}"
Expand Down
2 changes: 1 addition & 1 deletion dc-completion
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (C) 2022 - 2023 Ben Hählen
# This is the completion file for `dc`
##############
# Version 3.0.0
# Version 3.0.1
##############
_dc_completions()
{
Expand Down

0 comments on commit 53d4d68

Please sign in to comment.