Skip to content

Commit

Permalink
Merge pull request #594 from thaJeztah/split_stages
Browse files Browse the repository at this point in the history
Jenkinsfile: run builds in parallel, and build all distro/arches
  • Loading branch information
thaJeztah authored Oct 25, 2021
2 parents 94f2818 + 5413760 commit 8bbb124
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 60 deletions.
179 changes: 125 additions & 54 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,130 @@

def branch = env.CHANGE_TARGET ?: env.BRANCH_NAME

test_steps = [
'deb': { ->
stage('Ubuntu and Debian Package') {
wrappedNode(label: 'ubuntu-2004 && x86_64', cleanWorkspace: true) {
try {
checkout scm
sh "make REF=$branch checkout"
sh "make -C deb ubuntu-focal ubuntu-hirsute ubuntu-impish debian-bullseye"
} finally {
sh "make clean"
}
}
}
},
'raspbian': { ->
stage('Raspbian') {
wrappedNode(label: 'ubuntu && armhf', cleanWorkspace: true) {
try {
checkout scm
sh "make REF=$branch checkout"
sh "make -C deb raspbian-buster raspbian-bullseye"
} finally {
sh "make clean"
}
}
}
},
'rpm': { ->
stage('Centos 7 and 8 RPM Packages') {
wrappedNode(label: 'ubuntu-2004 && x86_64', cleanWorkspace: true) {
try {
checkout scm
sh "make REF=$branch checkout"
sh "make -C rpm centos-7 centos-8 fedora-35"
} finally {
sh "make clean"
}
}
}
},
'static-cross': { ->
stage('Static Linux Binaries') {
wrappedNode(label: 'ubuntu-2004 && x86_64', cleanWorkspace: true) {
try {
checkout scm
sh "make REF=$branch checkout"
sh "make REF=$branch DOCKER_BUILD_PKGS='static-linux cross-mac cross-win' static"
} finally {
sh "make clean"
}
}
}
},
def pkgs = [
[target: "centos-7", image: "centos:7", arches: ["amd64", "aarch64"]], // (EOL: June 30, 2024)
[target: "centos-8", image: "centos:8", arches: ["amd64", "aarch64"]],
[target: "debian-buster", image: "debian:buster", arches: ["amd64", "aarch64", "armhf"]], // Debian 10 (EOL: 2024)
[target: "debian-bullseye", image: "debian:bullseye", arches: ["amd64", "aarch64", "armhf"]], // Debian 11 (Next stable)
[target: "fedora-33", image: "fedora:33", arches: ["amd64", "aarch64"]], // EOL: November 23, 2021
[target: "fedora-34", image: "fedora:34", arches: ["amd64", "aarch64"]], // EOL: May 17, 2022
[target: "fedora-35", image: "fedora:35", arches: ["amd64", "aarch64"]], // EOL: November 30, 2022
[target: "raspbian-buster", image: "balenalib/rpi-raspbian:buster", arches: ["armhf"]], // Debian/Raspbian 10 (EOL: 2024)
[target: "raspbian-bullseye", image: "balenalib/rpi-raspbian:bullseye", arches: ["armhf"]], // Debian/Raspbian 11 (Next stable)
[target: "ubuntu-bionic", image: "ubuntu:bionic", arches: ["amd64", "aarch64", "armhf"]], // Ubuntu 18.04 LTS (End of support: April, 2023. EOL: April, 2028)
[target: "ubuntu-focal", image: "ubuntu:focal", arches: ["amd64", "aarch64", "armhf"]], // Ubuntu 20.04 LTS (End of support: April, 2025. EOL: April, 2030)
[target: "ubuntu-hirsute", image: "ubuntu:hirsute", arches: ["amd64", "aarch64", "armhf"]], // Ubuntu 21.04 (EOL: January, 2022)
[target: "ubuntu-impish", image: "ubuntu:impish", arches: ["amd64", "aarch64", "armhf"]], // Ubuntu 21.10 (EOL: July, 2022)
]

parallel(test_steps)
def genBuildStep(LinkedHashMap pkg, String arch) {
def nodeLabel = "linux&&${arch}"
def platform = ""
def branch = env.CHANGE_TARGET ?: env.BRANCH_NAME

if (arch == 'armhf') {
// Running armhf builds on EC2 requires --platform parameter
// Otherwise it accidentally pulls armel images which then breaks the verify step
platform = "--platform=linux/${arch}"
nodeLabel = "${nodeLabel}&&ubuntu"
} else {
nodeLabel = "${nodeLabel}&&ubuntu-2004"
}
return { ->
wrappedNode(label: nodeLabel, cleanWorkspace: true) {
stage("${pkg.target}-${arch}") {
// This is just a "dummy" stage to make the distro/arch visible
// in Jenkins' BlueOcean view, which truncates names....
sh 'echo starting...'
}
stage("info") {
sh 'docker version'
sh 'docker info'
}
stage("build") {
try {
checkout scm
sh "make REF=$branch ${pkg.target}"
} finally {
sh "make clean"
}
}
}
}
}

def build_package_steps = [
'static-linux': { ->
wrappedNode(label: 'ubuntu-2004 && x86_64', cleanWorkspace: true) {
stage("static-linux") {
// This is just a "dummy" stage to make the distro/arch visible
// in Jenkins' BlueOcean view, which truncates names....
sh 'echo starting...'
}
stage("info") {
sh 'docker version'
sh 'docker info'
}
stage("build") {
try {
checkout scm
sh "make REF=$branch DOCKER_BUILD_PKGS='static-linux' static"
} finally {
sh "make clean"
}
}
}
},
'cross-mac': { ->
wrappedNode(label: 'ubuntu-2004 && x86_64', cleanWorkspace: true) {
stage("cross-mac") {
// This is just a "dummy" stage to make the distro/arch visible
// in Jenkins' BlueOcean view, which truncates names....
sh 'echo starting...'
}
stage("info") {
sh 'docker version'
sh 'docker info'
}
stage("build") {
try {
checkout scm
sh "make REF=$branch DOCKER_BUILD_PKGS='cross-mac' static"
} finally {
sh "make clean"
}
}
}
},
'cross-win': { ->
wrappedNode(label: 'ubuntu-2004 && x86_64', cleanWorkspace: true) {
stage("cross-win") {
// This is just a "dummy" stage to make the distro/arch visible
// in Jenkins' BlueOcean view, which truncates names....
sh 'echo starting...'
}
stage("info") {
sh 'docker version'
sh 'docker info'
}
stage("build") {
try {
checkout scm
sh "make REF=$branch DOCKER_BUILD_PKGS='cross-win' static"
} finally {
sh "make clean"
}
}
}
},
]

def genPackageSteps(opts) {
return opts.arches.collectEntries {
["${opts.image}-${it}": genBuildStep(opts, it)]
}
}

build_package_steps << pkgs.collectEntries { genPackageSteps(it) }

parallel(build_package_steps)
16 changes: 10 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,17 @@ clean: clean-src ## remove build artifacts
$(MAKE) -C deb clean
$(MAKE) -C static clean

.PHONY: rpm
rpm: checkout ## build rpm packages
$(MAKE) -C $@ VERSION=$(VERSION) GO_VERSION=$(GO_VERSION) rpm
.PHONY: deb rpm
deb rpm: checkout ## build rpm/deb packages
$(MAKE) -C $@ VERSION=$(VERSION) GO_VERSION=$(GO_VERSION) $@

.PHONY: deb
deb: checkout ## build deb packages
$(MAKE) -C $@ VERSION=$(VERSION) GO_VERSION=$(GO_VERSION) deb
.PHONY: centos-% fedora-% rhel-%
centos-% fedora-% rhel-%: checkout ## build rpm packages for the specified distro
$(MAKE) -C rpm VERSION=$(VERSION) GO_VERSION=$(GO_VERSION) $@

.PHONY: debian-% raspbian-% ubuntu-%
debian-% raspbian-% ubuntu-%: checkout ## build deb packages for the specified distro
$(MAKE) -C deb VERSION=$(VERSION) GO_VERSION=$(GO_VERSION) $@

.PHONY: static
static: DOCKER_BUILD_PKGS:=static-linux cross-mac cross-win cross-arm
Expand Down

0 comments on commit 8bbb124

Please sign in to comment.