blob: b0641b41a35cc27e20672d0ac2d7b8226c861f84 [file] [log] [blame]
waynedunicane4ff7e52023-03-01 09:07:31 +00001#!/bin/bash
2#
3# ============LICENSE_START====================================================
adheli.tavaresd802fd92024-08-15 12:39:19 +01004# Copyright (C) 2023-2024 Nordix Foundation.
waynedunicane4ff7e52023-03-01 09:07:31 +00005# =============================================================================
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.tavaresd802fd92024-08-15 12:39:19 +010021# 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
26START=false
27REPLICAS=2
28
29# Parse arguments
30while [[ "$#" -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
49done
50
waynedunicane4ff7e52023-03-01 09:07:31 +000051if [ -z "${WORKSPACE}" ]; then
52 WORKSPACE=$(git rev-parse --show-toplevel)
53 export WORKSPACE
54fi
waynedunicane4ff7e52023-03-01 09:07:31 +000055
adheli.tavaresd802fd92024-08-15 12:39:19 +010056COMPOSE_FOLDER="${WORKSPACE}"/compose
rameshiyer27f851a5e2024-07-02 09:16:56 +000057
waynedunicane4ff7e52023-03-01 09:07:31 +000058cd ${COMPOSE_FOLDER}
59
waynedunicane4ff7e52023-03-01 09:07:31 +000060source export-ports.sh > /dev/null 2>&1
61source get-versions.sh > /dev/null 2>&1
62
adheli.tavaresd802fd92024-08-15 12:39:19 +010063export REPLICAS
64
65export database=postgres
66
67if [ "$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
70else
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
84fi
waynedunicane4ff7e52023-03-01 09:07:31 +000085
rameshiyer27f851a5e2024-07-02 09:16:56 +000086cd ${WORKSPACE}