-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
88 lines (74 loc) · 2.37 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
pipeline {
agent {
kubernetes {
yamlFile 'jenkins-containers.yaml'
}
}
environment {
APP_NAME = "flask-mysql-example"
GIT_REPO = "[email protected]:SyracuseUniversity/flask-mysql-example.git"
RELEASE = "1.0"
IMAGE_REPO = "harbor.ischool.syr.edu"
IMAGE_GROUP = "examples"
IMAGE_NAME = "${IMAGE_REPO}" + "/" + "${IMAGE_GROUP}" + "/" + "${APP_NAME}"
IMAGE_TAG = "${RELEASE}.${BUILD_NUMBER}"
}
stages {
stage("Cleanup Workspace") {
steps {
cleanWs()
}
}
stage("Checkout from SCM"){
steps {
git branch: 'main', credentialsId: "${APP_NAME}-key", url: "${GIT_REPO}"
}
}
stage('Build & Push with Kaniko') {
steps {
container(name: 'kaniko', shell: '/busybox/sh') {
sh '''#!/busybox/sh
# push build number to app
echo ${IMAGE_TAG} > `pwd`/app/version.txt
# build container image and ship
/kaniko/executor --dockerfile `pwd`/Dockerfile --context `pwd` --destination=${IMAGE_NAME}:${IMAGE_TAG} --destination=${IMAGE_NAME}:latest
'''
}
}
}
stage("Cleanup Workspace Again") {
steps {
cleanWs()
}
}
stage('update k8s deployment manifest') {
environment {
MANIFEST_REPO = "[email protected]:SyracuseUniversity/flask-mysql-manifests-example.git"
DEPLOYMENT_FILE = "app_deployment.yaml"
}
steps {
container(name: 'git', shell: '/bin/sh') {
sh '''#!/bin/sh
# set up ssh key and github hostkey
mkdir ~/.ssh
chmod 700 ~/.ssh
cp /keys/id_rsa ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H github.com >> ~/.ssh/known_hosts
# clone repo
git clone $MANIFEST_REPO `pwd`/manifests
cd `pwd`/manifests
# update build tag
yq eval ".spec.template.spec.containers[0].image = \\"${IMAGE_NAME}:${IMAGE_TAG}\\"" -i `pwd`/${DEPLOYMENT_FILE}
# push changes
git config user.email "[email protected]"
git config user.name "iSchool Jenkins"
git add .
git commit -m "build(${APP_NAME}): updated container build tag to ${IMAGE_TAG}"
git push origin main
'''
}
}
}
}
}