ktimoney | 82e5136 | 2023-08-28 13:41:45 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # ============LICENSE_START=============================================== |
| 4 | # Copyright (C) 2023 Nordix Foundation. All rights reserved. |
| 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 | # ============LICENSE_END================================================= |
| 18 | # |
| 19 | |
| 20 | . scripts/get_influxdb2_token.sh |
| 21 | . scripts/populate_keycloak.sh |
| 22 | |
| 23 | print_usage() { |
| 24 | echo "Usage: pmrapp-setup.sh" |
| 25 | exit 1 |
| 26 | } |
| 27 | |
| 28 | check_error() { |
| 29 | if [ $1 -ne 0 ]; then |
| 30 | echo "Failed $2" |
| 31 | echo "Exiting..." |
| 32 | exit 1 |
| 33 | fi |
| 34 | } |
| 35 | |
| 36 | setup_init() { |
| 37 | echo "Cleaning previously started containers..." |
| 38 | ./pmrapp-tear-down.sh |
| 39 | } |
| 40 | |
| 41 | check_images(){ |
| 42 | export PMRAPP_IMAGE="pm-rapp:latest" |
| 43 | } |
| 44 | |
| 45 | create_topic() { |
| 46 | TOPIC="rapp-topic" |
| 47 | retcode=1 |
| 48 | rt=43200000 |
| 49 | echo "Creating topic $TOPIC with retention $(($rt/1000)) seconds" |
| 50 | while [ $retcode -ne 0 ]; do |
| 51 | cmd_output=$(docker exec -it common-kafka-1-1 ./bin/kafka-topics.sh \ |
| 52 | --create --topic $TOPIC --config retention.ms=$rt --bootstrap-server kafka-1:9092) |
| 53 | retcode=$? |
| 54 | test_string="Topic 'rapp-topic' already exists" |
| 55 | if [[ $cmd_output == *${test_string}* ]]; then |
| 56 | echo $test_string |
| 57 | retcode=0 |
| 58 | fi |
| 59 | done |
| 60 | } |
| 61 | |
| 62 | setup_pmrapp() { |
| 63 | create_topic |
| 64 | |
| 65 | cid="pm-rapp" |
| 66 | create_clients nonrtric-realm $cid |
| 67 | check_error $? |
| 68 | generate_client_secrets nonrtric-realm $cid |
| 69 | check_error $? |
| 70 | |
| 71 | export PMRAPP_CLIENT_SECRET=$(< .sec_nonrtric-realm_$cid) |
| 72 | envsubst < docker-compose-pmrapp.yaml > docker-compose-pmrapp_gen.yaml |
| 73 | docker-compose -p pmrapp -f docker-compose-pmrapp_gen.yaml up -d |
| 74 | } |
| 75 | ## Main ## |
| 76 | setup_init |
| 77 | |
| 78 | check_images |
| 79 | |
| 80 | setup_pmrapp |
| 81 | check_error $? |