Aleksandra Maciaga | 6def597 | 2020-02-20 09:42:03 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
Bogumil Zebek | 78bc8f3 | 2020-02-27 07:39:38 +0100 | [diff] [blame] | 3 | # Copyright 2020 Nokia. |
Aleksandra Maciaga | 6def597 | 2020-02-20 09:42:03 +0100 | [diff] [blame] | 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | |
Bogumil Zebek | 78bc8f3 | 2020-02-27 07:39:38 +0100 | [diff] [blame] | 18 | # ------------------------------------ |
Aleksandra Maciaga | 93f9ea4 | 2020-03-03 13:38:58 +0100 | [diff] [blame] | 19 | # Resolve path to script's directory and cmp servers configuration |
Bogumil Zebek | 78bc8f3 | 2020-02-27 07:39:38 +0100 | [diff] [blame] | 20 | |
| 21 | SCRIPT=`realpath $0` |
| 22 | CURRENT_WORKDIR_PATH=`dirname $SCRIPT` |
Aleksandra Maciaga | 93f9ea4 | 2020-03-03 13:38:58 +0100 | [diff] [blame] | 23 | PROJECT_DIRECTORY="plans/aaf/certservice" |
Bogumil Zebek | 78bc8f3 | 2020-02-27 07:39:38 +0100 | [diff] [blame] | 24 | |
Aleksandra Maciaga | 7a5e3f6 | 2020-03-03 12:35:16 +0100 | [diff] [blame] | 25 | SCRIPTS_DIRECTORY="scripts" |
Aleksandra Maciaga | 93f9ea4 | 2020-03-03 13:38:58 +0100 | [diff] [blame] | 26 | |
| 27 | JENKINS_SCRIPTS_PATH="$CURRENT_WORKDIR_PATH/$PROJECT_DIRECTORY/$SCRIPTS_DIRECTORY" |
| 28 | LOCAL_SCRIPTS_PATH="$CURRENT_WORKDIR_PATH/$SCRIPTS_DIRECTORY" |
| 29 | |
Tomasz Wrobel | 75573b0 | 2020-03-05 16:43:50 +0100 | [diff] [blame] | 30 | # ------------------------------------ |
| 31 | #Prepare enviroment for client |
| 32 | #install docker sdk |
| 33 | echo "Uninstall docker-py and reinstall docker." |
| 34 | pip uninstall -y docker-py |
| 35 | pip uninstall -y docker |
| 36 | pip install -U docker==2.7.0 |
| 37 | |
| 38 | #export container name |
| 39 | export ClientContainerName=CertServiceClient |
| 40 | # ------------------------------------ |
| 41 | |
Aleksandra Maciaga | 93f9ea4 | 2020-03-03 13:38:58 +0100 | [diff] [blame] | 42 | if test -d "$JENKINS_SCRIPTS_PATH"; then |
| 43 | SCRIPTS_PATH=$JENKINS_SCRIPTS_PATH |
| 44 | else test -f "$LOCAL_SCRIPTS_PATH"; |
| 45 | SCRIPTS_PATH=$LOCAL_SCRIPTS_PATH |
Aleksandra Maciaga | 7a5e3f6 | 2020-03-03 12:35:16 +0100 | [diff] [blame] | 46 | fi |
| 47 | echo "Use scripts from: $SCRIPTS_PATH" |
| 48 | |
Bogumil Zebek | 78bc8f3 | 2020-02-27 07:39:38 +0100 | [diff] [blame] | 49 | CONFIGURATION_FILE="cmpServers.json" |
Aleksandra Maciaga | 93f9ea4 | 2020-03-03 13:38:58 +0100 | [diff] [blame] | 50 | |
| 51 | JENKINS_CONFIGURATION_PATH="$CURRENT_WORKDIR_PATH/$PROJECT_DIRECTORY/$CONFIGURATION_FILE" |
| 52 | LOCAL_CONFIGURATION_PATH="$CURRENT_WORKDIR_PATH/$CONFIGURATION_FILE" |
| 53 | |
| 54 | if test -f "$JENKINS_CONFIGURATION_PATH"; then |
| 55 | CONFIGURATION_PATH="$JENKINS_CONFIGURATION_PATH" |
| 56 | else test -f "$LOCAL_CONFIGURATION_PATH"; |
| 57 | CONFIGURATION_PATH=$LOCAL_CONFIGURATION_PATH |
Bogumil Zebek | 78bc8f3 | 2020-02-27 07:39:38 +0100 | [diff] [blame] | 58 | fi |
| 59 | echo "Use configuration from: $CONFIGURATION_PATH" |
Aleksandra Maciaga | 7a5e3f6 | 2020-03-03 12:35:16 +0100 | [diff] [blame] | 60 | |
Bogumil Zebek | 78bc8f3 | 2020-02-27 07:39:38 +0100 | [diff] [blame] | 61 | # ------------------------------------- |
| 62 | |
Aleksandra Maciaga | 7a5e3f6 | 2020-03-03 12:35:16 +0100 | [diff] [blame] | 63 | export CONFIGURATION_PATH=${CONFIGURATION_PATH} |
| 64 | export SCRIPTS_PATH=${SCRIPTS_PATH} |
| 65 | |
| 66 | docker-compose up -d |
Aleksandra Maciaga | 6def597 | 2020-02-20 09:42:03 +0100 | [diff] [blame] | 67 | |
Aleksandra Maciaga | 7ce0799 | 2020-03-09 10:01:12 +0100 | [diff] [blame] | 68 | AAFCERT_IP='none' |
Aleksandra Maciaga | 6def597 | 2020-02-20 09:42:03 +0100 | [diff] [blame] | 69 | # Wait container ready |
Aleksandra Maciaga | 7ce0799 | 2020-03-09 10:01:12 +0100 | [diff] [blame] | 70 | for i in {1..9} |
| 71 | do |
| 72 | AAFCERT_IP=`get-instance-ip.sh aafcert` |
| 73 | RESP_CODE=$(curl -I -s -o /dev/null -w "%{http_code}" http://${AAFCERT_IP}:8080/actuator/health) |
| 74 | if [[ "$RESP_CODE" == '200' ]]; then |
| 75 | echo 'AAF Cert Service is ready' |
| 76 | export AAFCERT_IP=${AAFCERT_IP} |
| 77 | docker exec aafcert-ejbca /opt/primekey/scripts/ejbca-configuration.sh |
| 78 | break |
| 79 | fi |
| 80 | echo 'Waiting for AAF Cert Service to start up...' |
| 81 | sleep 30s |
| 82 | done |
Aleksandra Maciaga | 6def597 | 2020-02-20 09:42:03 +0100 | [diff] [blame] | 83 | |
Aleksandra Maciaga | 7ce0799 | 2020-03-09 10:01:12 +0100 | [diff] [blame] | 84 | if [[ $AAFCERT_IP == 'none' ] || [ $AAFCERT_IP == '' ]]; then |
| 85 | echo "AAF Cert Service is not ready!" |
| 86 | exit 1 # Return error code |
| 87 | fi |