Merge "Enable merge jobs to trigger downstream job"
[ci-management.git] / jjb / shell / kni_deploy_aws.sh
1 #!/bin/bash
2 #
3 # Copyright (c) 2019 Red Hat
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 set -e -u -x -o pipefail
18
19 export PATH=$PATH:/usr/local/go/bin:/usr/local/bin
20 KNI_PATH='src/gerrit.akraino.org/kni/'
21 SITE_NAME='edge-sites-testing.devcluster.openshift.com'
22
23 echo '---> Starting kni installer generation'
24 export GOPATH=${WORKSPACE}/
25
26 # move the blueprint to an inner directory
27 mkdir ${WORKSPACE}/blueprint-pae
28 mv base profiles sites tools ${WORKSPACE}/blueprint-pae/
29
30 # clone installer in the right directory
31 sudo rm -rf ${WORKSPACE}/${KNI_PATH}
32 mkdir -p ${WORKSPACE}/${KNI_PATH}
33 pushd ${WORKSPACE}/${KNI_PATH}/
34 git clone https://gerrit.akraino.org/r/kni/installer
35 pushd installer
36
37 # first build kni installer
38 make build 2>&1 | tee ${WORKSPACE}/build.log
39
40 # add the right credentials to kni
41 mkdir $HOME/.kni || true
42 cp $WORKSPACE/akraino-secrets/coreos-pull-secret $HOME/.kni/pull-secret.json || true
43
44 # start the workflow
45 ./knictl fetch_requirements file://${WORKSPACE}/blueprint-pae//sites/${SITE_NAME} 2>&1 | tee ${WORKSPACE}/aws_requirements.log
46 ./knictl prepare_manifests ${SITE_NAME} 2>&1 | tee ${WORKSPACE}/aws_manifests.log
47
48 # now run the cluster
49 source $HOME/.kni/${SITE_NAME}/profile.env
50 $HOME/.kni/${SITE_NAME}/requirements/openshift-install create cluster --dir=/$HOME/.kni/${SITE_NAME}/final_manifests 2>&1 | tee ${WORKSPACE}/aws_deploy.log
51 STATUS=$?
52
53 # output tfstate
54 echo "metadata.json for removing cluster"
55 cat $HOME/.kni/${SITE_NAME}/final_manifests/metadata.json
56
57 if [ $STATUS -ne 0 ]; then
58     echo "Error deploying in AWS"
59     exit 1
60 fi
61
62 echo "Cluster successfully deployed! Start applying workloads"
63 ./knictl apply_workloads ${SITE_NAME} 2>&1 | tee ${WORKSPACE}/aws_workloads.go
64 STATUS=$?
65
66 if [ $STATUS -ne 0 ]; then
67     echo "Error applying workloads to AWS"
68     exit 1
69 fi
70
71 echo "Workloads successfully applied! Starting cleanup"
72 $HOME/.kni/${SITE_NAME}/requirements/openshift-install destroy cluster --dir=/$HOME/.kni/${SITE_NAME}/final_manifests 2>&1 | tee ${WORKSPACE}/aws_destroy.log
73 STATUS=$?
74
75 popd
76
77 exit $STATUS