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
10 # http://www.apache.org/licenses/LICENSE-2.0
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=================================================
21 echo "Usage: docker-setup.sh"
34 echo "Cleaning previously started containers..."
39 docker system prune -f
40 docker volume prune -f
42 echo "Creating dir for minio volume mapping"
44 mkdir -p /tmp/minio-test
45 mkdir -p /tmp/minio-test/0
46 rm -rf /tmp/minio-test/0/*
48 NW="nonrtric-docker-net"
49 echo "Creating docker network"
50 docker network inspect $NW 2> /dev/null 1> /dev/null
52 docker network create $NW
54 echo " Network: $NW exits"
59 if [ -z "$(docker images -q $1)" ]; then
60 echo "Pulling image... "$1
67 export KEYCLOAK_IMAGE=quay.io/keycloak/keycloak:20.0.1
68 pull_image $KEYCLOAK_IMAGE
70 export OPA_IMAGE=openpolicyagent/opa:latest-envoy
73 export BUNDLE_IMAGE=nginx:1.21
74 pull_image $BUNDLE_IMAGE
76 export MINIO_IMAGE=minio/minio
77 pull_image $MINIO_IMAGE
79 export REDPANDA_IMAGE=redpandadata/console:v2.2.3
80 pull_image $REDPANDA_IMAGE
82 export STRIMZI_IMAGE=quay.io/strimzi/kafka:0.35.0-kafka-3.4.0
83 pull_image $STRIMZI_IMAGE
85 export DMAAP_IMAGE=nexus3.onap.org:10002/onap/dmaap/dmaap-mr:1.4.4
86 pull_image $DMAAP_IMAGE
88 export VES_COLLECTOR_IMAGE=nexus3.onap.org:10002/onap/org.onap.dcaegen2.collectors.ves.vescollector:1.12.3
89 pull_image $VES_COLLECTOR_IMAGE
91 export ICS_IMAGE="nexus3.o-ran-sc.org:10001/o-ran-sc/nonrtric-plt-informationcoordinatorservice:1.5.0"
94 export DMAAPADP_IMAGE="nexus3.o-ran-sc.org:10001/o-ran-sc/nonrtric-plt-pmproducer:1.0.1"
95 pull_image $DMAAPADP_IMAGE
97 export DFC_IMAGE="nexus3.o-ran-sc.org:10001/o-ran-sc/nonrtric-plt-ranpm-datafilecollector:1.0.0"
100 export KPX_IMAGE="nexus3.o-ran-sc.org:10001/o-ran-sc/nonrtric-plt-ranpm-pm-file-converter:1.0.1"
101 pull_image $KPX_IMAGE
103 export AUTH_TOKEN_IMAGE=nexus3.o-ran-sc.org:10001/o-ran-sc/nonrtric-plt-auth-token-fetch:1.1.1
104 pull_image $AUTH_TOKEN_IMAGE
106 export NONRTRIC_GATEWAY_IMAGE=nexus3.o-ran-sc.org:10001/o-ran-sc/nonrtric-gateway:1.2.0
107 pull_image $NONRTRIC_GATEWAY_IMAGE
109 export CONTROL_PANEL_IMAGE=nexus3.o-ran-sc.org:10001/o-ran-sc/nonrtric-controlpanel:2.5.0
110 pull_image $CONTROL_PANEL_IMAGE
114 ./config/keycloak/certs/gen-certs.sh
115 echo "Starting containers for: keycloak, opa"
116 envsubst '$KEYCLOAK_IMAGE,$OPA_IMAGE,$BUNDLE_IMAGE' < docker-compose-security.yaml > docker-compose-security_gen.yaml
117 docker-compose -p security -f docker-compose-security_gen.yaml up -d
121 # Create realm in keycloak
122 . scripts/populate_keycloak.sh
124 create_realms nonrtric-realm
125 while [ $? -ne 0 ]; do
126 create_realms nonrtric-realm
129 # Create client for admin calls
131 create_clients nonrtric-realm $cid
133 generate_client_secrets nonrtric-realm $cid
140 TOKEN=$(get_client_token nonrtric-realm $cid)
142 cid="kafka-producer-pm-xml2json"
143 create_clients nonrtric-realm $cid
145 generate_client_secrets nonrtric-realm $cid
148 export XML2JSON_CLIENT_SECRET=$(< .sec_nonrtric-realm_$cid)
150 cid="pm-producer-json2kafka"
151 create_clients nonrtric-realm $cid
153 generate_client_secrets nonrtric-realm $cid
156 export JSON2KAFKA_CLIENT_SECRET=$(< .sec_nonrtric-realm_$cid)
159 create_clients nonrtric-realm $cid
161 generate_client_secrets nonrtric-realm $cid
164 export DFC_CLIENT_SECRET=$(< .sec_nonrtric-realm_$cid)
168 echo "Starting containers for: kafka, zookeeper, kafka client, ics, minio"
169 envsubst < docker-compose-k1.yaml > docker-compose-k1_gen.yaml
170 docker-compose -p common -f docker-compose-k1_gen.yaml up -d
174 echo "Creating topics: $TOPICS, may take a while ..."
178 echo "Creating topic $t with retention $(($rt/1000)) seconds"
179 while [ $retcode -ne 0 ]; do
180 docker exec -it common-kafka-1-1 ./bin/kafka-topics.sh \
181 --create --topic $t --config retention.ms=$rt --bootstrap-server kafka-1:9092
189 echo "Starting $NUM_DFC dfc"
190 export DFC_MINIO=http://minio-server:9000
191 export FILES_VOLUME="/pm-files"
194 for (( i=1; i<=$NUM_DFC; i++ )); do
195 echo "Updating dfc$i truststore"
197 cp ../dfc-common/template-truststore.jks truststore.jks
200 echo " Adding https ca cert to dfc$i truststore"
201 keytool -importcert -alias pm-https -file $cwd/config/https/certs/httpsca.crt -keystore truststore.jks -storetype JKS -storepass $(cat ../dfc-common/truststore.pass) -noprompt
206 chmod 666 config/dfc1/token-cache/jwt.txt
207 envsubst < docker-compose-dfc1.yaml > docker-compose-dfc_gen.yaml
208 envsubst < config/dfc1/application-template.yaml > config/dfc1/application.yaml
209 docker-compose -p dfc -f docker-compose-dfc_gen.yaml up -d
213 echo "Starting producers"
214 chmod 666 config/pmpr/token-cache/jwt.txt
215 export KPADP_MINIO=http://minio-server:9000
216 cp config/pmpr/application_configuration-minio-template.json config/pmpr/application_configuration.json
217 envsubst < config/pmpr/application-minio-template.yaml > config/pmpr/application.yaml
219 envsubst < docker-compose-producers.yaml > docker-compose-producers_gen.yaml
220 docker-compose -p prod -f docker-compose-producers_gen.yaml up -d
223 create_http_servers_certs() {
226 ./config/https/certs/gen-certs.sh $NUM_HTTP
229 setup_http_servers() {
230 cp pm-files/pm* ne-files
232 echo "Starting http servers"
233 export PM_HTTPSSERVER_IMAGE="pm-https-server:latest"
235 total_lines=$(cat docker-compose-pm-https.yaml | wc -l)
236 services_line=$(grep -n "services:" docker-compose-pm-https.yaml| cut -f1 -d:)
237 let remaining_lines=$total_lines-$services_line
238 export START_TIME=$(date +%Y%m%d.%H%M -d '3 hours ago')
240 grep -B $services_line "services:" docker-compose-pm-https.yaml > docker-compose-pm-https_gen.yaml
241 for (( i=1; i<=$NUM_HTTP; i++ )); do
242 export CONTAINER_NUM=$i
243 grep -A $remaining_lines "services:" docker-compose-pm-https.yaml | grep -v "services:" | \
244 envsubst '$CONTAINER_NUM,$PM_HTTPSSERVER_IMAGE,$START_TIME' >> docker-compose-pm-https_gen.yaml
246 docker-compose -p pm-https -f docker-compose-pm-https_gen.yaml up -d
250 export KAFKA_NUM_PARTITIONS=10
251 export TOPICS="file-ready collected-file json-file-ready-kp json-file-ready-kpadp pmreports"
260 # Wait for keycloak to start
261 echo 'Waiting for keycloak to be ready'
262 until [ $(curl -s -w '%{http_code}' -o /dev/null 'http://localhost:8462') -eq 200 ];
275 create_http_servers_certs
287 scripts/clean-shared-volume.sh