-
Notifications
You must be signed in to change notification settings - Fork 6
/
Jenkinsfile
196 lines (192 loc) · 6.67 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
pipeline {
agent none
options {
timeout(time: 20, unit: 'MINUTES')
}
stages {
// uncomment for a one-time action to clear caches in docker volumes
// stage('Clear-volume-cache') {
// agent any
// steps {
// script {
// // sh 'docker volume rm -f phpstan-cache'
// // sh 'docker volume rm -f composer-cache'
// }
// }
// }
// uncomment for a one-time action to clear caches in bind volumes
// stage('Clear-bind-cache') {
// agent {
// docker {
// image 'library/alpine:latest'
// args '--user root:root --volume "/:/realroot" '
// }
// }
// steps {
// script {
// cleanWs()
// sh 'rm -rf /tmp/gomod'
// }
// }
// }
stage('Go build x64') {
agent {
docker {
image 'golang:1.21.0-bullseye'
args "--volume /tmp/gomod:/go/pkg/mod --user root:root"
}
}
steps {
script {
// get owner UID of working directory to run commands as that user
def userId = sh(script: "stat -c '%u' .", returnStdout: true).trim()
sh "useradd --create-home --uid ${userId} jenkins"
sh "chown -R jenkins /go/pkg/mod"
sh 'su jenkins -c "make build-x64"'
stash(name: "build-x64", includes: "build/")
}
}
post {
always {
cleanWs()
}
}
}
stage('Go build arm64') {
agent {
dockerfile {
dir 'docker/go-docker'
args '--volume /var/run/docker.sock:/var/run/docker.sock --user root:root'
}
}
steps {
script {
// get owner UID of working directory to run commands as that user
def dockerGroupId = sh(script: "stat -c '%g' /var/run/docker.sock", returnStdout: true).trim()
def userId = sh(script: "stat -c '%u' .", returnStdout: true).trim()
// set group id of docker group to that of the host so we may access /var/run/docker.sock
sh "groupmod --gid ${dockerGroupId} docker"
sh "useradd --create-home --gid ${dockerGroupId} --uid ${userId} jenkins"
sh "newgrp docker"
sh 'su jenkins -c "make build-arm64"'
stash(name: "build-arm64", includes: "build/libuplink-aarch64-linux.so")
}
}
post {
always {
cleanWs()
}
}
}
stage('Go build windows') {
agent {
dockerfile {
dir 'docker/go-docker'
args '--volume /var/run/docker.sock:/var/run/docker.sock --user root:root'
}
}
steps {
script {
// get owner UID of working directory to run commands as that user
def dockerGroupId = sh(script: "stat -c '%g' /var/run/docker.sock", returnStdout: true).trim()
def userId = sh(script: "stat -c '%u' .", returnStdout: true).trim()
// set group id of docker group to that of the host so we may access /var/run/docker.sock
sh "groupmod --gid ${dockerGroupId} docker"
sh "useradd --create-home --gid ${dockerGroupId} --uid ${userId} jenkins"
sh "newgrp docker"
sh 'su jenkins -c "make build-windows"'
stash(name: "build-windows", includes: "build/libuplink-amd64-windows_nt.dll")
}
}
post {
always {
cleanWs()
}
}
}
stage('Release') {
agent {
dockerfile {
dir 'docker/zip'
}
}
steps {
unstash "build-x64"
unstash "build-arm64"
unstash "build-windows"
sh "make release.zip"
archiveArtifacts "release.zip"
}
post {
always {
cleanWs()
}
}
}
stage('Composer') {
agent {
docker {
image 'composer:2.3.8'
args '--mount type=volume,source=composer-cache2,destination=/root/.composer/cache '
}
}
steps {
sh 'composer install --ignore-platform-reqs'
stash(name: "vendor", includes: "vendor/")
}
post {
always {
cleanWs()
}
}
}
stage('PHPStan') {
agent {
docker {
image 'ghcr.io/phpstan/phpstan:1.8.1'
args '--mount type=volume,source=phpstan-cache,destination=/tmp/phpstan ' +
'--user root:root ' +
"--entrypoint='' "
}
}
steps {
unstash "vendor"
sh 'phpstan analyse'
}
post {
always {
cleanWs()
}
}
}
stage('PHPUnit') {
agent {
dockerfile {
dir 'docker/phpunit'
args '--user root:root '
}
}
steps {
unstash "vendor"
unstash "build-x64"
sh 'service postgresql start'
sh '''su -s /bin/bash -c "psql -U postgres -c 'create database teststorj;'" postgres'''
sh 'PATH="/root/go/bin:$PATH" && storj-sim network setup --postgres=postgres://postgres@localhost/teststorj?sslmode=disable'
// see https://github.com/storj/storj/wiki/Test-network#running-tests
sh 'PATH="/root/go/bin:$PATH" && storj-sim network test ./vendor/bin/phpunit test/'
}
post {
always {
cleanWs()
}
}
}
}
post {
always {
node(null) {
cleanWs()
}
}
}
}