waynedunican | e4ff7e5 | 2023-03-01 09:07:31 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # ============LICENSE_START==================================================== |
adheli.tavares | d802fd9 | 2024-08-15 12:39:19 +0100 | [diff] [blame] | 4 | # Copyright (C) 2023-2024 Nordix Foundation. |
waynedunican | e4ff7e5 | 2023-03-01 09:07:31 +0000 | [diff] [blame] | 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 apex-pdp 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 | |
waynedunican | e4ff7e5 | 2023-03-01 09:07:31 +0000 | [diff] [blame] | 51 | if [ -z "${WORKSPACE}" ]; then |
| 52 | WORKSPACE=$(git rev-parse --show-toplevel) |
| 53 | export WORKSPACE |
| 54 | fi |
waynedunican | e4ff7e5 | 2023-03-01 09:07:31 +0000 | [diff] [blame] | 55 | |
adheli.tavares | d802fd9 | 2024-08-15 12:39:19 +0100 | [diff] [blame] | 56 | COMPOSE_FOLDER="${WORKSPACE}"/compose |
rameshiyer27 | f851a5e | 2024-07-02 09:16:56 +0000 | [diff] [blame] | 57 | |
waynedunican | e4ff7e5 | 2023-03-01 09:07:31 +0000 | [diff] [blame] | 58 | cd ${COMPOSE_FOLDER} |
| 59 | |
waynedunican | e4ff7e5 | 2023-03-01 09:07:31 +0000 | [diff] [blame] | 60 | source export-ports.sh > /dev/null 2>&1 |
| 61 | source get-versions.sh > /dev/null 2>&1 |
| 62 | |
adheli.tavares | d802fd9 | 2024-08-15 12:39:19 +0100 | [diff] [blame] | 63 | export REPLICAS |
| 64 | |
| 65 | export database=postgres |
| 66 | |
| 67 | if [ "$START" = true ]; then |
| 68 | echo "Configuring docker compose for apex-pdp scaled with ${REPLICAS} replicas..." |
| 69 | docker compose -f compose.pdp.scale.yml up -d apexpdp nginx grafana postgres |
| 70 | else |
| 71 | echo "Collecting logs..." |
| 72 | containers=$(docker compose -f compose.pdp.scale.yml ps --all --format '{{.Service}}') |
| 73 | |
| 74 | IFS=$'\n' read -d '' -r -a item_list <<< "$containers" |
| 75 | for item in "${item_list[@]}" |
| 76 | do |
| 77 | if [ -n "$item" ]; then |
| 78 | docker compose -f compose.pdp.scale.yml logs $item >> $item.log |
| 79 | fi |
| 80 | done |
| 81 | |
| 82 | echo "Stopping compose containers..." |
| 83 | docker compose -f compose.pdp.scale.yml down -v --remove-orphans |
| 84 | fi |
waynedunican | e4ff7e5 | 2023-03-01 09:07:31 +0000 | [diff] [blame] | 85 | |
rameshiyer27 | f851a5e | 2024-07-02 09:16:56 +0000 | [diff] [blame] | 86 | cd ${WORKSPACE} |