Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows Container] Windows docker setups jenkins docker build #3905

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 24 additions & 4 deletions jenkins/docker/docker-build.jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
def docker_images = [
"linux": "opensearchstaging/ci-runner:ubuntu2004-x64-docker-buildx0.9.1-qemu5.0-awscli1.22-jdk11-v1",
"windows": "opensearchstaging/ci-runner:ci-runner-windows2019-servercore-opensearch-build-v1"
]

def docker_args = [
"linux": "-u root -v /var/run/docker.sock:/var/run/docker.sock",
"windows": "-u ContainerAdministrator -v //./pipe/docker_engine://./pipe/docker_engine"
]

def agent_nodes = [
"linux": "Jenkins-Agent-Ubuntu2004-X64-M52xlarge-Docker-Builder",
"windows": "Jenkins-Agent-Windows2019-X64-C54xlarge-Docker-Builder",
]

pipeline {
options {
timeout(time: 5, unit: 'HOURS')
Expand All @@ -22,12 +37,17 @@ pipeline {
description: 'The script path of the docker build script, assuming you are already in root dir of DOCKER_BUILD_GIT_REPOSITORY.',
trim: true
)
choice(
name: 'DOCKER_BUILD_OS',
description: 'Build docker image on which operating system.',
choices: ['linux', 'windows'],
)
}
stages {
stage('Parameters Check') {
steps {
script {
if(! DOCKER_BUILD_GIT_REPOSITORY.startsWith('https:/opensearch-project/')) {
if (! DOCKER_BUILD_GIT_REPOSITORY.startsWith('https:/opensearch-project/')) {
currentBuild.result = 'ABORTED'
error('The repository needs to be an opensearch-project repository')
}
Expand All @@ -37,9 +57,9 @@ pipeline {
stage('docker-build') {
agent {
docker {
label 'Jenkins-Agent-Ubuntu2004-X64-M52xlarge-Docker-Builder'
image 'opensearchstaging/ci-runner:ubuntu2004-x64-docker-buildx0.9.1-qemu5.0-awscli1.22-jdk11-v1'
args '-u root -v /var/run/docker.sock:/var/run/docker.sock'
label agent_nodes["${DOCKER_BUILD_OS}"]
image docker_images["${DOCKER_BUILD_OS}"]
args docker_args["${DOCKER_BUILD_OS}"]
registryUrl 'https://public.ecr.aws/'
alwaysPull true
}
Expand Down
5 changes: 5 additions & 0 deletions tests/jenkins/TestDockerBuild.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class TestDockerBuild extends BuildPipelineTest {
String dockerBuildGitRespository = 'https:/opensearch-project/opensearch-build'
String dockerBuildGitRespositoryReference = 'main'
String dockerBuildScriptwithCommands = 'bash docker/ci/build-image-multi-arch.sh -v <TAG_NAME> -f <DOCKERFILE PATH>'
String dockerBuildOS = 'linux'

@Override
@Before
Expand All @@ -41,6 +42,7 @@ class TestDockerBuild extends BuildPipelineTest {
binding.setVariable('DOCKER_BUILD_GIT_REPOSITORY', dockerBuildGitRespository)
binding.setVariable('DOCKER_BUILD_GIT_REPOSITORY_REFERENCE', dockerBuildGitRespositoryReference)
binding.setVariable('DOCKER_BUILD_SCRIPT_WITH_COMMANDS', dockerBuildScriptwithCommands)
binding.setVariable('DOCKER_BUILD_OS', dockerBuildOS)

}

Expand All @@ -65,6 +67,9 @@ class TestDockerBuild extends BuildPipelineTest {
// Validate the docker-build.sh is called with correct predefined credential
assertCallStack().contains("docker-build.sh(echo Account: jenkins-staging-dockerhub-credential)")

// Make sure dockerBuildOS is deciding agent_node docker_nodes docker_args correctly
assertCallStack().contains("docker-build.echo(Executing on agent [docker:[alwaysPull:true, args:-u root -v /var/run/docker.sock:/var/run/docker.sock, containerPerStageRoot:false, label:Jenkins-Agent-Ubuntu2004-X64-M52xlarge-Docker-Builder, image:opensearchstaging/ci-runner:ubuntu2004-x64-docker-buildx0.9.1-qemu5.0-awscli1.22-jdk11-v1, reuseNode:false, registryUrl:https://public.ecr.aws/, stages:[:]]])")

printCallStack()
}

Expand Down
Loading