forked from komarserjio/notejam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
68 lines (65 loc) · 2.04 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
def label = "worker-${UUID.randomUUID().toString()}"
def gitCommit = ""
podTemplate(label: label, containers: [
containerTemplate(name: 'docker', image: 'docker', command: 'cat', ttyEnabled: true),
],
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock')
]) {
node(label) {
def myRepo = checkout scm
gitCommit = myRepo.GIT_COMMIT
def gitBranch = myRepo.GIT_BRANCH
stage('Set Env') {
try {
container('docker') {
sh """
pwd
echo "GIT_BRANCH=${gitBranch}" >> /etc/environment
echo "GIT_COMMIT=${gitCommit}" >> /etc/environment
"""
}
}
catch (enverror) {
println "Failed to test - ${currentBuild.fullDisplayName}"
throw(enverror)
}
}
stage('Build') {
container('docker') {
sh """
cd notejam;
docker build . -t docker-registry:31000/notejam:${gitCommit};
docker push docker-registry:31000/notejam:${gitCommit};
"""
}
}
}
}
podTemplate(label: label, containers: [
containerTemplate(name: 'app', image: "docker-registry:31000/notejam:${gitCommit}", command: 'cat', ttyEnabled: true),
containerTemplate(name: 'mariadb', image: 'mariadb', ttyEnabled: true,
envVars: [envVar(key: 'MYSQL_ALLOW_EMPTY_PASSWORD', value: 'yes')],
ports: [portMapping(name: 'mysql', containerPort: 3306, hostPort: 3306)]
),
containerTemplate(name: 'kubectl', image: 'lachlanevenson/k8s-kubectl:v1.8.8', command: 'cat', ttyEnabled: true),
],
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock')
]) {
node(label) {
stage('Test Image') {
container('app') {
sh """
cd /app
bash test.sh
"""
}
}
stage('Deploy Image to production') {
container('kubectl') {
sh "kubectl set image deployment notejam-app notejam-app=docker-registry:31000/notejam:${gitCommit}"
}
}
}
}