Alanny Lopez | aef0a49 | 2017-12-28 16:03:14 -0600 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | ############################################################################### |
| 3 | # |
| 4 | # This script is for initializing the Kubernetes environement needed to run all |
| 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: |
| 19 | # Suggested way to run is to create a seperate script that will export all the |
| 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: |
| 33 | # ns = Name of namespace we will be deploying the components into, |
| 34 | # defaults to "openbmc". |
| 35 | # nfsip = IP address of the NFS server we will be using for mounting a |
| 36 | # Persistent Volume (PV) to, defaults to "10.0.0.0", should be |
| 37 | # replaced with an actual IP address of an NFS server. |
| 38 | # reclaim = The reclaim policy that will be used when creating the PV |
| 39 | # look at k8s docs for more info on this. Defaults to "Retain". |
| 40 | # path_prefix = The prefix we will add to the nfspath of the directories we |
| 41 | # intend to mount. This is used to place all the different |
| 42 | # directories into the same parent folder on the NFS server. |
| 43 | # defaults to "/san_mount/openbmc_k8s", should be changed to |
| 44 | # a valid path on your NFS server. |
| 45 | # regserver = The docker registry which will be used when pushing and |
| 46 | # pulling images. For internal use, it will be the internal |
| 47 | # registry created by ICP, defaults to "master.icp:8500" must |
| 48 | # be changed to an actual registry. |
| 49 | # username = The username that will be used to login to the regserver, |
| 50 | # defaults to "admin", should be changed. |
| 51 | # pass = The password that will be used to login to the regserver, |
| 52 | # defaults to "password", should be changed. |
| 53 | # email = The email that will be used to login to the regserver, |
| 54 | # defaults to "email@place.holder", should be changed. |
| 55 | # k8s_master = Set to True if you want to deploy a Jenkins Master into k8s, |
| 56 | # defaults to True. |
| 57 | ############################################################################### |
| 58 | |
| 59 | build_scripts_dir=${build_scripts_dir:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/.."} |
| 60 | |
| 61 | ns=${ns:-openbmc} |
| 62 | nfsip=${nfsip:-10.0.0.0} |
| 63 | regserver=${regserver:-master.icp:8500} |
| 64 | reclaim=${reclaim:-Retain} |
| 65 | path_prefix=${path_prefix:-/san_mount/openbmc_k8s} |
| 66 | username=${username:-admin} |
| 67 | pass=${pass:-password} |
| 68 | email=${email:-email\@place.holder} |
| 69 | k8s_master=${k8s_master:-True} |
| 70 | |
| 71 | echo "Create the Jenkins Slave Workspace PVC" |
| 72 | name="jenkins-slave-space" |
| 73 | size="100Gi" |
| 74 | mode="ReadWriteMany" |
| 75 | nfspath="${path_prefix}/jenkins-slave-space" |
| 76 | source ${build_scripts_dir}/kubernetes/storage-setup.sh |
| 77 | |
| 78 | echo "Create the Shared State Cache PVC" |
| 79 | name="shared-state-cache" |
| 80 | size="100Gi" |
| 81 | mode="ReadWriteMany" |
| 82 | nfspath="${path_prefix}/sstate-cache" |
| 83 | source ${build_scripts_dir}/kubernetes/storage-setup.sh |
| 84 | |
| 85 | echo "Create the Openbmc Reference PVC" |
| 86 | name="openbmc-reference-repo" |
| 87 | size="1Gi" |
| 88 | mode="ReadWriteMany" |
| 89 | nfspath="${path_prefix}/openbmc" |
| 90 | source ${build_scripts_dir}/kubernetes/storage-setup.sh |
| 91 | |
| 92 | echo "Create the QEMU Reference PVC" |
| 93 | name="qemu-repo" |
| 94 | size="1Gi" |
| 95 | mode="ReadWriteMany" |
| 96 | nfspath="${path_prefix}/qemu" |
| 97 | source ${build_scripts_dir}/kubernetes/storage-setup.sh |
| 98 | |
| 99 | # Create the regkey secret for the internal docker registry |
| 100 | kubectl create secret docker-registry regkey -n $ns \ |
| 101 | --docker-username=${username} \ |
| 102 | --docker-password=${pass} \ |
| 103 | --docker-email=${email} \ |
| 104 | --docker-server=${regserver} |
| 105 | |
| 106 | # Create the docker config.json secret using the base64 encode of |
| 107 | # '${username}:${pass}' |
| 108 | |
| 109 | base64up=$( echo -n "${username}:${pass}" | base64 ) |
| 110 | cat >> config.json << EOF |
| 111 | { |
| 112 | "auths": { |
| 113 | "${regserver}": { |
| 114 | "auth": "${base64up}" |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | EOF |
| 119 | |
| 120 | chmod ugo+rw config.json |
| 121 | kubectl create secret generic docker-config -n $ns --from-file=./config.json |
| 122 | rm -f ./config.json |
| 123 | |
| 124 | if [[ "${k8s_master}" == "True" ]]; then |
| 125 | # Create the Jenkins Master Home PVC |
| 126 | echo "Create the Jenkins Master Home PVC" |
| 127 | name="jenkins-home" |
| 128 | size="2Gi" |
| 129 | mode="ReadWriteOnce" |
| 130 | nfspath="${path_prefix}/jenkins-master-home" |
| 131 | source ${build_scripts_dir}/kubernetes/storage-setup.sh |
| 132 | |
| 133 | # Launch the Jenkins Master |
| 134 | launch="k8s" |
| 135 | # Clean up variables before sourcing the build-jenkins.sh |
| 136 | unset ns \ |
| 137 | nfsip \ |
| 138 | regserver \ |
| 139 | reclaim \ |
| 140 | path_prefix \ |
| 141 | username \ |
| 142 | pass email |
| 143 | source ${build_scripts_dir}/build-jenkins.sh |
| 144 | fi |