blob: aff49f66f97ce37cfd4bab09a22a8bdf311bbc76 [file] [log] [blame]
Alanny Lopezaef0a492017-12-28 16:03:14 -06001#!/bin/bash
2###############################################################################
3#
Gunnar Mills61852582018-04-08 16:28:15 -05004# This script is for initializing the Kubernetes environment needed to run all
Alanny Lopezaef0a492017-12-28 16:03:14 -06005# 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 Mills61852582018-04-08 16:28:15 -050019# Suggested way to run is to create a separate script that will export all the
Alanny Lopezaef0a492017-12-28 16:03:14 -060020# 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 Lopez1347ea62018-02-25 01:07:59 -060033# 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 Lopezaef0a492017-12-28 16:03:14 -060062###############################################################################
63
Alanny Lopez1347ea62018-02-25 01:07:59 -060064# Variables used to initialize environment:
Alanny Lopezaef0a492017-12-28 16:03:14 -060065build_scripts_dir=${build_scripts_dir:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/.."}
Alanny Lopezaef0a492017-12-28 16:03:14 -060066email=${email:-email\@place.holder}
67k8s_master=${k8s_master:-True}
Alanny Lopez1347ea62018-02-25 01:07:59 -060068nfs_ip=${nfs_ip:-10.0.0.0}
69ns=${ns:-openbmc}
70pass=${pass:-password}
71path_prefix=${path_prefix:-/san_mount/openbmc_k8s}
72reclaim=${reclaim:-Retain}
73reg_server=${reg_server:-master.icp:8500}
74username=${username:-admin}
Alanny Lopezaef0a492017-12-28 16:03:14 -060075
76echo "Create the Jenkins Slave Workspace PVC"
77name="jenkins-slave-space"
78size="100Gi"
79mode="ReadWriteMany"
Alanny Lopez1347ea62018-02-25 01:07:59 -060080nfs_path="${path_prefix}/jenkins-slave-space"
Alanny Lopezaef0a492017-12-28 16:03:14 -060081source ${build_scripts_dir}/kubernetes/storage-setup.sh
82
83echo "Create the Shared State Cache PVC"
84name="shared-state-cache"
85size="100Gi"
86mode="ReadWriteMany"
Alanny Lopez1347ea62018-02-25 01:07:59 -060087nfs_path="${path_prefix}/sstate-cache"
Alanny Lopezaef0a492017-12-28 16:03:14 -060088source ${build_scripts_dir}/kubernetes/storage-setup.sh
89
90echo "Create the Openbmc Reference PVC"
91name="openbmc-reference-repo"
92size="1Gi"
93mode="ReadWriteMany"
Alanny Lopez1347ea62018-02-25 01:07:59 -060094nfs_path="${path_prefix}/openbmc"
Alanny Lopezaef0a492017-12-28 16:03:14 -060095source ${build_scripts_dir}/kubernetes/storage-setup.sh
96
97echo "Create the QEMU Reference PVC"
98name="qemu-repo"
99size="1Gi"
100mode="ReadWriteMany"
Alanny Lopez1347ea62018-02-25 01:07:59 -0600101nfs_path="${path_prefix}/qemu"
Alanny Lopezaef0a492017-12-28 16:03:14 -0600102source ${build_scripts_dir}/kubernetes/storage-setup.sh
103
104# Create the regkey secret for the internal docker registry
105kubectl create secret docker-registry regkey -n $ns \
106--docker-username=${username} \
107--docker-password=${pass} \
108--docker-email=${email} \
Alanny Lopez1347ea62018-02-25 01:07:59 -0600109--docker-server=${reg_server}
Alanny Lopezaef0a492017-12-28 16:03:14 -0600110
111# Create the docker config.json secret using the base64 encode of
112# '${username}:${pass}'
113
114base64up=$( echo -n "${username}:${pass}" | base64 )
115cat >> config.json << EOF
116{
117 "auths": {
118 "${regserver}": {
119 "auth": "${base64up}"
120 }
121 }
122}
123EOF
124
125chmod ugo+rw config.json
126kubectl create secret generic docker-config -n $ns --from-file=./config.json
127rm -f ./config.json
128
129if [[ "${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
149fi