From 1ed4efe2e944012af77bf8a14ac81574f5fb8b59 Mon Sep 17 00:00:00 2001 From: Benjamin Schmitz Date: Thu, 13 Jun 2024 08:14:09 +0200 Subject: [PATCH] Add regex to match docker services in artemis-docker.sh --- roles/artemis/templates/artemis-docker.sh.j2 | 37 ++++++++++++-------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/roles/artemis/templates/artemis-docker.sh.j2 b/roles/artemis/templates/artemis-docker.sh.j2 index 28de1b5..020cc65 100755 --- a/roles/artemis/templates/artemis-docker.sh.j2 +++ b/roles/artemis/templates/artemis-docker.sh.j2 @@ -26,21 +26,26 @@ HELP } function start { - local pr_tag=$1 - local pr_branch=$2 - - echo "Starting Artemis with PR tag: $pr_tag and branch: $pr_branch" - rm -rf Artemis - git clone https://github.com/ls1intum/Artemis.git -b "$pr_branch" Artemis - sed -i "s/ARTEMIS_DOCKER_TAG=.*/ARTEMIS_DOCKER_TAG='$pr_tag'/g" $ENV_FILE - docker compose --project-directory "$PROJECT_DIR" -f "$PROJECT_DIR/$COMPOSE_FILE" --env-file "$ENV_FILE" up -d --pull always --no-build + local pr_tag=$1 + local pr_branch=$2 + + echo "Starting Artemis with PR tag: $pr_tag and branch: $pr_branch" + rm -rf Artemis + git clone https://github.com/ls1intum/Artemis.git -b "$pr_branch" Artemis + sed -i "s/ARTEMIS_DOCKER_TAG=.*/ARTEMIS_DOCKER_TAG='$pr_tag'/g" $ENV_FILE + docker compose --project-directory "$PROJECT_DIR" -f "$PROJECT_DIR/$COMPOSE_FILE" --env-file "$ENV_FILE" up -d --pull always --no-build } function stop { - # TODO: In the future extract pr_tag and pr_branch from env + # TODO: In the future extract pr_tag and pr_branch from env + + echo "Stopping Artemis" - echo "Stopping Artemis" - docker compose --project-directory "$PROJECT_DIR" -f "$PROJECT_DIR/$COMPOSE_FILE" --env-file "$ENV_FILE" stop artemis-app + # Get all docker-compose services matching artemis-app* to be multi-node and single-node compatible. + services=$(docker compose --project-directory "$PROJECT_DIR" -f "$PROJECT_DIR/$COMPOSE_FILE" --env-file "$ENV_FILE" ps --services) + artemis_services=$(echo "$services" | grep "^artemis-app") + + docker compose --project-directory "$PROJECT_DIR" -f "$PROJECT_DIR/$COMPOSE_FILE" --env-file "$ENV_FILE" stop $artemis_services } function restart { @@ -49,15 +54,19 @@ function restart { } function artemis_logs { - docker compose --project-directory "$PROJECT_DIR" -f "$PROJECT_DIR/$COMPOSE_FILE" --env-file "$ENV_FILE" logs -f artemis-app + # Get all docker-compose services matching artemis-app* to be multi-node and single-node compatible. + services=$(docker compose --project-directory "$PROJECT_DIR" -f "$PROJECT_DIR/$COMPOSE_FILE" --env-file "$ENV_FILE" ps --services) + artemis_services=$(echo "$services" | grep "^artemis-app") + + docker compose --project-directory "$PROJECT_DIR" -f "$PROJECT_DIR/$COMPOSE_FILE" --env-file "$ENV_FILE" logs -f $artemis_services } function all_logs { - docker compose --project-directory "$PROJECT_DIR" -f "$PROJECT_DIR/$COMPOSE_FILE" --env-file "$ENV_FILE" logs -f + docker compose --project-directory "$PROJECT_DIR" -f "$PROJECT_DIR/$COMPOSE_FILE" --env-file "$ENV_FILE" logs -f } function run_docker_compose_cmd { - docker compose --project-directory "$PROJECT_DIR" -f "$PROJECT_DIR/$COMPOSE_FILE" --env-file "$ENV_FILE" "$@" + docker compose --project-directory "$PROJECT_DIR" -f "$PROJECT_DIR/$COMPOSE_FILE" --env-file "$ENV_FILE" "$@" } # read subcommand `artemis-docker subcommand server` in variable and remove base command from argument list