| 1 |
GIT_COMMIT_EMAIL = "" |
| 2 |
GIT_COMMIT_HASH = "" |
| 3 |
REGISTRY_URL = "registry.ci.leil.io" |
| 4 |
|
| 5 |
def buildSfstests() { |
| 6 |
sh ''' |
| 7 |
git clone "https://github.com/leil-io/sfstests" |
| 8 |
cd sfstests |
| 9 |
git checkout v0.5.0 |
| 10 |
go build -o $WORKSPACE/sfstests |
| 11 |
''' |
| 12 |
} |
| 13 |
|
| 14 |
def buildImage(imageName) { |
| 15 |
sh """ |
| 16 |
cd $WORKSPACE |
| 17 |
mkdir -p build |
| 18 |
docker buildx build --build-arg BASE_IMAGE=${imageName} --tag saunafs-test:latest -f tests/docker/Dockerfile.test $WORKSPACE |
| 19 |
""" |
| 20 |
} |
| 21 |
|
| 22 |
def pushImage(registryImageName) { |
| 23 |
sh """ |
| 24 |
docker tag saunafs-test:latest ${registryImageName} |
| 25 |
docker push ${registryImageName} |
| 26 |
""" |
| 27 |
} |
| 28 |
|
| 29 |
def runSanity() { |
| 30 |
def resultsFile = "test_results_sanity.xml" |
| 31 |
sh """ |
| 32 |
./sfstests/sfstests \ |
| 33 |
--auth /etc/apt/auth.conf.d/ \ |
| 34 |
--workers ${SANITY_WORKERS} \ |
| 35 |
--multiplier ${MACHINE_MULTIPLIER} \ |
| 36 |
--cpus 1 \ |
| 37 |
--xml-path ${resultsFile} |
| 38 |
""" |
| 39 |
publishJunit(resultsFile) |
| 40 |
} |
| 41 |
def runShort() { |
| 42 |
def resultsFile = "test_results_short.xml" |
| 43 |
sh """ |
| 44 |
./sfstests/sfstests \ |
| 45 |
--auth /etc/apt/auth.conf.d/ \ |
| 46 |
--suite ShortSystemTests \ |
| 47 |
--workers ${SHORT_WORKERS} \ |
| 48 |
--multiplier ${MACHINE_MULTIPLIER} \ |
| 49 |
--cpus 2 \ |
| 50 |
--xml-path ${resultsFile} |
| 51 |
""" |
| 52 |
publishJunit(resultsFile) |
| 53 |
} |
| 54 |
def runMachine() { |
| 55 |
def resultsFile = "test_results_machine.xml" |
| 56 |
sh """ ./sfstests/sfstests \ |
| 57 |
--auth /etc/apt/auth.conf.d/ \ |
| 58 |
--suite SingleMachineTests \ |
| 59 |
--workers 1 \ |
| 60 |
--skip-on-fail \ |
| 61 |
--multiplier ${MACHINE_MULTIPLIER} \ |
| 62 |
--xml-path ${resultsFile} |
| 63 |
""" |
| 64 |
publishJunit(resultsFile) |
| 65 |
} |
| 66 |
def runLong() { |
| 67 |
def resultsFile = "test_results_long.xml" |
| 68 |
sh """ ./sfstests/sfstests \ |
| 69 |
--auth /etc/apt/auth.conf.d/ \ |
| 70 |
--workers ${LONG_WORKERS} \ |
| 71 |
--suite LongSystemTests \ |
| 72 |
--multiplier ${MACHINE_MULTIPLIER} \ |
| 73 |
--skip-on-fail \ |
| 74 |
--cpus 2 \ |
| 75 |
--xml-path ${resultsFile} |
| 76 |
""" |
| 77 |
publishJunit(resultsFile) |
| 78 |
} |
| 79 |
|
| 80 |
def publishJunit(resultsFile) { |
| 81 |
junit( |
| 82 |
skipMarkingBuildUnstable: false, |
| 83 |
testResults: resultsFile, |
| 84 |
) |
| 85 |
} |
| 86 |
|
| 87 |
def slackBadMessage(channelMsg, userMsg) { |
| 88 |
if (env.BRANCH_NAME == 'dev') { |
| 89 |
slackSend(color: "danger", message: "<$BUILD_URL|$channelMsg>") |
| 90 |
} else { |
| 91 |
GIT_COMMIT_EMAIL = sh( |
| 92 |
script: 'git --no-pager show -s --format="%ae"', |
| 93 |
returnStdout: true |
| 94 |
).trim() |
| 95 |
def userId = slackUserIdFromEmail(GIT_COMMIT_EMAIL) |
| 96 |
if (userId?.trim()) { |
| 97 |
slackSend( |
| 98 |
color: "warning", |
| 99 |
channel: "$userId", |
| 100 |
message: "<$BUILD_URL|$userMsg>" |
| 101 |
) |
| 102 |
} else { |
| 103 |
echo "Failed to retrieve Slack user ID for email: ${GIT_COMMIT_EMAIL}" |
| 104 |
} |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
def slackGoodMessage(userMsg) { |
| 109 |
if (env.BRANCH_NAME == 'dev') { |
| 110 |
// No need to alert if everything works :) |
| 111 |
return |
| 112 |
} |
| 113 |
// We still want to alert developers that a pipeline passed |
| 114 |
def userId = slackUserIdFromEmail(GIT_COMMIT_EMAIL) |
| 115 |
if (userId?.trim()) { |
| 116 |
slackSend( |
| 117 |
color: "good", |
| 118 |
channel: "$userId", |
| 119 |
message: "<$BUILD_URL|$userMsg>" |
| 120 |
) |
| 121 |
} else { |
| 122 |
echo "Failed to retrieve Slack user ID for email: ${GIT_COMMIT_EMAIL}" |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
if(env.BRANCH_NAME?.equals("dev")) { |
| 127 |
properties([disableConcurrentBuilds()]) |
| 128 |
} else { |
| 129 |
properties([disableConcurrentBuilds(abortPrevious: true)]) |
| 130 |
} |
| 131 |
|
| 132 |
pipeline { |
| 133 |
agent none |
| 134 |
|
| 135 |
parameters { |
| 136 |
booleanParam( |
| 137 |
name: 'DEPLOY_PACKAGE_TO_EXPERIMENTAL', |
| 138 |
defaultValue: false, |
| 139 |
description: 'Build and deploy packages to EXPERIMENTAL' |
| 140 |
) |
| 141 |
string( |
| 142 |
name: 'DEBIAN_PACKAGE_REF', |
| 143 |
defaultValue: 'dev', |
| 144 |
description: 'If deploying packages, what leil-io/debian-package reference to use?' |
| 145 |
) |
| 146 |
} |
| 147 |
|
| 148 |
options { |
| 149 |
skipStagesAfterUnstable() |
| 150 |
// TODO: Add more lenient rules for dev |
| 151 |
buildDiscarder(logRotator(artifactDaysToKeepStr: "7", artifactNumToKeepStr: "2")) |
| 152 |
parallelsAlwaysFailFast() |
| 153 |
} |
| 154 |
tools { go '1.22.2' } |
| 155 |
stages { |
| 156 |
stage('Get build metadata') { |
| 157 |
agent {label 'linux'} |
| 158 |
steps { |
| 159 |
checkout scm |
| 160 |
script { |
| 161 |
GIT_COMMIT_EMAIL = sh( |
| 162 |
script: 'git --no-pager show -s --format="%ae"', |
| 163 |
returnStdout: true |
| 164 |
).trim() |
| 165 |
GIT_COMMIT_HASH = sh( |
| 166 |
script: 'git rev-parse HEAD', |
| 167 |
returnStdout: true, |
| 168 |
).trim() |
| 169 |
} |
| 170 |
} |
| 171 |
post { |
| 172 |
cleanup { |
| 173 |
cleanWs(cleanWhenNotBuilt: true, |
| 174 |
deleteDirs: true, |
| 175 |
disableDeferredWipeout: true, |
| 176 |
notFailBuild: true, |
| 177 |
) |
| 178 |
} |
| 179 |
} |
| 180 |
} |
| 181 |
stage('Build and test') { |
| 182 |
parallel { |
| 183 |
stage('Run special tests (Ubuntu 24.04)') { |
| 184 |
agent {label 'unittests'} |
| 185 |
stages { |
| 186 |
stage("Checkout source") { |
| 187 |
steps { |
| 188 |
checkout scm |
| 189 |
} |
| 190 |
} |
| 191 |
stage("Build and unit test") { |
| 192 |
steps { |
| 193 |
sh """ |
| 194 |
export PATH="/usr/lib/ccache:$PATH" |
| 195 |
cd vcpkg |
| 196 |
./bootstrap-vcpkg.sh |
| 197 |
cd .. |
| 198 |
mkdir -p build |
| 199 |
cd build |
| 200 |
nice cmake \ |
| 201 |
-DCMAKE_TOOLCHAIN_FILE="../vcpkg/scripts/buildsystems/vcpkg.cmake" \ |
| 202 |
-DENABLE_CLIENT_LIB=ON \ |
| 203 |
-DENABLE_DOCS=ON \ |
| 204 |
-DENABLE_NFS_GANESHA=ON \ |
| 205 |
-DENABLE_POLONAISE=OFF \ |
| 206 |
-DENABLE_URAFT=ON \ |
| 207 |
-DGSH_CAN_HOST_LOCAL_FS=ON \ |
| 208 |
-DCMAKE_INSTALL_PREFIX="/usr/local/" \ |
| 209 |
-DCMAKE_BUILD_TYPE=RelWithDebInfo \ |
| 210 |
-DENABLE_TESTS=ON \ |
| 211 |
-DCODE_COVERAGE=OFF \ |
| 212 |
-DSAUNAFS_TEST_POINTER_OBFUSCATION=ON \ |
| 213 |
-DENABLE_WERROR=ON \ |
| 214 |
-DENABLE_FOUNDATIONDB=ON \ |
| 215 |
.. |
| 216 |
cd src/unittests |
| 217 |
nice make -j\$((\$(nproc) / 2)) |
| 218 |
# Make sure that failures do NOT fail the pipeline |
| 219 |
sudo systemctl restart foundationdb |
| 220 |
./unittests || true |
| 221 |
""" |
| 222 |
publishJunit("build/src/unittests/*test_detail.xml") |
| 223 |
} |
| 224 |
} |
| 225 |
stage("Build and run rebalancing tests") { |
| 226 |
steps { |
| 227 |
sh """ |
| 228 |
export PATH="/usr/lib/ccache:$PATH" |
| 229 |
cd build |
| 230 |
sudo nice make -j\$((\$(nproc) / 2)) install |
| 231 |
saunafs-tests --gtest_filter="RebalancingTests*" --gtest_output="xml:./rebalance_test_detail.xml" || true |
| 232 |
""" |
| 233 |
publishJunit("build/*test_detail.xml") |
| 234 |
} |
| 235 |
} |
| 236 |
} |
| 237 |
post { |
| 238 |
failure { |
| 239 |
slackBadMessage( |
| 240 |
"Unit tests failed on ${BRANCH_NAME}", |
| 241 |
"Unit tests failed on branch ${BRANCH_NAME}, build number ${BUILD_NUMBER}" |
| 242 |
) |
| 243 |
} |
| 244 |
cleanup { |
| 245 |
sh """ |
| 246 |
sudo chown \$(id -u):\$(id -g) $WORKSPACE -R |
| 247 |
""" |
| 248 |
} |
| 249 |
} |
| 250 |
} |
| 251 |
stage('Build with clang') { |
| 252 |
agent {label 'build'} |
| 253 |
steps { |
| 254 |
checkout scm |
| 255 |
script { |
| 256 |
sh """ |
| 257 |
docker buildx build --tag saunafs-clang-build:latest -f tests/docker/Dockerfile.test $WORKSPACE |
| 258 |
""" |
| 259 |
} |
| 260 |
} |
| 261 |
post { |
| 262 |
failure { |
| 263 |
slackBadMessage( |
| 264 |
"clang failed to build on ${BRANCH_NAME}", |
| 265 |
"clang failed on branch ${BRANCH_NAME}, build number ${BUILD_NUMBER}" |
| 266 |
) |
| 267 |
} |
| 268 |
cleanup { |
| 269 |
cleanWs(cleanWhenNotBuilt: true, |
| 270 |
deleteDirs: true, |
| 271 |
disableDeferredWipeout: true, |
| 272 |
notFailBuild: true, |
| 273 |
) |
| 274 |
sh """ |
| 275 |
docker image rm saunafs-clang-build || true |
| 276 |
""" |
| 277 |
} |
| 278 |
} |
| 279 |
} |
| 280 |
stage('Build Ubuntu 22.04') { |
| 281 |
environment { |
| 282 |
SANITY_WORKERS = "${env.SANITY_WORKERS ?: '4'}" |
| 283 |
SHORT_WORKERS = "${env.SHORT_WORKERS ?: '4'}" |
| 284 |
LONG_WORKERS = "${env.LONG_WORKERS ?: '4'}" |
| 285 |
MACHINE_MULTIPLIER = "${env.MACHINE_MULTIPLIER ?: '5'}" |
| 286 |
REGISTRY_IMAGE_NAME = "${REGISTRY_URL}/ubuntu22.04-saunafs-test:$GIT_COMMIT" |
| 287 |
} |
| 288 |
agent { label "build" } |
| 289 |
stages { |
| 290 |
stage("Checkout source") { |
| 291 |
steps { |
| 292 |
checkout scm |
| 293 |
} |
| 294 |
} |
| 295 |
stage('Build image') { |
| 296 |
steps { |
| 297 |
script { |
| 298 |
buildImage("ubuntu:22.04") |
| 299 |
pushImage(env.REGISTRY_IMAGE_NAME) |
| 300 |
} |
| 301 |
} |
| 302 |
} |
| 303 |
} |
| 304 |
post { |
| 305 |
// Clean after build |
| 306 |
failure { |
| 307 |
slackBadMessage( |
| 308 |
"Ubuntu 22.04 build failed on ${BRANCH_NAME}", |
| 309 |
"Ubuntu 22.04 build failed on branch ${BRANCH_NAME}, build number ${BUILD_NUMBER}" |
| 310 |
) |
| 311 |
} |
| 312 |
cleanup { |
| 313 |
cleanWs(cleanWhenNotBuilt: true, |
| 314 |
deleteDirs: true, |
| 315 |
disableDeferredWipeout: true, |
| 316 |
notFailBuild: true, |
| 317 |
) |
| 318 |
sh """ |
| 319 |
docker image rm ${env.REGISTRY_IMAGE_NAME} || true |
| 320 |
docker image rm saunafs-test:latest || true |
| 321 |
""" |
| 322 |
} |
| 323 |
} |
| 324 |
} |
| 325 |
stage('Build Ubuntu 24.04') { |
| 326 |
agent { label "test && ubuntu-2404" } |
| 327 |
environment { |
| 328 |
SANITY_WORKERS = "${env.SANITY_WORKERS ?: '4'}" |
| 329 |
SHORT_WORKERS = "${env.SHORT_WORKERS ?: '4'}" |
| 330 |
LONG_WORKERS = "${env.LONG_WORKERS ?: '4'}" |
| 331 |
|
| 332 |
MACHINE_MULTIPLIER = "${env.MACHINE_MULTIPLIER ?: '5'}" |
| 333 |
REGISTRY_IMAGE_NAME = "${REGISTRY_URL}/ubuntu24.04-saunafs-test:$GIT_COMMIT" |
| 334 |
} |
| 335 |
stages { |
| 336 |
stage("Checkout source") { |
| 337 |
steps { |
| 338 |
checkout scm |
| 339 |
} |
| 340 |
} |
| 341 |
stage('Build sfstests') { |
| 342 |
steps { |
| 343 |
buildSfstests() |
| 344 |
} |
| 345 |
} |
| 346 |
|
| 347 |
|
| 348 |
stage('Build image') { |
| 349 |
steps { |
| 350 |
script { |
| 351 |
buildImage("ubuntu:24.04") |
| 352 |
pushImage(env.REGISTRY_IMAGE_NAME) |
| 353 |
} |
| 354 |
} |
| 355 |
} |
| 356 |
|
| 357 |
stage('Run Sanity') { |
| 358 |
steps { |
| 359 |
runSanity() |
| 360 |
} |
| 361 |
} |
| 362 |
|
| 363 |
stage('Run short system tests') { |
| 364 |
steps { |
| 365 |
runShort() |
| 366 |
} |
| 367 |
} |
| 368 |
|
| 369 |
stage('Run machine tests') { |
| 370 |
when { |
| 371 |
anyOf { |
| 372 |
branch 'dev' |
| 373 |
branch 'gh-readonly-queue/*' |
| 374 |
branch 'stable' |
| 375 |
changeRequest() |
| 376 |
} |
| 377 |
} |
| 378 |
steps { |
| 379 |
runMachine() |
| 380 |
} |
| 381 |
} |
| 382 |
|
| 383 |
stage('Run long system tests') { |
| 384 |
when { |
| 385 |
anyOf { |
| 386 |
branch 'dev' |
| 387 |
branch 'gh-readonly-queue/*' |
| 388 |
branch 'stable' |
| 389 |
changeRequest() |
| 390 |
} |
| 391 |
} |
| 392 |
steps { |
| 393 |
runLong() |
| 394 |
} |
| 395 |
} |
| 396 |
} |
| 397 |
post { |
| 398 |
unstable { |
| 399 |
script { |
| 400 |
slackBadMessage( |
| 401 |
"Tests failed to pass on ${BRANCH_NAME}", |
| 402 |
"Tests failed on branch ${BRANCH_NAME}, build number ${BUILD_NUMBER}" |
| 403 |
) |
| 404 |
} |
| 405 |
} |
| 406 |
failure { |
| 407 |
script { |
| 408 |
slackBadMessage( |
| 409 |
"Ubuntu 24.04 pipeline failed on ${BRANCH_NAME}", |
| 410 |
"Ubuntu 24.04 pipeline failed on branch ${BRANCH_NAME}, build number ${BUILD_NUMBER}" |
| 411 |
) |
| 412 |
} |
| 413 |
} |
| 414 |
success { |
| 415 |
script { |
| 416 |
slackGoodMessage( |
| 417 |
"Ubuntu 24.04 pipeline passed on branch ${BRANCH_NAME}, build number ${BUILD_NUMBER}" |
| 418 |
) |
| 419 |
} |
| 420 |
} |
| 421 |
// Clean after build |
| 422 |
cleanup { |
| 423 |
cleanWs(cleanWhenNotBuilt: true, |
| 424 |
deleteDirs: true, |
| 425 |
disableDeferredWipeout: true, |
| 426 |
notFailBuild: true, |
| 427 |
) |
| 428 |
sh ''' |
| 429 |
docker rm $(docker stop $(docker ps -a -q --filter ancestor=saunafs-test --format="{{.ID}}")) || true |
| 430 |
''' |
| 431 |
sh """ |
| 432 |
docker image rm ${env.REGISTRY_IMAGE_NAME} || true |
| 433 |
docker image rm saunafs-test:latest || true |
| 434 |
""" |
| 435 |
} |
| 436 |
} |
| 437 |
} |
| 438 |
} |
| 439 |
} |
| 440 |
stage('Deploy packages to dev repository') { |
| 441 |
agent none |
| 442 |
when { |
| 443 |
anyOf { |
| 444 |
branch "dev" |
| 445 |
expression { return params.DEPLOY_PACKAGE_TO_EXPERIMENTAL } |
| 446 |
} |
| 447 |
} |
| 448 |
steps { |
| 449 |
script { |
| 450 |
def repo = params.DEPLOY_PACKAGE_TO_EXPERIMENTAL |
| 451 |
? "Experimental" |
| 452 |
: "Development" |
| 453 |
build ( |
| 454 |
job: 'SaunaFS Packages (Dev)', |
| 455 |
parameters: [ |
| 456 |
string(name: 'PACKAGE_REF', value: params.DEBIAN_PACKAGE_REF), |
| 457 |
string(name: 'SAUNAFS_REF', value: GIT_COMMIT_HASH), |
| 458 |
string(name: 'REPOSITORY', value: repo) |
| 459 |
] |
| 460 |
) |
| 461 |
} |
| 462 |
} |
| 463 |
} |
| 464 |
} |
| 465 |
} |