-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
74 lines (73 loc) · 2.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
pipeline {
agent any
options {
disableConcurrentBuilds()
}
stages {
stage('Checkout'){
steps {
checkout scm
}
}
stage('Build') {
steps {
script {
env.REAL_PWD = getDockerPWD();
sh 'docker run --rm -w /app -v $REAL_PWD:/app golang:alpine go build'
}
}
}
stage('Test') {
steps {
script {
env.REAL_PWD = getDockerPWD();
sh 'docker run --rm -w /app -v $REAL_PWD:/app golang:alpine go test ./...'
}
}
}
stage('Prep buildx') {
when { branch 'master' }
steps {
script {
env.BUILDX_BUILDER = getBuildxBuilder();
}
}
}
stage('Dockerhub login') {
when { branch 'master' }
steps {
withCredentials([usernamePassword(credentialsId: 'dockerhub', usernameVariable: 'DOCKERHUB_CREDENTIALS_USR', passwordVariable: 'DOCKERHUB_CREDENTIALS_PSW')]) {
sh 'docker login -u $DOCKERHUB_CREDENTIALS_USR -p "$DOCKERHUB_CREDENTIALS_PSW"'
}
}
}
stage('Build Server Docker Image') {
when { branch 'master' }
steps {
sh """
docker buildx build --pull --builder \$BUILDX_BUILDER --target server --platform linux/arm64,linux/amd64 -t nbr23/rss-banquet:server-latest -t nbr23/rss-banquet:server-`git rev-parse --short HEAD` --push .
"""
}
}
stage('Build Nginx Server Docker Image') {
when { branch 'master' }
steps {
sh """
docker buildx build --pull --builder \$BUILDX_BUILDER --target nginx --platform linux/arm64,linux/amd64 -t nbr23/rss-banquet:server-nginx-latest -t nbr23/rss-banquet:server-nginx-`git rev-parse --short HEAD` --push .
"""
}
}
stage('Sync github repos') {
when { branch 'master' }
steps {
syncRemoteBranch('[email protected]:nbr23/rss-banquet.git', 'master')
}
}
}
post {
always {
sh 'docker buildx stop $BUILDX_BUILDER || true'
sh 'docker buildx rm $BUILDX_BUILDER || true'
}
}
}