|
1 |
| -#!/bin/sh |
| 1 | +#!/bin/bash |
| 2 | + |
2 | 3 | REGISTRY_URL=$1
|
3 | 4 | JENKINS_USER=$2
|
4 | 5 | JENKINS_PASSWORD=$3
|
5 | 6 | GITHUB_USER_NAME=$4
|
6 | 7 | GITHUB_USER_EMAIL=$5
|
7 | 8 | GITHUB_ORGANIZATION=$6
|
8 | 9 | GITHUB_PERSONAL_ACCESS_TOKEN=$7
|
9 |
| -DT_API_TOKEN=$8 |
10 |
| -DT_TENANT_URL=$9 |
11 | 10 |
|
12 |
| -# Deploy Jenkins - see keptn/install/setupInfrastructure.sh: |
| 11 | +source ./deploy_utils.sh |
| 12 | + |
| 13 | +# Deploy Jenkins |
13 | 14 | rm -f config/jenkins/gen/k8s-jenkins-deployment.yml
|
14 | 15 |
|
15 |
| -export GATEWAY=$(kubectl describe svc istio-ingressgateway -n istio-system | grep "LoadBalancer Ingress:" | sed 's~LoadBalancer Ingress:[ \t]*~~') |
| 16 | +GATEWAY=$(kubectl describe svc istio-ingressgateway -n istio-system | grep "LoadBalancer Ingress:" | sed 's~LoadBalancer Ingress:[ \t]*~~') |
| 17 | +verify_variable "$GATEWAY" "GATEWAY is empty and could not be derived from the Istio ingress gateway." |
16 | 18 |
|
17 | 19 | cat config/jenkins/k8s-jenkins-deployment.yml | \
|
18 | 20 | sed 's~GATEWAY_PLACEHOLDER~'"$GATEWAY"'~' | \
|
19 | 21 | sed 's~GITHUB_USER_EMAIL_PLACEHOLDER~'"$GITHUB_USER_EMAIL"'~' | \
|
20 | 22 | sed 's~GITHUB_ORGANIZATION_PLACEHOLDER~'"$GITHUB_ORGANIZATION"'~' | \
|
21 |
| - sed 's~DOCKER_REGISTRY_IP_PLACEHOLDER~'"$REGISTRY_URL"'~' | \ |
22 |
| - sed 's~DT_TENANT_URL_PLACEHOLDER~'"$DT_TENANT_URL"'~' | \ |
23 |
| - sed 's~DT_API_TOKEN_PLACEHOLDER~'"$DT_API_TOKEN"'~' >> config/jenkins/gen/k8s-jenkins-deployment.yml |
24 |
| - |
25 |
| -kubectl create -f config/jenkins/k8s-jenkins-pvcs.yml |
26 |
| -kubectl create -f config/jenkins/gen/k8s-jenkins-deployment.yml |
27 |
| -kubectl create -f config/jenkins/k8s-jenkins-rbac.yml |
28 |
| -kubectl create -f config/jenkins/k8s-jenkins-service-entry.yml |
29 |
| - |
30 |
| -echo "Wait 200s for Jenkins..." |
31 |
| -sleep 200 |
32 |
| - |
33 |
| -# Setup credentials in Jenkins |
34 |
| -echo "--------------------------" |
35 |
| -echo "Setup Credentials in Jenkins " |
36 |
| -echo "--------------------------" |
37 |
| - |
38 |
| -# Export Jenkins route in a variable |
39 |
| -export JENKINS_URL="jenkins.keptn.$GATEWAY.xip.io" |
40 |
| - |
41 |
| -curl -X POST http://$JENKINS_URL/credentials/store/system/domain/_/createCredentials \ |
42 |
| ---user $JENKINS_USER:$JENKINS_PASSWORD \ |
43 |
| ---data-urlencode 'json={ |
44 |
| - "": "0", |
45 |
| - "credentials": { |
46 |
| - "scope": "GLOBAL", |
47 |
| - "id": "git-credentials-acm", |
48 |
| - "username": "'$GITHUB_USER_NAME'", |
49 |
| - "password": "'$GITHUB_PERSONAL_ACCESS_TOKEN'", |
50 |
| - "description": "Token used by Jenkins to access the GitHub repositories", |
51 |
| - "$class": "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl" |
52 |
| - } |
53 |
| -}' |
54 |
| - |
55 |
| -curl -X POST http://$JENKINS_URL/credentials/store/system/domain/_/createCredentials \ |
56 |
| ---user $JENKINS_USER:$JENKINS_PASSWORD \ |
57 |
| ---data-urlencode 'json={ |
58 |
| - "": "0", |
59 |
| - "credentials": { |
60 |
| - "scope": "GLOBAL", |
61 |
| - "id": "perfsig-api-token", |
62 |
| - "apiToken": "'$DT_API_TOKEN'", |
63 |
| - "description": "Dynatrace API Token used by the Performance Signature plugin", |
64 |
| - "$class": "de.tsystems.mms.apm.performancesignature.dynatracesaas.model.DynatraceApiTokenImpl" |
65 |
| - } |
66 |
| -}' |
67 |
| - |
68 |
| -echo "--------------------------" |
69 |
| -echo "End setup credentials in Jenkins " |
70 |
| -echo "--------------------------" |
| 23 | + sed 's~DOCKER_REGISTRY_IP_PLACEHOLDER~'"$REGISTRY_URL"'~' >> config/jenkins/gen/k8s-jenkins-deployment.yml |
| 24 | + |
| 25 | +kubectl apply -f config/jenkins/k8s-jenkins-pvcs.yml |
| 26 | +verify_kubectl $? "Creating persistent volume claim for jenkins failed." |
| 27 | + |
| 28 | +kubectl apply -f config/jenkins/gen/k8s-jenkins-deployment.yml |
| 29 | +verify_kubectl $? "Creating deployment for jenkins failed." |
| 30 | + |
| 31 | +kubectl apply -f config/jenkins/k8s-jenkins-rbac.yml |
| 32 | +verify_kubectl $? "Creating cluster role binding for jenkins failed." |
| 33 | + |
| 34 | +kubectl apply -f config/jenkins/k8s-jenkins-service-entry.yml |
| 35 | +verify_kubectl $? "Creating service entries for jenkins failed." |
| 36 | + |
| 37 | +wait_for_deployment_in_namespace "jenkins" "keptn" |
| 38 | + |
| 39 | +echo "Wait 100s for Jenkins..." |
| 40 | +sleep 100 |
| 41 | + |
| 42 | +JENKINS_URL="jenkins.keptn.$GATEWAY.xip.io" |
| 43 | + |
| 44 | +# Configure Jenkins with GitHub credentials |
| 45 | +RETRY=0; RETRY_MAX=12; |
| 46 | + |
| 47 | +while [[ $RETRY -lt $RETRY_MAX ]]; do |
| 48 | + curl -X POST http://$JENKINS_URL/credentials/store/system/domain/_/createCredentials \ |
| 49 | + --user $JENKINS_USER:$JENKINS_PASSWORD \ |
| 50 | + --data-urlencode 'json={ |
| 51 | + "": "0", |
| 52 | + "credentials": { |
| 53 | + "scope": "GLOBAL", |
| 54 | + "id": "git-credentials-acm", |
| 55 | + "username": "'$GITHUB_USER_NAME'", |
| 56 | + "password": "'$GITHUB_PERSONAL_ACCESS_TOKEN'", |
| 57 | + "description": "Token used by Jenkins to access the GitHub repositories", |
| 58 | + "$class": "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl" |
| 59 | + } |
| 60 | + }' |
| 61 | + |
| 62 | + if [[ $? == '0' ]] |
| 63 | + then |
| 64 | + print_debug "Git credentials in Jenkins created." |
| 65 | + break |
| 66 | + fi |
| 67 | + RETRY=$[$RETRY+1] |
| 68 | + print_debug "Retry: ${RETRY}/${RETRY_MAX} - Wait 10s for creating git credentials in Jenkins ..." |
| 69 | + sleep 10 |
| 70 | +done |
| 71 | + |
| 72 | +if [[ $RETRY == $RETRY_MAX ]]; then |
| 73 | + print_error "Git credentials could not be created in Jenkins." |
| 74 | + exit 1 |
| 75 | +fi |
71 | 76 |
|
72 | 77 | # Create secret and deploy jenkins-service
|
73 | 78 | kubectl create secret generic -n keptn jenkins-secret --from-literal=jenkinsurl="jenkins.keptn.svc.cluster.local" --from-literal=user="$JENKINS_USER" --from-literal=password="$JENKINS_PASSWORD"
|
| 79 | +verify_kubectl $? "Creating secret for jenkins-service failed." |
74 | 80 |
|
75 | 81 | kubectl delete -f config/service/service.yaml --ignore-not-found
|
76 | 82 | kubectl apply -f config/service/service.yaml
|
| 83 | +verify_kubectl $? "Deploying jenkins-service failed." |
77 | 84 |
|
78 | 85 | # Deploy Tiller for Helm
|
79 |
| -kubectl -n kube-system create serviceaccount tiller |
| 86 | +kubectl create serviceaccount tiller -n kube-system |
| 87 | +verify_kubectl $? "Creating service account for tiller in namespace kube-system failed." |
| 88 | + |
80 | 89 | kubectl create clusterrolebinding tiller --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
|
| 90 | +verify_kubectl $? "Creating cluster role binding for tiller failed." |
| 91 | + |
81 | 92 | helm init --service-account tiller
|
| 93 | +verify_install_step $? "Helm init failed." |
0 commit comments