Skip to content

Commit

Permalink
Update ecs generator launcher script
Browse files Browse the repository at this point in the history
  • Loading branch information
QU3B1M committed Dec 13, 2024
1 parent 368315d commit c25a034
Showing 1 changed file with 61 additions and 29 deletions.
90 changes: 61 additions & 29 deletions docker/ecs/ecs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,73 @@ set -e
# ====
# Checks that the script is run from the intended location
# ====
function check_project_root_folder() {
current=$(basename "$(pwd)")
function navigate_to_project_root() {
local repo_root_marker
local script_path
local script_abs_path

if [[ "$0" != "./ecs.sh" && "$0" != "ecs.sh" ]]; then
echo "Run the script from its location"
usage
repo_root_marker=".github"
script_path=$(dirname "$0")
script_abs_path=$(cd "$script_path" && pwd)

while [[ "$script_abs_path" != "/" ]] && [[ ! -f "$script_abs_path/$repo_root_marker" ]]; do
script_abs_path=$(dirname "$script_abs_path")
done

if [[ "$script_abs_path" == "/" ]]; then
echo "Unable to find the repository root."
exit 1
fi
# Change working directory to the root of the repository
cd ../..

cd "$script_abs_path"
}

# ====
# Displays usage information
# ====
function usage() {
echo "Usage: $0 {up|down|stop} <ECS_MODULE> [REPO_PATH]"
exit 1
}

function main() {
export REPO_PATH="$2"
export ECS_MODULE="$3"
local compose_filename="docker/${current}/ecs.yml"
local compose_cmd="docker compose run -f $compose_filename"

case $1 in
up)
# Main folder created here to grant access to both containers
mkdir -p artifacts
$compose_cmd up -d
;;
down)
$compose_cmd down
;;
stop)
$compose_cmd stop
;;
*)
usage
exit 1
;;
esac
local compose_filename
local compose_cmd
local module
local repo_path

if [[ "$#" -lt 2 || "$#" -gt 3 ]]; then
usage
fi

navigate_to_project_root

module="$2"
if [[ -n "$3" ]]; then
repo_path="$3"
else
repo_path="$(pwd)"
fi

compose_filename="docker/ecs/ecs.yml"
compose_cmd="docker-compose -f $compose_filename"

case $1 in
up)
# Main folder created here to grant access to both containers
mkdir -p artifacts
$compose_cmd ECS_MODULE="$module" REPO_PATH="$repo_path" up -d
;;
down)
$compose_cmd down
;;
stop)
$compose_cmd stop
;;
*)
usage
;;
esac
}

main "$@"

0 comments on commit c25a034

Please sign in to comment.