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` |
Pawel | b7a057e | 2020-08-07 14:53:48 +0200 | [diff] [blame^] | 23 | PROJECT_DIRECTORY="plans/oom-platform-cert-service/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 | |
Joanna Jeremicz | 9c14f19 | 2020-03-19 14:51:51 +0100 | [diff] [blame] | 38 | #reinstall pyopenssl library |
| 39 | echo "Reinstall pyopenssl library." |
| 40 | pip uninstall pyopenssl -y |
| 41 | pip install pyopenssl==17.5.0 |
| 42 | |
Joanna Jeremicz | c21b008 | 2020-06-15 16:21:55 +0200 | [diff] [blame] | 43 | #install pyjks for .jks files management |
| 44 | pip install pyjks |
| 45 | |
kjaniak | 25fac3a | 2020-03-18 13:01:36 +0100 | [diff] [blame] | 46 | #Disable proxy - for local run |
| 47 | unset http_proxy https_proxy |
| 48 | |
Tomasz Wrobel | 75573b0 | 2020-03-05 16:43:50 +0100 | [diff] [blame] | 49 | #export container name |
| 50 | export ClientContainerName=CertServiceClient |
| 51 | # ------------------------------------ |
| 52 | |
Aleksandra Maciaga | 93f9ea4 | 2020-03-03 13:38:58 +0100 | [diff] [blame] | 53 | if test -d "$JENKINS_SCRIPTS_PATH"; then |
| 54 | SCRIPTS_PATH=$JENKINS_SCRIPTS_PATH |
| 55 | else test -f "$LOCAL_SCRIPTS_PATH"; |
| 56 | SCRIPTS_PATH=$LOCAL_SCRIPTS_PATH |
Aleksandra Maciaga | 7a5e3f6 | 2020-03-03 12:35:16 +0100 | [diff] [blame] | 57 | fi |
| 58 | echo "Use scripts from: $SCRIPTS_PATH" |
| 59 | |
Bogumil Zebek | 78bc8f3 | 2020-02-27 07:39:38 +0100 | [diff] [blame] | 60 | CONFIGURATION_FILE="cmpServers.json" |
Aleksandra Maciaga | 93f9ea4 | 2020-03-03 13:38:58 +0100 | [diff] [blame] | 61 | |
| 62 | JENKINS_CONFIGURATION_PATH="$CURRENT_WORKDIR_PATH/$PROJECT_DIRECTORY/$CONFIGURATION_FILE" |
| 63 | LOCAL_CONFIGURATION_PATH="$CURRENT_WORKDIR_PATH/$CONFIGURATION_FILE" |
| 64 | |
| 65 | if test -f "$JENKINS_CONFIGURATION_PATH"; then |
| 66 | CONFIGURATION_PATH="$JENKINS_CONFIGURATION_PATH" |
| 67 | else test -f "$LOCAL_CONFIGURATION_PATH"; |
| 68 | CONFIGURATION_PATH=$LOCAL_CONFIGURATION_PATH |
Bogumil Zebek | 78bc8f3 | 2020-02-27 07:39:38 +0100 | [diff] [blame] | 69 | fi |
| 70 | echo "Use configuration from: $CONFIGURATION_PATH" |
Aleksandra Maciaga | 7a5e3f6 | 2020-03-03 12:35:16 +0100 | [diff] [blame] | 71 | |
Bogumil Zebek | 78bc8f3 | 2020-02-27 07:39:38 +0100 | [diff] [blame] | 72 | # ------------------------------------- |
| 73 | |
Aleksandra Maciaga | 7a5e3f6 | 2020-03-03 12:35:16 +0100 | [diff] [blame] | 74 | export CONFIGURATION_PATH=${CONFIGURATION_PATH} |
| 75 | export SCRIPTS_PATH=${SCRIPTS_PATH} |
| 76 | |
Aleksandra Maciaga | 13b7d05 | 2020-03-26 17:28:47 +0100 | [diff] [blame] | 77 | #Generate keystores, truststores, certificates and keys |
Pawel | b7a057e | 2020-08-07 14:53:48 +0200 | [diff] [blame^] | 78 | mkdir -p ${WORKSPACE}/tests/oom-platform-cert-service/certservice/assets/certs/ |
Aleksandra Maciaga | 13b7d05 | 2020-03-26 17:28:47 +0100 | [diff] [blame] | 79 | make all -C ./certs/ |
Pawel | b7a057e | 2020-08-07 14:53:48 +0200 | [diff] [blame^] | 80 | cp ${WORKSPACE}/plans/oom-platform-cert-service/certservice/certs/root.crt ${WORKSPACE}/tests/oom-platform-cert-service/certservice/assets/certs/root.crt |
Aleksandra Maciaga | 13b7d05 | 2020-03-26 17:28:47 +0100 | [diff] [blame] | 81 | echo "Generated keystores" |
Pawel | b7a057e | 2020-08-07 14:53:48 +0200 | [diff] [blame^] | 82 | openssl pkcs12 -in ${WORKSPACE}/plans/oom-platform-cert-service/certservice/certs/certServiceServer-keystore.p12 -clcerts -nokeys -password pass:secret | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ${WORKSPACE}/tests/oom-platform-cert-service/certservice/assets/certs/certServiceServer.crt |
Aleksandra Maciaga | 13b7d05 | 2020-03-26 17:28:47 +0100 | [diff] [blame] | 83 | echo "Generated server certificate" |
Pawel | b7a057e | 2020-08-07 14:53:48 +0200 | [diff] [blame^] | 84 | openssl pkcs12 -in ${WORKSPACE}/plans/oom-platform-cert-service/certservice/certs/certServiceServer-keystore.p12 -nocerts -nodes -password pass:secret| sed -ne '/-BEGIN PRIVATE KEY-/,/-END PRIVATE KEY-/p' > ${WORKSPACE}/tests/oom-platform-cert-service/certservice/assets/certs/certServiceServer.key |
Aleksandra Maciaga | 13b7d05 | 2020-03-26 17:28:47 +0100 | [diff] [blame] | 85 | echo "Generated server key" |
| 86 | |
Aleksandra Maciaga | 7a5e3f6 | 2020-03-03 12:35:16 +0100 | [diff] [blame] | 87 | docker-compose up -d |
Aleksandra Maciaga | 6def597 | 2020-02-20 09:42:03 +0100 | [diff] [blame] | 88 | |
Pawel | b7a057e | 2020-08-07 14:53:48 +0200 | [diff] [blame^] | 89 | OOMCERT_IP='none' |
Aleksandra Maciaga | 6def597 | 2020-02-20 09:42:03 +0100 | [diff] [blame] | 90 | # Wait container ready |
Aleksandra Maciaga | 7ce0799 | 2020-03-09 10:01:12 +0100 | [diff] [blame] | 91 | for i in {1..9} |
| 92 | do |
Pawel | b7a057e | 2020-08-07 14:53:48 +0200 | [diff] [blame^] | 93 | OOMCERT_IP=`get-instance-ip.sh oomcert-service` |
Aleksandra Maciaga | 13b7d05 | 2020-03-26 17:28:47 +0100 | [diff] [blame] | 94 | RESP_CODE=$(curl -s https://localhost:8443/actuator/health --cacert ./certs/root.crt --cert-type p12 --cert ./certs/certServiceServer-keystore.p12 --pass secret | \ |
| 95 | python2 -c 'import json,sys;obj=json.load(sys.stdin);print obj["status"]') |
| 96 | if [[ "$RESP_CODE" == "UP" ]]; then |
Pawel | b7a057e | 2020-08-07 14:53:48 +0200 | [diff] [blame^] | 97 | echo 'OOM Cert Service is ready' |
| 98 | export OOMCERT_IP=${OOMCERT_IP} |
| 99 | docker exec oomcert-ejbca /opt/primekey/scripts/ejbca-configuration.sh |
Aleksandra Maciaga | 7ce0799 | 2020-03-09 10:01:12 +0100 | [diff] [blame] | 100 | break |
| 101 | fi |
Pawel | b7a057e | 2020-08-07 14:53:48 +0200 | [diff] [blame^] | 102 | echo 'Waiting for OOM Cert Service to start up...' |
Aleksandra Maciaga | 7ce0799 | 2020-03-09 10:01:12 +0100 | [diff] [blame] | 103 | sleep 30s |
| 104 | done |
Aleksandra Maciaga | 6def597 | 2020-02-20 09:42:03 +0100 | [diff] [blame] | 105 | |
Pawel | b7a057e | 2020-08-07 14:53:48 +0200 | [diff] [blame^] | 106 | if [ "$OOMCERT_IP" == 'none' -o "$OOMCERT_IP" == '' ]; then |
| 107 | echo "OOM Cert Service is not ready!" |
Aleksandra Maciaga | 7ce0799 | 2020-03-09 10:01:12 +0100 | [diff] [blame] | 108 | exit 1 # Return error code |
| 109 | fi |