-
Notifications
You must be signed in to change notification settings - Fork 3
/
Jenkinsfile.img
85 lines (84 loc) · 2.85 KB
/
Jenkinsfile.img
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
pipeline {
agent {
kubernetes {
// Use Kubernetes to build our images.
// Use Img instead of docker so we can build images without access to docker.
// Note that you must have the secret docker-credentials in your namespace.
// Note2 you need to run a privileged container which is less insecure than exposing your docke socket.
defaultContainer 'img'
yaml """
kind: Pod
metadata:
annotations:
container.apparmor.security.beta.kubernetes.io/img: unconfined
container.seccomp.security.alpha.kubernetes.io/img: unconfined
spec:
containers:
- name: img
image: docker.io/ssilbory/img-builder:latest
securityContext:
privileged: true
imagePullPolicy: Always
command:
- sleep
args:
- 9999999
volumeMounts:
- name: jenkins-docker-cfg
mountPath: /root/.docker
volumes:
- name: jenkins-docker-cfg
projected:
sources:
- secret:
name: docker-credentials
items:
- key: .dockerconfigjson
path: config.json
"""
}
}
environment {
// Grab our Nirmata Token from Jenkins creds
NIRMATA_TOKEN = credentials('NIRMATA_TOKEN')
// This needs to be changed if you are using Nirmata PE
NIRMATA_URL = 'https://nirmata.io'
// This should be your locally cached copy
NCTL_URL = 'https://nirmata-downloads.s3.us-east-2.amazonaws.com/nctl/nctl_3.1.0-rc2/nctl_3.1.0-rc2_linux_64-bit.zip'
// The rest should changed to your app and repo.
DOCKER_REPO = 'ssilbory/alpine-tomcat'
APP_NAME = 'alpine-tomcat'
ENV_NAME = 'tomcat'
YAML_FILE = 'tomcat.yaml'
}
stages {
stage('Build with Img') {
// You might want to break this into multiple stages
steps {
// Get our git repo
git 'https://github.com/silborynirmata/jekins-example.git'
// Build container
sh "img build . -t ${DOCKER_REPO}:${env.BUILD_ID}"
// You can also auth like this instead of the docker secret.
// sh "img login -u $REPO_USER -p REPO_PASSWORD"
sh "img push ${DOCKER_REPO}:${env.BUILD_ID}"
// Use our build tag in K8
sh "sed s/:latest/:${env.BUILD_ID}/ -i ${YAML_FILE}"
// This requires that the environment and application exists.
sh '''if command -v nctl ;then
nctl environments apps apply ${APP_NAME} -e ${ENV_NAME} -f ${YAML_FILE}
else
if [ -f nctl ];then
chmod +x nctl
else
wget -O nctl.zip ${NCTL_URL}
unzip -o nctl.zip
chmod 500 nctl
fi
# Your app must exist in Nirmata
./nctl environments apps apply ${APP_NAME} -e ${ENV_NAME} -f ${YAML_FILE}
fi'''
}
}
}
}