Remove extra popd
[kni/installer.git] / ci / kni_deploy_libvirt.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='testing.virt.edge-sites.net'
22
23 echo '---> Starting kni installer generation'
24 export GOPATH=${WORKSPACE}/
25
26 # first build kni installer
27 sudo rm -rf ${WORKSPACE}/${KNI_PATH}
28 mkdir -p ${WORKSPACE}/${KNI_PATH}/installer
29 cp -a installer ${WORKSPACE}/${KNI_PATH}/
30 pushd ${WORKSPACE}/${KNI_PATH}/installer
31 make build 2>&1 | tee ${WORKSPACE}/build.log
32
33 # do a host preparation and cleanup
34 bash utils/prep_host.sh virt.edge-sites.net
35 wget https://raw.githubusercontent.com/openshift/installer/master/scripts/maintenance/virsh-cleanup.sh
36 chmod a+x ./virsh-cleanup.sh
37 sudo -E bash -c "yes Y | ./virsh-cleanup.sh"
38
39 # add the right credentials to kni
40 mkdir $HOME/.kni || true
41 cp $WORKSPACE/akraino-secrets/coreos-pull-secret $HOME/.kni/pull-secret.json || true
42 cp $HOME/.ssh/id_rsa.pub $HOME/.kni/id_rsa.pub || true
43
44 # replace site path with a local ref to the cloned blueprint
45 BLUEPRINT_PATH="${WORKSPACE}/blueprint-pae/"
46 KUSTOMIZATION_FILE=${BLUEPRINT_PATH}/sites/${SITE_NAME}/00_install-config/kustomization.yaml
47 sed -i "s#- git::https://gerrit.akraino.org/r/kni/blueprint-pae.git/#- file://${BLUEPRINT_PATH}#g" ${KUSTOMIZATION_FILE}
48
49 # start the workflow
50 sudo rm -rf /$HOME/.kni/${SITE_NAME}/final_manifests || true
51 ./knictl fetch_requirements file://${BLUEPRINT_PATH}/sites/${SITE_NAME} 2>&1 | tee ${WORKSPACE}/libvirt_requirements.log
52 ./knictl prepare_manifests ${SITE_NAME} 2>&1 | tee ${WORKSPACE}/libvirt_manifests.log
53
54 # now run the cluster
55 source $HOME/.kni/${SITE_NAME}/profile.env
56 sudo -E $HOME/.kni/${SITE_NAME}/requirements/openshift-install create cluster --dir=/$HOME/.kni/${SITE_NAME}/final_manifests 2>&1 | tee ${WORKSPACE}/libvirt_deploy.log
57 STATUS=$?
58
59 # output tfstate
60 echo "metadata.json for removing cluster"
61 cat $HOME/.kni/${SITE_NAME}/final_manifests/metadata.json
62
63 if [ $STATUS -ne 0 ]; then
64     echo "Error deploying in libvirt"
65     exit 1
66 fi
67
68 echo "Cluster successfully deployed! Start applying workloads"
69 ./knictl apply_workloads ${SITE_NAME} 2>&1 | tee ${WORKSPACE}/libvirt_workloads.log
70 STATUS=$?
71
72 if [ $STATUS -ne 0 ]; then
73     echo "Error applying workloads to libvirt"
74     exit 1
75 fi
76
77 popd
78
79 exit $STATUS