Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

refactor: build docker-inbound-agent like docker-agent #363

Merged
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 64 additions & 97 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,115 +3,82 @@ pipeline {

options {
buildDiscarder(logRotator(daysToKeepStr: '10'))
timestamps()
}

stages {
stage('Build') {
parallel {
stage('Windows') {
options {
timeout(time: 60, unit: 'MINUTES')
stage('docker-inbound-agent') {
failFast true
matrix {
axes {
axis {
name 'AGENT_TYPE'
values 'linux', 'windows-2019'
}
environment {
DOCKERHUB_ORGANISATION = "${infra.isTrusted() ? 'jenkins' : 'jenkins4eval'}"
}
stages {
stage('Build and Test') {
// This stage is the "CI" and should be run on all code changes triggered by a code change
when {
not { buildingTag() }
}
stages {
stage('Main') {
agent {
label env.AGENT_TYPE
}
options {
timeout(time: 30, unit: 'MINUTES')
}
environment {
DOCKERHUB_ORGANISATION = "${infra.isTrusted() ? 'jenkins' : 'jenkins4eval'}"
}
stages {
stage('Prepare Docker') {
when {
environment name: 'AGENT_TYPE', value: 'linux'
}
steps {
sh '''
docker buildx create --use
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
'''
}
}
steps {
script {
def parallelBuilds = [:]
def images = ['jdk11-windowsservercore-ltsc2019', 'jdk11-nanoserver-1809', 'jdk17-windowsservercore-ltsc2019', 'jdk17-nanoserver-1809']
for (unboundImage in images) {
def image = unboundImage // Bind variable before the closure
// Prepare a map of the steps to run in parallel
parallelBuilds[image] = {
// Allocate a node for each image to avoid filling disk
node('docker-windows') {
checkout scm
powershell '& ./make.ps1 -Build ' + image + ' test'
junit(allowEmptyResults: true, keepLongStdio: true, testResults: 'target/**/junit-results.xml')
}
stage('Build and Test') {
// This stage is the "CI" and should be run on all code changes triggered by a code change
when {
not { buildingTag() }
}
steps {
script {
if(isUnix()) {
sh 'make build'
sh 'make test'
// If the tests are passing for Linux AMD64, then we can build all the CPU architectures
sh 'docker buildx bake --file docker-bake.hcl linux'
} else {
powershell "& ./build.ps1 test"
}
}
// Peform the parallel execution
parallel parallelBuilds
}
}
}
stage('Deploy to DockerHub') {
agent {
label 'docker-windows'
}
// This stage is the "CD" and should only be run when a tag triggered the build
when {
buildingTag()
}
steps {
script {
// This function is defined in the jenkins-infra/pipeline-library
infra.withDockerCredentials {
powershell '& ./make.ps1 -PushVersions -VersionTag $env:TAG_NAME publish'
post {
always {
junit(allowEmptyResults: true, keepLongStdio: true, testResults: 'target/**/junit-results.xml')
}
}
}
}
}
}
stage('Linux') {
agent {
label "docker&&linux"
}
options {
timeout(time: 30, unit: 'MINUTES')
}
environment {
JENKINS_REPO = "${infra.isTrusted() ? 'jenkins' : 'jenkins4eval'}/inbound-agent"
}
stages {
stage('Prepare Docker') {
steps {
sh '''
docker buildx create --use
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
'''
}
}
stage('Build and Test') {
// This stage is the "CI" and should be run on all code changes triggered by a code change
when {
not { buildingTag() }
}
steps {
sh 'make build'
sh 'make test'
// If the tests are passing for Linux AMD64, then we can build all the CPU architectures
sh 'docker buildx bake --file docker-bake.hcl linux'
}
post {
always {
junit(allowEmptyResults: true, keepLongStdio: true, testResults: 'target/*.xml')
stage('Deploy to DockerHub') {
// This stage is the "CD" and should only be run when a tag triggered the build
when {
buildingTag()
}
}
}
stage('Deploy to DockerHub') {
// This stage is the "CD" and should only be run when a tag triggered the build
when {
buildingTag()
}
steps {
script {
// This function is defined in the jenkins-infra/pipeline-library
infra.withDockerCredentials {
sh '''
export IMAGE_TAG="${TAG_NAME}"
export ON_TAG=true
docker buildx bake --push --file docker-bake.hcl linux
'''
steps {
script {
infra.withDockerCredentials {
if (isUnix()) {
sh '''
export IMAGE_TAG="${TAG_NAME}"
export ON_TAG=true
docker buildx bake --push --file docker-bake.hcl linux
'''
} else {
powershell "& ./build.ps1 -PushVersions -VersionTag $env:TAG_NAME publish"
}
}
}
}
}
Expand Down
33 changes: 33 additions & 0 deletions build-windows.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
services:
jdk11-nanoserver:
image: jdk11-nanoserver-${NANOSERVER_VERSION_NAME}
build:
context: ./
dockerfile: ./windows/nanoserver/Dockerfile
args:
version: ${PARENT_IMAGE_VERSION}
WINDOWS_VERSION_TAG: ${NANOSERVER_VERSION_TAG}
jdk17-nanoserver:
image: jdk17-nanoserver-${NANOSERVER_VERSION_NAME}
build:
context: ./
dockerfile: ./windows/nanoserver/Dockerfile
args:
version: ${PARENT_IMAGE_VERSION}
WINDOWS_VERSION_TAG: ${NANOSERVER_VERSION_TAG}
jdk11-windowsservercore:
image: jdk11-windowsservercore-${WINDOWS_VERSION_NAME}
build:
context: ./
dockerfile: ./windows/windowsservercore/Dockerfile
args:
version: ${PARENT_IMAGE_VERSION}
WINDOWS_VERSION_TAG: ${WINDOWS_VERSION_TAG}
jdk17-windowsservercore:
image: jdk17-windowsservercore-${WINDOWS_VERSION_NAME}
build:
context: ./
dockerfile: ./windows/windowsservercore/Dockerfile
args:
version: ${PARENT_IMAGE_VERSION}
WINDOWS_VERSION_TAG: ${WINDOWS_VERSION_TAG}
Loading