This repository has been archived by the owner on May 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Jenkinsfile
127 lines (126 loc) · 3.46 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
121
122
123
124
125
126
127
pipeline {
agent {
label 'docker-multiarch-big'
}
options {
buildDiscarder(logRotator(numToKeepStr: '5'))
disableConcurrentBuilds()
ansiColor('xterm')
}
environment {
IMAGE = 'alpine-nginx-full'
BUILDX_NAME = "${IMAGE}_${GIT_BRANCH}"
BRANCH_LOWER = "${BRANCH_NAME.toLowerCase().replaceAll('/', '-')}"
// Software versions; OpenResty does not support Lua >= 5.2
OPENRESTY_VERSION = '1.19.3.1'
LUA_VERSION = '5.1.5'
LUAROCKS_VERSION = '3.3.1'
}
stages {
stage('Environment') {
parallel {
stage('Master') {
when {
branch 'master'
}
steps {
script {
env.BASE_TAG = 'latest'
env.BUILDX_PUSH_TAGS = "-t docker.io/jc21/${IMAGE}:${BASE_TAG}"
env.BUILDX_PUSH_TAGS_NODE = "-t docker.io/jc21/${IMAGE}:node"
env.BUILDX_PUSH_TAGS_GOLANG = "-t docker.io/jc21/${IMAGE}:golang"
}
}
}
stage('Other') {
when {
not {
branch 'master'
}
}
steps {
script {
// Defaults to the Branch name, which is applies to all branches AND pr's
env.BASE_TAG = "github-${BRANCH_LOWER}"
env.BUILDX_PUSH_TAGS = "-t docker.io/jc21/${IMAGE}:${BASE_TAG}"
env.BUILDX_PUSH_TAGS_NODE = "${BUILDX_PUSH_TAGS}-node"
env.BUILDX_PUSH_TAGS_GOLANG = "${BUILDX_PUSH_TAGS}-golang"
}
}
}
}
}
stage('Base Build') {
environment {
BUILDX_NAME = "${IMAGE}_${GIT_BRANCH}_base"
}
steps {
withCredentials([usernamePassword(credentialsId: 'jc21-dockerhub', passwordVariable: 'DOCKER_PASS', usernameVariable: 'DOCKER_USER')]) {
sh 'docker login -u "${DOCKER_USER}" -p "${DOCKER_PASS}"'
sh "./scripts/buildx --push ${BUILDX_PUSH_TAGS}"
}
}
}
stage('Other Builds') {
parallel {
stage('Golang') {
environment {
BUILDX_NAME = "${IMAGE}_${GIT_BRANCH}_golang"
}
steps {
sh 'sed -i "s/BASE_TAG/${BASE_TAG}/g" Dockerfile.golang'
withCredentials([usernamePassword(credentialsId: 'jc21-dockerhub', passwordVariable: 'DOCKER_PASS', usernameVariable: 'DOCKER_USER')]) {
sh 'docker login -u "${DOCKER_USER}" -p "${DOCKER_PASS}"'
sh "./scripts/buildx --push -f Dockerfile.golang ${BUILDX_PUSH_TAGS_GOLANG}"
}
}
}
stage('Node') {
environment {
BUILDX_NAME = "${IMAGE}_${GIT_BRANCH}_node"
}
steps {
sh 'sed -i "s/BASE_TAG/${BASE_TAG}/g" Dockerfile.node'
withCredentials([usernamePassword(credentialsId: 'jc21-dockerhub', passwordVariable: 'DOCKER_PASS', usernameVariable: 'DOCKER_USER')]) {
sh 'docker login -u "${DOCKER_USER}" -p "${DOCKER_PASS}"'
sh "./scripts/buildx --push -f Dockerfile.node ${BUILDX_PUSH_TAGS_NODE}"
}
}
}
}
}
stage('PR Comment') {
when {
allOf {
changeRequest()
not {
equals expected: 'UNSTABLE', actual: currentBuild.result
}
}
}
steps {
script {
def comment = pullRequest.comment("""Docker Image for build ${BUILD_NUMBER} is available on [DockerHub](https://cloud.docker.com/repository/docker/jc21/${IMAGE}) as:
- `jc21/${IMAGE}:github-${BRANCH_LOWER}`
- `jc21/${IMAGE}:github-${BRANCH_LOWER}-node`
- `jc21/${IMAGE}:github-${BRANCH_LOWER}-golang`
""")
}
}
}
}
post {
success {
juxtapose event: 'success'
sh 'figlet "SUCCESS"'
}
failure {
juxtapose event: 'failure'
sh 'figlet "FAILURE"'
}
unstable {
juxtapose event: 'unstable'
sh 'figlet "UNSTABLE"'
}
}
}