blob: a9e95b88dd23f96f41f1d52012150ebd7d2017e5 [file] [log] [blame]
rameshiyer27f851a5e2024-07-02 09:16:56 +00001#!/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.tavaresd802fd92024-08-15 12:39:19 +010021# 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
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
rameshiyer27f851a5e2024-07-02 09:16:56 +000051if [ -z "${WORKSPACE}" ]; then
52 WORKSPACE=$(git rev-parse --show-toplevel)
53 export WORKSPACE
54fi
55
rameshiyer27f851a5e2024-07-02 09:16:56 +000056COMPOSE_FOLDER="${WORKSPACE}"/compose
57
58cd ${COMPOSE_FOLDER}
59
60echo "Configuring docker compose..."
61source export-ports.sh > /dev/null 2>&1
62source get-versions.sh > /dev/null 2>&1
63
adheli.tavaresd802fd92024-08-15 12:39:19 +010064export REPLICAS
65
66if [ -z "$PROJECT" ]; then
67 export PROJECT=clamp
68fi
69
70export database=postgres
71
72if [ "$START" = true ]; then
73 docker compose -f compose.acm.scale.yml up -d nginx
74else
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
86fi
87
rameshiyer27f851a5e2024-07-02 09:16:56 +000088cd ${WORKSPACE}