-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbootstrap.sh
executable file
·68 lines (59 loc) · 2.48 KB
/
bootstrap.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/sh
QUAYIO_USERNAME=$1
GITHUB_REPO=$2
ENV_PREFIX=$3
DEPLOYMENT_PATH=${4:-deploy}
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) SED_OPTIONS="-i";;
Darwin*) SED_OPTIONS="-i \"\"";;
*) echo "unknown OS ${unameOut}"; exit 1;;
esac
if [[ $# -lt 3 ]]; then
echo 'usage: ./setup.sh <quayio-username> <github repo> <prefix>'
exit 1
fi
IFS='/' # assumes orgname/repo
read -ra seg <<< "${GITHUB_REPO}"
if [[ ${#seg[@]} -ne 2 ]]; then
echo 'github repo must be of the form orgname/repo'
exit 1
fi
ORGNAME=${seg[0]}
APP_NAME=${seg[1]}
IMAGE_REPO="quay.io/${QUAYIO_USERNAME}/${APP_NAME}"
GITHUB_REPO="${ORGNAME}/${APP_NAME}"
GITHUB_STAGE_REPO="${ORGNAME}/${APP_NAME}-stage-config"
FILENAME="$HOME/Downloads/${QUAYIO_USERNAME}-auth.json"
if [ ! -f "${FILENAME}" ]; then
echo "${FILENAME} does not exist"
exit 1
fi
FILENAME="$HOME/Downloads/${QUAYIO_USERNAME}-secret.yml"
if [ ! -f "${FILENAME}" ]; then
echo "${FILENAME} does not exist"
exit 1
fi
sed $SED_OPTIONS "s|REPLACE_IMAGE|${IMAGE_REPO}|g" **/*.yaml
sed $SED_OPTIONS "s|GITHUB_REPO|${GITHUB_REPO}|g" 07-eventlisteners/cicd-event-listener.yaml
sed $SED_OPTIONS "s|GITHUB_STAGE_REPO|${GITHUB_STAGE_REPO}|g" 07-eventlisteners/cicd-event-listener.yaml
sed $SED_OPTIONS "s|DEPLOYMENT_PATH|${DEPLOYMENT_PATH}|g" 06-cd/*.yaml
sed $SED_OPTIONS "s|ENV_PREFIX|${ENV_PREFIX}|g" **/*.yaml
oc apply -f https://github.com/tektoncd/pipeline/releases/download/v0.10.1/release.notags.yaml
oc apply -f https://github.com/tektoncd/triggers/releases/download/v0.3.1/release.yaml
oc new-project ${ENV_PREFIX}-dev-environment
oc new-project ${ENV_PREFIX}-stage-environment
oc new-project ${ENV_PREFIX}-cicd-environment
oc create secret generic regcred --from-file=.dockerconfigjson="$HOME/Downloads/${QUAYIO_USERNAME}-auth.json" --type=kubernetes.io/dockerconfigjson
oc apply -f 02-serviceaccount
oc adm policy add-scc-to-user privileged -z demo-sa
oc adm policy add-role-to-user edit -z demo-sa
oc create rolebinding demo-sa-admin-dev --clusterrole=edit --serviceaccount=${ENV_PREFIX}-cicd-environment:demo-sa --namespace=${ENV_PREFIX}-dev-environment
oc create rolebinding demo-sa-admin-stage --clusterrole=edit --serviceaccount=${ENV_PREFIX}-cicd-environment:demo-sa --namespace=${ENV_PREFIX}-stage-environment
oc apply -f 03-tasks
oc apply -f 04-templatesandbindings
oc apply -f 05-ci
oc apply -f 06-cd
oc apply -f 07-eventlisteners
oc apply -f 08-routes
oc create secret generic github-auth --from-file="$HOME/Downloads/token"