From 0ed9e4696563e02d792675bab34689a8ecbbf20f Mon Sep 17 00:00:00 2001 From: Dean Ayalon Date: Mon, 6 May 2024 00:47:01 +0300 Subject: [PATCH] Added compose script iterating all services Tried using main docker-compose - Problems listed as comments in the file --- .vscode/settings.json | 6 ++++++ compose.sh | 50 +++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 26 ++++++++++++++++++++++ verdaccio | 2 +- 4 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json create mode 100755 compose.sh create mode 100644 docker-compose.yml diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f807e44 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "editor.detectIndentation": false, + "files.associations": { + "*.env": "properties" + } +} \ No newline at end of file diff --git a/compose.sh b/compose.sh new file mode 100755 index 0000000..84d61f6 --- /dev/null +++ b/compose.sh @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3ae2878 --- /dev/null +++ b/docker-compose.yml @@ -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 diff --git a/verdaccio b/verdaccio index 95dc83b..f2a2678 160000 --- a/verdaccio +++ b/verdaccio @@ -1 +1 @@ -Subproject commit 95dc83b305f65f0ad8ffc71967929293865aec4e +Subproject commit f2a267858c53c7ffa2dfb48c8d317ade70027536