forked from kubernetes/ingress-nginx
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathJenkinsfile
120 lines (119 loc) · 3.31 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
110
111
112
113
114
115
116
117
118
119
120
@Library('jenkins.shared.library') _
pipeline {
agent {
label 'ubuntu_docker_label'
}
tools {
go "Go 1.15"
}
options {
checkoutToSubdirectory('src/github.com/infobloxopen/ingress-nginx')
}
environment {
DIRECTORY = "src/github.com/infobloxopen/ingress-nginx"
GIT_VERSION = sh(script: "cd ${DIRECTORY} && git describe --always --long --tags --match 'controller-*' | sed s/controller-//",
returnStdout: true).trim()
TAG = "${env.GIT_VERSION}-j${env.BUILD_NUMBER}-nginx"
REGISTRY = 'infoblox'
IMAGE_NAME = 'nginx-fips'
PLATFORMS = 'linux/amd64'
BUILDX_PLATFORMS = 'linux/amd64'
ARCH = 'amd64'
BASE_IMAGE = "${REGISTRY}/${env.IMAGE_NAME}:${TAG}"
DOCKER_CLI_EXPERIMENTAL = 'enabled'
GOPATH = "$WORKSPACE"
DEBUG=1
}
stages {
stage("Setup docker-ce") {
when {
expression {
DOCKER_VERSION = sh(returnStdout: true, script: "docker -v | awk -F\"[ ,]+\" '/version/ {print \$3}'").trim()
DOCKER_VERSION < '19.03.0'
}
}
steps {
sh "curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -"
sh 'sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"'
sh "sudo apt-get update"
sh 'sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce'
}
}
stage("Setup") {
steps {
sh "rm -f $DIRECTORY/images.list"
prepareBuild()
}
}
stage("Build NGINX Image") {
steps {
dir("$DIRECTORY/images/nginx") {
sh "make build"
sh "make fips-test"
}
}
}
stage("Push NGINX Image") {
steps {
withDockerRegistry([credentialsId: "${env.JENKINS_DOCKER_CRED_ID}", url: ""]) {
dir("$DIRECTORY/images/nginx") {
sh "make push"
}
}
dir("$DIRECTORY") {
sh 'echo ${REGISTRY}/${IMAGE_NAME}:${TAG} >> images.list'
}
}
}
stage("Ingress Unit Tests") {
steps {
withEnv(["USER=root"]) {
dir("$DIRECTORY") {
// tests must be run by privileged user
// issue in v0.49.x ?
sh "make test"
sh "sudo rm -rf .cache .modcache"
}
}
}
}
stage("Build Ingress Image") {
steps {
withEnv(["TAG=${env.GIT_VERSION}-j${env.BUILD_NUMBER}-ingress", "PLATFORMS=amd64"]) {
dir("$DIRECTORY") {
sh "make build"
sh "make image"
}
}
}
}
stage("Push Ingress Image") {
steps {
withEnv(["TAG=${env.GIT_VERSION}-j${env.BUILD_NUMBER}-ingress", "PLATFORMS=amd64"]) {
withDockerRegistry([credentialsId: "${env.JENKINS_DOCKER_CRED_ID}", url: ""]) {
dir("$DIRECTORY") {
sh "make release"
sh 'echo ${REGISTRY}/${IMAGE_NAME}:${TAG} >> images.list'
}
}
}
}
}
}
post {
success {
// finalizeBuild is one of the Secure CICD helper methods
dir("$DIRECTORY") {
sh "touch images.list"
finalizeBuild(readFile(file: 'images.list'))
}
}
cleanup {
dir("$DIRECTORY") {
sh "make clean || true"
sh "rm -f images.list"
}
cleanWs()
}
}
}