From 9a387561b2da494a049f90620527a7bfb87c5ca0 Mon Sep 17 00:00:00 2001 From: Jesse Awan Date: Wed, 22 Dec 2021 16:51:06 +0100 Subject: [PATCH] remove docker native buildtool check (#3336) * remove docker native buildtool check --- test/groovy/BuildExecuteTest.groovy | 56 +++-------------------------- vars/buildExecute.groovy | 21 +---------- 2 files changed, 6 insertions(+), 71 deletions(-) diff --git a/test/groovy/BuildExecuteTest.groovy b/test/groovy/BuildExecuteTest.groovy index a6de3042b..8d31230f5 100644 --- a/test/groovy/BuildExecuteTest.groovy +++ b/test/groovy/BuildExecuteTest.groovy @@ -286,68 +286,23 @@ class BuildExecuteTest extends BasePiperTest { @Test void testDocker() { + boolean buildToolCalled = false binding.setVariable('docker', new DockerMock('test')) def pushParams = [:] - helper.registerAllowedMethod('containerPushToRegistry', [Map.class], { m -> - pushParams = m + helper.registerAllowedMethod('kanikoExecute', [Map.class], { m -> + buildToolCalled = true return }) stepRule.step.buildExecute( script: nullScript, buildTool: 'docker', - dockerImageName: 'path/to/myImage', - dockerImageTag: 'myTag', - dockerRegistryUrl: 'https://my.registry:55555' ) - - assertThat(pushParams.dockerBuildImage.image.toString(), is('path/to/myImage:myTag')) - assertThat(pushParams.dockerRegistryUrl.toString(), is('https://my.registry:55555')) - assertThat(nullScript.commonPipelineEnvironment.getValue('containerImage').toString(), is('path/to/myImage:myTag')) - } - - @Test - void testDockerWithEnv() { - nullScript.commonPipelineEnvironment.setArtifactVersion('1.0.0') - binding.setVariable('docker', new DockerMock('test')) - def pushParams = [:] - helper.registerAllowedMethod('containerPushToRegistry', [Map.class], { m -> - pushParams = m - return - }) - stepRule.step.buildExecute( - script: nullScript, - buildTool: 'docker', - dockerImageName: 'path/to/myImage', - dockerRegistryUrl: 'https://my.registry:55555' - ) - - assertThat(pushParams.dockerBuildImage.image.toString(), is('path/to/myImage:1.0.0')) - assertThat(pushParams.dockerRegistryUrl.toString(), is('https://my.registry:55555')) - assertThat(nullScript.commonPipelineEnvironment.getValue('containerImage').toString(), is('path/to/myImage:1.0.0')) - } - - @Test - void testDockerNoPush() { - binding.setVariable('docker', new DockerMock('test')) - def pushParams = [:] - helper.registerAllowedMethod('containerPushToRegistry', [Map.class], { m -> - pushParams = m - return - }) - stepRule.step.buildExecute( - script: nullScript, - buildTool: 'docker', - dockerImageName: 'path/to/myImage', - dockerImageTag: 'myTag', - dockerRegistryUrl: '' - ) - - assertThat(pushParams.dockerBuildImage, nullValue()) - assertThat(pushParams.dockerRegistryUrl, nullValue()) + assertThat(buildToolCalled, is(true)) } @Test void testKaniko() { + binding.setVariable('docker', new DockerMock('test')) def buildToolCalled = false helper.registerAllowedMethod('kanikoExecute', [Map.class], { m -> buildToolCalled = true @@ -359,5 +314,4 @@ class BuildExecuteTest extends BasePiperTest { ) assertThat(buildToolCalled, is(true)) } - } diff --git a/vars/buildExecute.groovy b/vars/buildExecute.groovy index bf2e4bc11..ba099710c 100644 --- a/vars/buildExecute.groovy +++ b/vars/buildExecute.groovy @@ -86,26 +86,7 @@ void call(Map parameters = [:]) { npmExecuteScripts script: script, install: config.npmInstall, runScripts: config.npmRunScripts break case ['docker', 'kaniko']: - DockerUtils dockerUtils = new DockerUtils(script) - if (config.buildTool == 'docker' && !dockerUtils.withDockerDaemon()) { - config.buildTool = 'kaniko' - echo "[${STEP_NAME}] No Docker daemon available, thus switching to Kaniko build" - } - if (config.buildTool == 'kaniko'){ - kanikoExecute script: script - }else{ - ConfigurationHelper.newInstance(this, config) - .withMandatoryProperty('dockerImageName') - .withMandatoryProperty('dockerImageTag') - - def dockerImageNameAndTag = "${config.dockerImageName}:${config.dockerImageTag}" - def dockerBuildImage = docker.build(dockerImageNameAndTag, "${config.containerBuildOptions ?: ''} .") - //only push if registry is defined - if (config.dockerRegistryUrl) { - containerPushToRegistry script: script, dockerBuildImage: dockerBuildImage, dockerRegistryUrl: config.dockerRegistryUrl - } - script.commonPipelineEnvironment.setValue('containerImage', dockerImageNameAndTag) - } + kanikoExecute script: script break default: if (config.dockerImage && config.dockerCommand) {