|
|
@ -1,104 +0,0 @@ |
|
|
|
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 redis-operator .' |
|
|
|
image = docker.image("redis-operator") |
|
|
|
} |
|
|
|
|
|
|
|
stage("Push image") { |
|
|
|
docker.withRegistry("https://"+registry+"/", 'ecr:us-east-1:3c5c323b-afed-4bf0-ae1a-3b19d1c904fe') { |
|
|
|
image.push("${branch}-${build}") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
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/v1 |
|
|
|
kind: Deployment |
|
|
|
metadata: |
|
|
|
name: redis-operator |
|
|
|
spec: |
|
|
|
replicas: 1 |
|
|
|
selector: |
|
|
|
matchLabels: |
|
|
|
name: redis-operator |
|
|
|
template: |
|
|
|
metadata: |
|
|
|
labels: |
|
|
|
name: redis-operator |
|
|
|
spec: |
|
|
|
serviceAccountName: redis-operator |
|
|
|
containers: |
|
|
|
- name: redis-operator |
|
|
|
image: 716309063777.dkr.ecr.us-east-1.amazonaws.com/redis-operator:${branch}-${build} |
|
|
|
command: |
|
|
|
- redis-operator |
|
|
|
imagePullPolicy: Always |
|
|
|
env: |
|
|
|
- name: WATCH_NAMESPACE |
|
|
|
value: "" |
|
|
|
- name: POD_NAME |
|
|
|
valueFrom: |
|
|
|
fieldRef: |
|
|
|
fieldPath: metadata.name |
|
|
|
- name: OPERATOR_NAME |
|
|
|
value: "redis-operator" |
|
|
|
""" |
|
|
|
archiveArtifacts: 'operator.yaml' |
|
|
|
sh "kubectl apply -f operator.yaml -n default" |
|
|
|
} |
|
|
|
} else { |
|
|
|
// deploy PR to sandbox |
|
|
|
stage ('Deploy to sandbox') { |
|
|
|
writeFile file: 'operator.yaml', text: """ |
|
|
|
--- |
|
|
|
apiVersion: apps/v1beta1 |
|
|
|
kind: Deployment |
|
|
|
metadata: |
|
|
|
name: redis-operator |
|
|
|
spec: |
|
|
|
replicas: 1 |
|
|
|
selector: |
|
|
|
matchLabels: |
|
|
|
app: redis-operator |
|
|
|
template: |
|
|
|
metadata: |
|
|
|
labels: |
|
|
|
app: redis-operator |
|
|
|
spec: |
|
|
|
serviceAccountName: redis-operator |
|
|
|
containers: |
|
|
|
- name: redis-operator |
|
|
|
image: 716309063777.dkr.ecr.us-east-1.amazonaws.com/redis-operator:${branch}-${build} |
|
|
|
command: |
|
|
|
- redis-operator |
|
|
|
imagePullPolicy: Always |
|
|
|
env: |
|
|
|
- name: POD_NAME |
|
|
|
valueFrom: |
|
|
|
fieldRef: |
|
|
|
fieldPath: metadata.name |
|
|
|
- name: OPERATOR_NAME |
|
|
|
value: "redis-operator" |
|
|
|
- name: WATCH_NAMESPACE |
|
|
|
value: "redis-operator-${branch}" |
|
|
|
""" |
|
|
|
archiveArtifacts: 'operator.yaml' |
|
|
|
// create separated namespace and deploy operator into it |
|
|
|
sh "HOME=/root;KUBECONFIG=/root/.kube/sandbox.config kubectl create ns redis-operator-${branch} || true" |
|
|
|
sh "HOME=/root;KUBECONFIG=/root/.kube/sandbox.config kubectl apply -f deploy/service_account.yaml -n redis-operator-${branch} || true" |
|
|
|
sh "HOME=/root;KUBECONFIG=/root/.kube/sandbox.config kubectl apply -f deploy/role_binding_sandbox.yaml -n redis-operator-${branch} || true" |
|
|
|
sh "HOME=/root;KUBECONFIG=/root/.kube/sandbox.config kubectl apply -f operator.yaml -n redis-operator-${branch} || true" |
|
|
|
} |
|
|
|
} |
|
|
|
} |