-
Notifications
You must be signed in to change notification settings - Fork 63
/
Jenkinsfile
127 lines (118 loc) · 5.55 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 'linux-x64'
}
environment {
APP_VERSION = 'v0.6.2'
HS_VERSION = "v0.22.1" // Version of Headscale this is compatible with
BUILD_DATE = ''
BUILDER_NAME = "multiarch-${env.BUILD_TAG}"
DOCKERHUB_CRED = credentials('dockerhub-ifargle-pat')
GHCR_URL = "https://ghcr.io/"
GHCR_CRED = credentials('github-ifargle-pat')
SYSCTL_URL = "https://git.sysctl.io/"
SYSCTL_CRED = credentials('gitea-jenkins-pat')
}
options {
buildDiscarder(logRotator(numToKeepStr: '100', artifactNumToKeepStr: '20'))
timestamps()
}
stages {
stage('Build ENV') {
steps {
sh 'printenv'
script { BUILD_DATE = java.time.LocalDate.now() }
sh """
# Create the builder:
docker buildx create --name $BUILDER_NAME --driver-opt=image=moby/buildkit
docker buildx use $BUILDER_NAME
docker buildx inspect --bootstrap
docker buildx ls
"""
sh 'docker login -u ${DOCKERHUB_CRED_USR} -p ${DOCKERHUB_CRED_PSW}'
sh 'docker login -u ${GHCR_CRED_USR} -p ${GHCR_CRED_PSW} $GHCR_URL'
sh 'docker login -u ${SYSCTL_CRED_USR} -p ${SYSCTL_CRED_PSW} $SYSCTL_URL'
}
}
stage('Build') {
options { timeout(time: 8, unit: 'HOURS') }
steps {
script {
if (env.BRANCH_NAME == 'main') {
sh """
docker buildx build . \
--tag git.sysctl.io/albert/headscale-webui:latest \
--tag registry-1.docker.io/ifargle/headscale-webui:latest \
--tag ghcr.io/ifargle/headscale-webui:latest \
--tag git.sysctl.io/albert/headscale-webui:${APP_VERSION} \
--tag registry-1.docker.io/ifargle/headscale-webui:${APP_VERSION} \
--tag ghcr.io/ifargle/headscale-webui:${APP_VERSION} \
--build-arg GIT_COMMIT_ARG=${env.GIT_COMMIT} \
--build-arg GIT_BRANCH_ARG=${env.BRANCH_NAME} \
--build-arg APP_VERSION_ARG=${APP_VERSION} \
--build-arg BUILD_DATE_ARG=${BUILD_DATE} \
--build-arg HS_VERSION_ARG=${HS_VERSION} \
--label \"GIT_COMMIT=${env.GIT_COMMIT}\" \
--platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 \
--push
"""
} else { // If I'm just testing, I don't need to build for ARM
sh """
docker buildx build . \
--tag git.sysctl.io/albert/headscale-webui:testing \
--tag ghcr.io/ifargle/headscale-webui:testing \
--tag git.sysctl.io/albert/headscale-webui:${env.BRANCH_NAME} \
--tag ghcr.io/ifargle/headscale-webui:${env.BRANCH_NAME} \
--build-arg GIT_COMMIT_ARG=${env.GIT_COMMIT} \
--build-arg GIT_BRANCH_ARG=${env.BRANCH_NAME} \
--build-arg APP_VERSION_ARG=${APP_VERSION} \
--build-arg BUILD_DATE_ARG=${BUILD_DATE} \
--build-arg HS_VERSION_ARG=${HS_VERSION} \
--label \"GIT_COMMIT=${env.GIT_COMMIT}\" \
--platform linux/amd64 \
--push
"""
}
}
}
}
stage('Pull Test') {
steps {
script {
if (env.BRANCH_NAME == 'main') {
sh """
docker pull git.sysctl.io/albert/headscale-webui:latest
docker pull registry-1.docker.io/ifargle/headscale-webui:latest
docker pull ghcr.io/ifargle/headscale-webui:latest
docker pull git.sysctl.io/albert/headscale-webui:${APP_VERSION}
docker pull registry-1.docker.io/ifargle/headscale-webui:${APP_VERSION}
docker pull ghcr.io/ifargle/headscale-webui:${APP_VERSION}
"""
}
else {
sh """
docker pull git.sysctl.io/albert/headscale-webui:testing
docker pull ghcr.io/ifargle/headscale-webui:testing
docker pull git.sysctl.io/albert/headscale-webui:${env.BRANCH_NAME}
docker pull ghcr.io/ifargle/headscale-webui:${env.BRANCH_NAME}
"""
}
}
}
}
}
post {
always {
script {
sh """
docker buildx use default
docker buildx rm $BUILDER_NAME
## Sanity check step
docker buildx ls
docker logout
docker system prune --force
"""
}
}
}
}