adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # ============LICENSE_START==================================================== |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 4 | # Copyright (C) 2022-2024 Nordix Foundation. |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +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 | |
| 21 | #Usage: $0 [policy-component] [OPTIONS]" |
| 22 | #" OPTIONS:" |
| 23 | #" --grafana start the docker compose with grafana" |
| 24 | #" --gui start the docker compose with gui" |
| 25 | #" no policy-component will start all components" |
| 26 | |
| 27 | if [ -z "${WORKSPACE}" ]; then |
| 28 | WORKSPACE=$(git rev-parse --show-toplevel) |
| 29 | export WORKSPACE |
| 30 | fi |
| 31 | COMPOSE_FOLDER="${WORKSPACE}"/compose |
| 32 | |
| 33 | # Set default values for the options |
| 34 | grafana=false |
| 35 | gui=false |
| 36 | |
| 37 | # Parse the command-line arguments |
| 38 | while [[ $# -gt 0 ]] |
| 39 | do |
| 40 | key="$1" |
| 41 | |
| 42 | case $key in |
| 43 | --grafana) |
| 44 | grafana=true |
| 45 | shift |
| 46 | ;; |
| 47 | --gui) |
| 48 | gui=true |
| 49 | shift 2 |
| 50 | break; |
| 51 | ;; |
| 52 | *) |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 53 | component="$1" |
| 54 | shift |
| 55 | ;; |
| 56 | esac |
| 57 | done |
| 58 | |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 59 | cd ${COMPOSE_FOLDER} |
| 60 | |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 61 | echo "Configuring docker compose..." |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 62 | source export-ports.sh > /dev/null 2>&1 |
| 63 | source get-versions.sh > /dev/null 2>&1 |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 64 | |
| 65 | # in case of csit running for PAP (groups should be for pap) but starts apex-pdp for dependencies. |
| 66 | if [ -z "$PROJECT" ]; then |
adheli.tavares | c244ab0 | 2023-03-13 16:55:02 +0000 | [diff] [blame] | 67 | export PROJECT=$component |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 68 | fi |
| 69 | |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 70 | # docker compose fails when not running CSIT |
| 71 | if [ -z "$ROBOT_LOG_DIR" ]; then |
| 72 | export ROBOT_LOG_DIR=/tmp/ |
| 73 | fi |
| 74 | |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 75 | if [ -n "$component" ]; then |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 76 | if [ "$component" == "logs" ]; then |
| 77 | echo "Collecting logs..." |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 78 | docker compose logs > docker-compose.log |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 79 | elif [ "$grafana" = true ]; then |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 80 | echo "Starting ${component} application with Grafana" |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 81 | docker compose up -d "${component}" grafana |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 82 | echo "Prometheus server: http://localhost:${PROMETHEUS_PORT}" |
| 83 | echo "Grafana server: http://localhost:${GRAFANA_PORT}" |
| 84 | elif [ "$gui" = true ]; then |
| 85 | echo "Starting application with gui..." |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 86 | docker compose -f docker-compose.yml -f docker-compose.gui.yml up -d "${component}" policy-gui |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 87 | echo "Clamp GUI: https://localhost:2445/clamp" |
| 88 | else |
| 89 | echo "Starting ${component} application" |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 90 | docker compose up -d "${component}" |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 91 | fi |
| 92 | else |
adheli.tavares | c244ab0 | 2023-03-13 16:55:02 +0000 | [diff] [blame] | 93 | export PROJECT=api # api has groups.json complete with all 3 pdps |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 94 | if [ "$gui" = true ]; then |
| 95 | echo "Starting application with gui..." |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 96 | docker compose -f docker-compose.yml -f docker-compose.gui.yml up -d |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 97 | echo "Clamp GUI: https://localhost:2445/clamp" |
| 98 | else |
| 99 | echo "Starting all components..." |
adheli.tavares | 80e382e | 2024-05-01 14:08:35 +0100 | [diff] [blame] | 100 | docker compose up -d |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 101 | fi |
| 102 | fi |
adheli.tavares | 5980fb4 | 2023-03-16 16:31:11 +0000 | [diff] [blame] | 103 | |
| 104 | cd ${WORKSPACE} |