Alanny Lopez | aef0a49 | 2017-12-28 16:03:14 -0600 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | ############################################################################### |
| 3 | # |
Gunnar Mills | 6185258 | 2018-04-08 16:28:15 -0500 | [diff] [blame] | 4 | # This script is for initializing the Kubernetes environment needed to run all |
Alanny Lopez | aef0a49 | 2017-12-28 16:03:14 -0600 | [diff] [blame] | 5 | # the kubernetes integrated scripts in Kubernetes. |
| 6 | # - Provisions the PV's and PVC's for: |
| 7 | # * The Kubernetes JNLP Jenkins slave's shared workspace |
| 8 | # * Shared state cache |
| 9 | # * Openbmc/openbmc git reference repository |
| 10 | # * Openbmc/qemu git reference repository |
| 11 | # - Create docker-registry secret for pulling from the internal repo |
| 12 | # - Create the config.json used to mount docker configuration to Kubernetes |
| 13 | # Jenkins slaves that build and push docker images via shell scripts. |
| 14 | # Optionally: |
| 15 | # - Launch a Jenkins Master deployment into Kubernetes. |
| 16 | # - Provision the PV and PVC for the Jenkin Master home directory |
| 17 | # |
| 18 | # Instructions: |
Gunnar Mills | 6185258 | 2018-04-08 16:28:15 -0500 | [diff] [blame] | 19 | # Suggested way to run is to create a separate script that will export all the |
Alanny Lopez | aef0a49 | 2017-12-28 16:03:14 -0600 | [diff] [blame] | 20 | # necessary variables and then source in this script. But editing this one |
| 21 | # works as well. |
| 22 | # |
| 23 | ############################################################################### |
| 24 | # |
| 25 | # Requirements: |
| 26 | # - NFS server with directory to use as path for mount |
| 27 | # - Access to an existing Kubernetes Cluster |
| 28 | # - Kubectl installed and configured on machine running script |
| 29 | # |
| 30 | ############################################################################### |
| 31 | # |
| 32 | # Variables used to initialize environment: |
Alanny Lopez | 1347ea6 | 2018-02-25 01:07:59 -0600 | [diff] [blame] | 33 | # build_scripts_dir The path for the openbmc-build-scripts directory. |
| 34 | # Default: The parent directory containing this script |
| 35 | # email The email that will be used to login to the regserver. |
| 36 | # Default: "email@place.holder", placeholder. |
| 37 | # k8s_master Set to True if you want to deploy a Jenkins Master into |
| 38 | # the Kubernetes deployment. |
| 39 | # Default: True |
| 40 | # nfs_ip IP address of the NFS server we will be using for mounting |
| 41 | # a Persistent Volume (PV) to. This should be replaced with |
| 42 | # an actual IP address of an NFS server. |
| 43 | # Default: "10.0.0.0", placeholder |
| 44 | # ns Name of namespace the components will be deployed into. |
| 45 | # Default:"openbmc" |
| 46 | # pass The password that will be used to login to the regserver. |
| 47 | # Default: "password", placeholder |
| 48 | # path_prefix The prefix we will add to the nfspath of the directories |
| 49 | # we intend to mount. This is used to place all the |
| 50 | # different directories into the same parent folder on the |
| 51 | # NFS server. |
| 52 | # Default: "/san_mount/openbmc_k8s", placeholder |
| 53 | # reclaim The reclaim policy that will be used when creating the PV |
| 54 | # look at k8s docs for more info on this. |
| 55 | # Default: "Retain" |
| 56 | # reg_server The docker registry which will be used when pushing and |
| 57 | # pulling images. For internal use, it will be the internal |
| 58 | # registry created by ICP. |
| 59 | # Default: "master.icp:8500", placeholder |
| 60 | # username The username that will be used to login to the regserver. |
| 61 | # Default: "admin", placeholder |
Alanny Lopez | aef0a49 | 2017-12-28 16:03:14 -0600 | [diff] [blame] | 62 | ############################################################################### |
| 63 | |
Alanny Lopez | 1347ea6 | 2018-02-25 01:07:59 -0600 | [diff] [blame] | 64 | # Variables used to initialize environment: |
Alanny Lopez | aef0a49 | 2017-12-28 16:03:14 -0600 | [diff] [blame] | 65 | build_scripts_dir=${build_scripts_dir:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/.."} |
Alanny Lopez | aef0a49 | 2017-12-28 16:03:14 -0600 | [diff] [blame] | 66 | email=${email:-email\@place.holder} |
| 67 | k8s_master=${k8s_master:-True} |
Alanny Lopez | 1347ea6 | 2018-02-25 01:07:59 -0600 | [diff] [blame] | 68 | nfs_ip=${nfs_ip:-10.0.0.0} |
| 69 | ns=${ns:-openbmc} |
| 70 | pass=${pass:-password} |
| 71 | path_prefix=${path_prefix:-/san_mount/openbmc_k8s} |
| 72 | reclaim=${reclaim:-Retain} |
| 73 | reg_server=${reg_server:-master.icp:8500} |
| 74 | username=${username:-admin} |
Alanny Lopez | aef0a49 | 2017-12-28 16:03:14 -0600 | [diff] [blame] | 75 | |
| 76 | echo "Create the Jenkins Slave Workspace PVC" |
| 77 | name="jenkins-slave-space" |
| 78 | size="100Gi" |
| 79 | mode="ReadWriteMany" |
Alanny Lopez | 1347ea6 | 2018-02-25 01:07:59 -0600 | [diff] [blame] | 80 | nfs_path="${path_prefix}/jenkins-slave-space" |
Alanny Lopez | aef0a49 | 2017-12-28 16:03:14 -0600 | [diff] [blame] | 81 | source ${build_scripts_dir}/kubernetes/storage-setup.sh |
| 82 | |
| 83 | echo "Create the Shared State Cache PVC" |
| 84 | name="shared-state-cache" |
| 85 | size="100Gi" |
| 86 | mode="ReadWriteMany" |
Alanny Lopez | 1347ea6 | 2018-02-25 01:07:59 -0600 | [diff] [blame] | 87 | nfs_path="${path_prefix}/sstate-cache" |
Alanny Lopez | aef0a49 | 2017-12-28 16:03:14 -0600 | [diff] [blame] | 88 | source ${build_scripts_dir}/kubernetes/storage-setup.sh |
| 89 | |
| 90 | echo "Create the Openbmc Reference PVC" |
| 91 | name="openbmc-reference-repo" |
| 92 | size="1Gi" |
| 93 | mode="ReadWriteMany" |
Alanny Lopez | 1347ea6 | 2018-02-25 01:07:59 -0600 | [diff] [blame] | 94 | nfs_path="${path_prefix}/openbmc" |
Alanny Lopez | aef0a49 | 2017-12-28 16:03:14 -0600 | [diff] [blame] | 95 | source ${build_scripts_dir}/kubernetes/storage-setup.sh |
| 96 | |
| 97 | echo "Create the QEMU Reference PVC" |
| 98 | name="qemu-repo" |
| 99 | size="1Gi" |
| 100 | mode="ReadWriteMany" |
Alanny Lopez | 1347ea6 | 2018-02-25 01:07:59 -0600 | [diff] [blame] | 101 | nfs_path="${path_prefix}/qemu" |
Alanny Lopez | aef0a49 | 2017-12-28 16:03:14 -0600 | [diff] [blame] | 102 | source ${build_scripts_dir}/kubernetes/storage-setup.sh |
| 103 | |
| 104 | # Create the regkey secret for the internal docker registry |
| 105 | kubectl create secret docker-registry regkey -n $ns \ |
| 106 | --docker-username=${username} \ |
| 107 | --docker-password=${pass} \ |
| 108 | --docker-email=${email} \ |
Alanny Lopez | 1347ea6 | 2018-02-25 01:07:59 -0600 | [diff] [blame] | 109 | --docker-server=${reg_server} |
Alanny Lopez | aef0a49 | 2017-12-28 16:03:14 -0600 | [diff] [blame] | 110 | |
| 111 | # Create the docker config.json secret using the base64 encode of |
| 112 | # '${username}:${pass}' |
| 113 | |
| 114 | base64up=$( echo -n "${username}:${pass}" | base64 ) |
| 115 | cat >> config.json << EOF |
| 116 | { |
| 117 | "auths": { |
| 118 | "${regserver}": { |
| 119 | "auth": "${base64up}" |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | EOF |
| 124 | |
| 125 | chmod ugo+rw config.json |
| 126 | kubectl create secret generic docker-config -n $ns --from-file=./config.json |
| 127 | rm -f ./config.json |
| 128 | |
| 129 | if [[ "${k8s_master}" == "True" ]]; then |
| 130 | # Create the Jenkins Master Home PVC |
| 131 | echo "Create the Jenkins Master Home PVC" |
| 132 | name="jenkins-home" |
| 133 | size="2Gi" |
| 134 | mode="ReadWriteOnce" |
| 135 | nfspath="${path_prefix}/jenkins-master-home" |
| 136 | source ${build_scripts_dir}/kubernetes/storage-setup.sh |
| 137 | |
| 138 | # Launch the Jenkins Master |
| 139 | launch="k8s" |
| 140 | # Clean up variables before sourcing the build-jenkins.sh |
| 141 | unset ns \ |
| 142 | nfsip \ |
| 143 | regserver \ |
| 144 | reclaim \ |
| 145 | path_prefix \ |
| 146 | username \ |
| 147 | pass email |
| 148 | source ${build_scripts_dir}/build-jenkins.sh |
| 149 | fi |