Skip to content

Commit

Permalink
Added compose script iterating all services
Browse files Browse the repository at this point in the history
Tried using main docker-compose - Problems listed as comments in the file
  • Loading branch information
DeanAyalon committed May 5, 2024
1 parent 497c83c commit 0ed9e46
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"editor.detectIndentation": false,
"files.associations": {
"*.env": "properties"
}
}
50 changes: 50 additions & 0 deletions compose.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

# Execution context
cd "$(dirname "$0")"

# Service modules
modules=("nginx" "verdaccio")

help() {
echo "Usage: $0 [-m] [-e] [args...]"
echo "Options:"
echo " -m Interactively choose modules to bring up."
echo " -e Interactively choose .env file for each module."
echo " args Specify the docker compose command to be ran."
}

# Flags
while getopts "ehm" opt; do
case ${opt} in
e ) custom_env=true ;;
h ) help; exit 2 ;;
m ) select_modules=true ;;
* ) help; exit 1 ;;
esac
done
shift $((OPTIND -1))

args=$@

# Compose the modules
for module in "${modules[@]}"; do
if [ $select_modules ]; then
read -p "Execute the command for $module? [Y/n] " choice
if [[ $choice =~ ^[Nn]$ ]]; then
echo "Skipping $module..."
continue
fi
fi

if [ $custom_env ]; then
echo "Choose an .env file for $module (default: $module/.env)"
read -p "$module/" env_file
[ ! -z $env_file ] && env_cmd="--env-file $module/$env_file"
fi

echo "$module: > docker compose $args"
[ ! -z $env_file ] && echo "env-file $env_file"
# Use Docker Compose to bring up the module
docker compose -f $module/docker-compose.yml $env_cmd $args
done
26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# name: dean
# services:
# nginx:
# # USES .ENV FROM THE MAIN DIR PATH, NOT NGINX
# extends:
# file: ./nginx/docker-compose.yml
# service: nginx
# verdaccio:
# extends:
# file: ./verdaccio/docker-compose.yml
# service: verdaccio

# ## ONLY USES .ENV FROM THE FIRST PATH
# # include:
# # - path:
# # - ./verdaccio/docker-compose.yml
# # - ./nginx/docker-compose.yml

# # ONLY USES .ENV FROM THE FIRST PATH
# # docker compose -f ./nginx/docker-compose.yml -f ./verdaccio/docker-compose.yml up -d

# # CLOSE, BUT VARIABLES UNDER THE SAME NAME, SUCH AS PORT, NOW NEED TO BE NAMED SERVICE_PORT, OR THEY'RE OVERRIDDEN BY THE LAST --ENV-FILE
# # docker compose --env-file ./nginx/.env --env-file ./verdaccio/.env up -d

# # I CAN HAVE A SCRIPT ENTER EACH SERVICE AND PERFORM docker compose up -d
# # BUT THAT MISSES THE POINT
2 changes: 1 addition & 1 deletion verdaccio

0 comments on commit 0ed9e46

Please sign in to comment.