rameshiyer27 | f851a5e | 2024-07-02 09:16:56 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # ============LICENSE_START==================================================== |
| 4 | # Copyright (C) 2024 Nordix Foundation. |
| 5 | # ============================================================================= |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # |
| 18 | # SPDX-License-Identifier: Apache-2.0 |
| 19 | # ============LICENSE_END====================================================== |
| 20 | |
adheli.tavares | d802fd9 | 2024-08-15 12:39:19 +0100 | [diff] [blame] | 21 | # Usage: --start to run the docker compose with acm replicas |
| 22 | # --stop to stop the docker compose containers |
| 23 | # --replicas number of replicas (defaults to 2) |
| 24 | |
| 25 | # Initialize variables |
| 26 | START=false |
| 27 | REPLICAS=2 |
| 28 | |
| 29 | # Parse arguments |
| 30 | while [[ "$#" -gt 0 ]]; do |
| 31 | case $1 in |
| 32 | --start) |
| 33 | START=true |
| 34 | shift |
| 35 | ;; |
| 36 | --stop) |
| 37 | START=false |
| 38 | shift |
| 39 | ;; |
| 40 | --replicas=*) |
| 41 | REPLICAS="${1#*=}" |
| 42 | shift |
| 43 | ;; |
| 44 | *) |
| 45 | echo "Unknown option: $1" |
| 46 | exit 1 |
| 47 | ;; |
| 48 | esac |
| 49 | done |
| 50 | |
rameshiyer27 | f851a5e | 2024-07-02 09:16:56 +0000 | [diff] [blame] | 51 | if [ -z "${WORKSPACE}" ]; then |
| 52 | WORKSPACE=$(git rev-parse --show-toplevel) |
| 53 | export WORKSPACE |
| 54 | fi |
| 55 | |
rameshiyer27 | f851a5e | 2024-07-02 09:16:56 +0000 | [diff] [blame] | 56 | COMPOSE_FOLDER="${WORKSPACE}"/compose |
| 57 | |
| 58 | cd ${COMPOSE_FOLDER} |
| 59 | |
| 60 | echo "Configuring docker compose..." |
| 61 | source export-ports.sh > /dev/null 2>&1 |
| 62 | source get-versions.sh > /dev/null 2>&1 |
| 63 | |
adheli.tavares | d802fd9 | 2024-08-15 12:39:19 +0100 | [diff] [blame] | 64 | export REPLICAS |
| 65 | |
| 66 | if [ -z "$PROJECT" ]; then |
| 67 | export PROJECT=clamp |
| 68 | fi |
| 69 | |
| 70 | export database=postgres |
| 71 | |
| 72 | if [ "$START" = true ]; then |
| 73 | docker compose -f compose.acm.scale.yml up -d nginx |
| 74 | else |
| 75 | containers=$(docker compose -f compose.acm.scale.yml ps --all --format '{{.Service}}') |
| 76 | |
| 77 | IFS=$'\n' read -d '' -r -a item_list <<< "$containers" |
| 78 | for item in "${item_list[@]}" |
| 79 | do |
| 80 | if [ -n "$item" ]; then |
| 81 | docker compose -f compose.acm.scale.yml logs $item >> $item.log |
| 82 | fi |
| 83 | done |
| 84 | |
| 85 | docker compose -f compose.acm.scale.yml down -v --remove-orphans |
| 86 | fi |
| 87 | |
rameshiyer27 | f851a5e | 2024-07-02 09:16:56 +0000 | [diff] [blame] | 88 | cd ${WORKSPACE} |