summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Jenkinsfile84
-rw-r--r--Jenkinsfile.docker74
2 files changed, 93 insertions, 65 deletions
diff --git a/Jenkinsfile b/Jenkinsfile
index cea7ad9d..154a21d6 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -21,71 +21,24 @@
@Library('vyos-build@current')_
setDescription()
-// Due to long build times on DockerHub we rather build the container by ourself
-// and publish it later on.
-
-// create container names on demand
-env.DOCKER_IMAGE = "vyos/vyos-build:" + getGitBranchName()
-env.DOCKER_IMAGE_ARM = "vyos/vyos-build:" + getGitBranchName() + "-armhf"
-env.DOCKER_IMAGE_ARM64 = "vyos/vyos-build:" + getGitBranchName() + "-arm64"
-
node('Docker') {
- stage('Fetch') {
- git branch: getGitBranchName(),
- url: getGitRepoURL()
- }
- stage('Build Docker container') {
- parallel (
- 'x86-64': {
- script {
- dir('docker') {
- sh """
- docker build -t ${env.DOCKER_IMAGE} .
- """
- if (! isCustomBuild()) {
- withDockerRegistry([credentialsId: "DockerHub"]) {
- sh "docker push ${env.DOCKER_IMAGE}"
- }
-
- }
- }
- }
- },
- )
- }
stage('Build timestamp') {
script {
env.TIMESTAMP = sh(returnStdout: true, script: 'date +%Y%m%d%H%M').toString().trim()
- }
- }
-}
+ // create container name on demand
+ def branchName = getGitBranchName()
+ // Adjust PR target branch name so we can re-map it to the proper Docker image.
+ if (isPullRequest())
+ branchName = env.CHANGE_TARGET.toLowerCase()
+ if (branchName.equals('master'))
+ branchName = 'current'
-node('ec2_arm64') {
- stage('Fetch') {
- git branch: getGitBranchName(),
- url: getGitRepoURL()
- }
- stage('Build Docker container') {
- parallel (
- 'arm64': {
- script {
- dir('docker') {
- sh """
- docker build -t ${env.DOCKER_IMAGE_ARM64} --build-arg ARCH=arm64v8/ .
- """
- if (! isCustomBuild()) {
- withDockerRegistry([credentialsId: "DockerHub"]) {
- sh "docker push ${env.DOCKER_IMAGE_ARM64}"
- }
- }
- }
- }
- },
- )
- }
- stage('Build timestamp') {
- script {
- env.TIMESTAMP = sh(returnStdout: true, script: 'date +%Y%m%d%H%M').toString().trim()
+ env.DOCKER_IMAGE = 'vyos/vyos-build:' + branchName
+
+ // Get the current UID and GID from the jenkins agent to allow use of the same UID inside Docker
+ env.USR_ID = sh(returnStdout: true, script: 'id -u').toString().trim()
+ env.GRP_ID = sh(returnStdout: true, script: 'id -g').toString().trim()
+ env.DOCKER_ARGS = '--sysctl net.ipv6.conf.lo.disable_ipv6=0 -e GOSU_UID=' + env.USR_ID + ' -e GOSU_GID=' + env.GRP_ID
}
}
}
@@ -109,11 +62,12 @@ pipeline {
cron('H 2 * * *')
}
agent {
- dockerfile {
+ docker {
+ label "Docker"
+ args "${env.DOCKER_ARGS}"
+ image "${env.DOCKER_IMAGE}"
+ alwaysPull true
reuseNode true
- filename 'Dockerfile'
- dir 'docker'
- args '--privileged --sysctl net.ipv6.conf.lo.disable_ipv6=0 -e GOSU_UID=1006 -e GOSU_GID=1006'
}
}
stages {
@@ -141,7 +95,7 @@ pipeline {
sh """
./configure \
--build-by ${params.BUILD_BY} \
- --debian-mirror http://ftp.us.debian.org/debian/ \
+ --debian-mirror http://deb.debian.org/debian/ \
--build-type release \
--version ${params.BUILD_VERSION} ${CUSTOM_PACKAGES}
sudo make iso
diff --git a/Jenkinsfile.docker b/Jenkinsfile.docker
new file mode 100644
index 00000000..0706127b
--- /dev/null
+++ b/Jenkinsfile.docker
@@ -0,0 +1,74 @@
+#!/usr/bin/env groovy
+// Copyright (C) 2019-2021 VyOS maintainers and contributors
+//
+// This program is free software; you can redistribute it and/or modify
+// in order to easy exprort images built to "external" world
+// it under the terms of the GNU General Public License version 2 or later as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+@NonCPS
+
+// Using a version specifier library, use 'current' branch. The underscore (_)
+// is not a typo! You need this underscore if the line immediately after the
+// @Library annotation is not an import statement!
+@Library('vyos-build@current')_
+setDescription()
+
+pipeline {
+ agent none
+ stages {
+ stage('Build containers') {
+ when {
+ beforeOptions true
+ beforeAgent true
+ // Only run ISO image build process of explicit user request or
+ // once a night triggered by the timer.
+ anyOf {
+ changeset pattern: "**/docker/*"
+ triggeredBy cause: "UserIdCause"
+ }
+ }
+ parallel {
+ stage('x86_64') {
+ agent {
+ label "ec2_amd64"
+ }
+ steps {
+ script {
+ DOCKER_IMAGE = "vyos/vyos-build:" + getGitBranchName()
+ sh "docker build -t ${DOCKER_IMAGE} docker"
+ if (! isCustomBuild()) {
+ withDockerRegistry([credentialsId: "DockerHub"]) {
+ sh "docker push ${DOCKER_IMAGE}"
+ }
+ }
+ }
+ }
+ }
+ stage('arm64') {
+ agent {
+ label "ec2_arm64"
+ }
+ steps {
+ script {
+ DOCKER_IMAGE = "vyos/vyos-build:" + getGitBranchName() + "-arm64"
+ sh "docker build -t ${DOCKER_IMAGE} --build-arg ARCH=arm64v8/ docker"
+ if (! isCustomBuild()) {
+ withDockerRegistry([credentialsId: "DockerHub"]) {
+ sh "docker push ${DOCKER_IMAGE}"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}