forked from tekliner/rabbitmq-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
109 lines (106 loc) · 3.95 KB
/
Jenkinsfile
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
node {
checkout scm
def branch = env.BRANCH_NAME.toLowerCase()
def registry = "716309063777.dkr.ecr.us-east-1.amazonaws.com"
def build = env.BUILD_NUMBER
def image
stage("Build image") {
sh 'docker build -t rabbitmq-operator .'
image = docker.image("rabbitmq-operator")
}
stage("Push image") {
docker.withRegistry("https://"+registry+"/", 'ecr:us-east-1:3c5c323b-afed-4bf0-ae1a-3b19d1c904fe') {
image.push("${branch}-${build}")
}
}
// check branch and select cluster to deploy
if (branch == 'master') {
stage ('Wait for confirmation of build promotion') {
input message: 'Is this build ready for production?', submitter: 'tekliner'
}
stage ('Deploy to production') {
writeFile file: 'operator.yaml', text: """
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: rabbitmq-operator
spec:
replicas: 1
selector:
matchLabels:
app: rabbitmq-operator
template:
metadata:
labels:
app: rabbitmq-operator
spec:
serviceAccountName: rabbitmq-operator
containers:
- name: rabbitmq-operator
image: 716309063777.dkr.ecr.us-east-1.amazonaws.com/rabbitmq-operator:${branch}-${build}
command:
- rabbitmq-operator
imagePullPolicy: Always
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: OPERATOR_NAME
value: "rabbitmq-operator"
- name: WATCH_NAMESPACE
value: ""
"""
archiveArtifacts: 'operator.yaml'
sh "kubectl apply -f operator.yaml -n messaging"
sh "kubectl apply -f deploy/deploy-operator-default/clusterrole.yaml"
}
} else {
// deploy PR to sandbox
stage ('Deploy to sandbox') {
writeFile file: 'operator.yaml', text: """
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: rabbitmq-operator
spec:
replicas: 1
selector:
matchLabels:
app: rabbitmq-operator
template:
metadata:
labels:
app: rabbitmq-operator
spec:
serviceAccountName: rabbitmq-operator
containers:
- name: rabbitmq-operator
image: 716309063777.dkr.ecr.us-east-1.amazonaws.com/rabbitmq-operator:${branch}-${build}
command:
- rabbitmq-operator
imagePullPolicy: Always
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: OPERATOR_NAME
value: "rabbitmq-operator"
- name: WATCH_NAMESPACE
value: "rabbitmq-operator-${branch}"
"""
archiveArtifacts: 'operator.yaml'
// create separated namespace and deploy operator into it
sh "HOME=/root;KUBECONFIG=/root/.kube/sandbox.config kubectl create ns rabbitmq-operator-${branch} || true"
sh "HOME=/root;KUBECONFIG=/root/.kube/sandbox.config kubectl apply -f deploy/deploy-operator-default/service_account.yaml -n rabbitmq-operator-${branch} || true"
sh "HOME=/root;KUBECONFIG=/root/.kube/sandbox.config kubectl apply -f deploy/deploy-operator-default/role_binding.yaml -n rabbitmq-operator-${branch} || true"
sh "HOME=/root;KUBECONFIG=/root/.kube/sandbox.config kubectl apply -f deploy/deploy-operator-default/role.yaml -n rabbitmq-operator-${branch} || true"
sh "HOME=/root;KUBECONFIG=/root/.kube/sandbox.config kubectl apply -f deploy/deploy-operator-default/clusterrole.yaml -n rabbitmq-operator-${branch} || true"
sh "HOME=/root;KUBECONFIG=/root/.kube/sandbox.config kubectl apply -f deploy/deploy-operator-default/clusterrolebinding.yaml -n rabbitmq-operator-${branch} || true"
sh "HOME=/root;KUBECONFIG=/root/.kube/sandbox.config kubectl apply -f operator.yaml -n rabbitmq-operator-${branch} || true"
}
}
}