From 6bb32639347989a19d7fdf5ce810e7cb216d359e Mon Sep 17 00:00:00 2001 From: bohmber Date: Fri, 28 Dec 2018 20:45:40 +0100 Subject: [PATCH 1/5] Allow to configure noCache option for openshift docker build strategy https://docs.openshift.com/container-platform/3.6/dev_guide/builds/build_strategies.html#no-cache Signed-off-by: bohmber --- .../core/service/openshift/OpenshiftBuildService.java | 11 +++++++++++ .../service/openshift/OpenshiftBuildServiceTest.java | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/io/fabric8/maven/core/service/openshift/OpenshiftBuildService.java b/core/src/main/java/io/fabric8/maven/core/service/openshift/OpenshiftBuildService.java index 53eb187727..ee88498ecd 100644 --- a/core/src/main/java/io/fabric8/maven/core/service/openshift/OpenshiftBuildService.java +++ b/core/src/main/java/io/fabric8/maven/core/service/openshift/OpenshiftBuildService.java @@ -308,6 +308,7 @@ private BuildStrategy createBuildStrategy(ImageConfiguration imageConfig, OpenSh .withName(fromName) .withNamespace(StringUtils.isEmpty(fromNamespace) ? null : fromNamespace) .endFrom() + .withNoCache(checkForNocache(imageConfig)) .endDockerStrategy().build(); if (openshiftPullSecret != null) { @@ -353,6 +354,16 @@ private BuildStrategy createBuildStrategy(ImageConfiguration imageConfig, OpenSh } } + private Boolean checkForNocache(ImageConfiguration imageConfig) { + String nocache = System.getProperty("docker.nocache"); + if (nocache != null) { + return nocache.length() == 0 || Boolean.valueOf(nocache); + } else { + BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration(); + return buildConfig.getNoCache(); + } + } + private Boolean checkOrCreatePullSecret(BuildServiceConfig config, OpenShiftClient client, KubernetesListBuilder builder, String pullSecretName, ImageConfiguration imageConfig) throws MojoExecutionException, UnsupportedEncodingException { io.fabric8.maven.docker.service.BuildService.BuildContext dockerBuildContext = config.getDockerBuildContext(); diff --git a/core/src/test/java/io/fabric8/maven/core/service/openshift/OpenshiftBuildServiceTest.java b/core/src/test/java/io/fabric8/maven/core/service/openshift/OpenshiftBuildServiceTest.java index 13bf6399a9..b3e078730c 100644 --- a/core/src/test/java/io/fabric8/maven/core/service/openshift/OpenshiftBuildServiceTest.java +++ b/core/src/test/java/io/fabric8/maven/core/service/openshift/OpenshiftBuildServiceTest.java @@ -270,6 +270,7 @@ public void testDockerBuildFromExt() throws Exception { .name(projectName) .buildConfig(new BuildImageConfiguration.Builder() .fromExt(fromExt) + .nocache(Boolean.TRUE) .build() ).build(); @@ -277,7 +278,7 @@ public void testDockerBuildFromExt() throws Exception { assertTrue(mockServer.getRequestCount() > 8); collector.assertEventsRecordedInOrder("build-config-check", "new-build-config", "pushed"); - assertEquals("{\"apiVersion\":\"build.openshift.io/v1\",\"kind\":\"BuildConfig\",\"metadata\":{\"annotations\":{},\"labels\":{},\"name\":\"myapp-docker\"},\"spec\":{\"nodeSelector\":{},\"output\":{\"to\":{\"kind\":\"ImageStreamTag\",\"name\":\"myapp:latest\"}},\"source\":{\"type\":\"Binary\"},\"strategy\":{\"dockerStrategy\":{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"app:1.2-1\",\"namespace\":\"my-project\"}},\"type\":\"Docker\"},\"triggers\":[]}}", collector.getBodies().get(1)); + assertEquals("{\"apiVersion\":\"build.openshift.io/v1\",\"kind\":\"BuildConfig\",\"metadata\":{\"annotations\":{},\"labels\":{},\"name\":\"myapp-docker\"},\"spec\":{\"nodeSelector\":{},\"output\":{\"to\":{\"kind\":\"ImageStreamTag\",\"name\":\"myapp:latest\"}},\"source\":{\"type\":\"Binary\"},\"strategy\":{\"dockerStrategy\":{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"app:1.2-1\",\"namespace\":\"my-project\"},\"noCache\":true},\"type\":\"Docker\"},\"triggers\":[]}}", collector.getBodies().get(1)); collector.assertEventsNotRecorded("patch-build-config"); bTestComplete = true; } catch (Fabric8ServiceException exception) { From 15753e2d861efe4514f48cd5c59382bf801e67d2 Mon Sep 17 00:00:00 2001 From: bohmber Date: Tue, 1 Jan 2019 20:36:16 +0100 Subject: [PATCH 2/5] Allow to configure noCache option for openshift docker build strategy added changelog entry Signed-off-by: bohmber --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4147faa2da..b4ab2f4693 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ After this we will switch probably to real [Semantic Versioning 2.0.0](http://se * Fix 1460: Upgraded kubernetes client to 4.1.1 * Fix 690: Removes deprecated _legacyPortMapping_ property. * Fix 1458: Support for from Image configuration in openshift docker build strategy +* Fix 1466: Allow to configure noCache option for openshift docker build strategy ### 4.0.0-M2 (2018-12-14) * Fix 10: Make VolumeConfiguration more flexible From 99728e5d5e2b7edec716ac62793d9832978c106d Mon Sep 17 00:00:00 2001 From: Devang Gaur Date: Thu, 10 Jan 2019 14:37:42 +0530 Subject: [PATCH 3/5] Added 'skip' options to goals. (#1471) fixes #732 . --- CHANGELOG.md | 1 + .../maven/plugin/mojo/build/ApplyMojo.java | 8 +++++++- .../maven/plugin/mojo/build/BuildMojo.java | 7 +++++++ .../maven/plugin/mojo/build/PushMojo.java | 5 ++++- .../maven/plugin/mojo/build/ResourceMojo.java | 7 +++++++ .../maven/plugin/mojo/develop/DeployMojo.java | 16 +++++++++++++++- 6 files changed, 41 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4ab2f4693..fd91dc6fd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ After this we will switch probably to real [Semantic Versioning 2.0.0](http://se * Fix 690: Removes deprecated _legacyPortMapping_ property. * Fix 1458: Support for from Image configuration in openshift docker build strategy * Fix 1466: Allow to configure noCache option for openshift docker build strategy +* Fix 732: Added 'skip' options to goals. ### 4.0.0-M2 (2018-12-14) * Fix 10: Make VolumeConfiguration more flexible diff --git a/plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/ApplyMojo.java b/plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/ApplyMojo.java index 8c12093a66..38942c971e 100644 --- a/plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/ApplyMojo.java +++ b/plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/ApplyMojo.java @@ -193,10 +193,16 @@ public class ApplyMojo extends AbstractFabric8Mojo { @Parameter(property = "fabric8.s2i.buildNameSuffix", defaultValue = "-s2i") protected String s2iBuildNameSuffix; + @Parameter(property = "fabric8.skip.apply", defaultValue = "false") + protected boolean skipApply; + private ClusterAccess clusterAccess; protected ApplyService applyService; public void executeInternal() throws MojoExecutionException { + if (skipApply) { + return; + } clusterAccess = new ClusterAccess(getClusterConfiguration()); @@ -649,4 +655,4 @@ protected MavenProject getRootProject() { return project; } -} \ No newline at end of file +} diff --git a/plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/BuildMojo.java b/plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/BuildMojo.java index 06706eaff1..a556bfaad6 100644 --- a/plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/BuildMojo.java +++ b/plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/BuildMojo.java @@ -172,6 +172,9 @@ public class BuildMojo extends io.fabric8.maven.docker.BuildMojo { @Parameter(property = "fabric8.build.recreate", defaultValue = "none") private String buildRecreate; + @Parameter(property = "docker.skip.build", defaultValue = "false") + protected boolean skipBuild; + @Component private MavenProjectHelper projectHelper; @@ -215,6 +218,10 @@ protected boolean isDockerAccessRequired() { @Override protected void executeInternal(ServiceHub hub) throws MojoExecutionException { + if (skipBuild) { + return; + } + try { if (shouldSkipBecauseOfPomPackaging()) { getLog().info("Disabling docker build for pom packaging"); diff --git a/plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/PushMojo.java b/plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/PushMojo.java index 895b81b550..c1b263b43d 100644 --- a/plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/PushMojo.java +++ b/plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/PushMojo.java @@ -92,6 +92,9 @@ public class PushMojo extends io.fabric8.maven.docker.PushMojo { @Parameter(property = "fabric8.build.strategy" ) private OpenShiftBuildStrategy buildStrategy = OpenShiftBuildStrategy.s2i; + @Parameter(property = "docker.skip.push", defaultValue = "false") + protected boolean skipPush; + @Override protected String getLogPrefix() { return "F8> "; @@ -99,7 +102,7 @@ protected String getLogPrefix() { @Override public void execute() throws MojoExecutionException, MojoFailureException { - if (skip) { + if (skip || skipPush) { return; } super.execute(); diff --git a/plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/ResourceMojo.java b/plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/ResourceMojo.java index 2a4431e7ba..c4a245f8b7 100644 --- a/plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/ResourceMojo.java +++ b/plugin/src/main/java/io/fabric8/maven/plugin/mojo/build/ResourceMojo.java @@ -317,6 +317,9 @@ public class ResourceMojo extends AbstractFabric8Mojo { @Parameter(property = "kompose.dir", defaultValue = "${user.home}/.kompose/bin") private File komposeBinDir; + @Parameter(property = "docker.skip.resource", defaultValue = "false") + protected boolean skipResource; + // Access for creating OpenShift binary builds private ClusterAccess clusterAccess; @@ -427,6 +430,10 @@ private static File writeResource(File resourceFileBase, Object entity, Resource } public void executeInternal() throws MojoExecutionException, MojoFailureException { + if (skipResource) { + return; + } + realResourceDir = ResourceDirCreator.getFinalResourceDir(resourceDir, environment); realResourceDirOpenShiftOverride = ResourceDirCreator.getFinalResourceDir(resourceDirOpenShiftOverride, environment); diff --git a/plugin/src/main/java/io/fabric8/maven/plugin/mojo/develop/DeployMojo.java b/plugin/src/main/java/io/fabric8/maven/plugin/mojo/develop/DeployMojo.java index 2faede6631..bcd597ae61 100644 --- a/plugin/src/main/java/io/fabric8/maven/plugin/mojo/develop/DeployMojo.java +++ b/plugin/src/main/java/io/fabric8/maven/plugin/mojo/develop/DeployMojo.java @@ -16,10 +16,12 @@ package io.fabric8.maven.plugin.mojo.develop; import io.fabric8.maven.plugin.mojo.build.ApplyMojo; +import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Execute; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.plugins.annotations.Parameter; /** * This goal forks the install goal then applies the generated kubernetes resources to the current cluster. @@ -32,4 +34,16 @@ @Mojo(name = "deploy", requiresDependencyResolution = ResolutionScope.COMPILE, defaultPhase = LifecyclePhase.VALIDATE) @Execute(phase = LifecyclePhase.INSTALL) -public class DeployMojo extends ApplyMojo { } +public class DeployMojo extends ApplyMojo { + @Parameter(property = "docker.skip.deploy", defaultValue = "false") + protected boolean skipDeploy; + + @Override + public void executeInternal() throws MojoExecutionException { + if (skipDeploy) { + return; + } + + super.executeInternal(); + } +} From 0de3303ceb0b6144d0d786e3a98b4047995be5b3 Mon Sep 17 00:00:00 2001 From: bohmber Date: Tue, 1 Jan 2019 20:36:16 +0100 Subject: [PATCH 4/5] Allow to configure noCache option for openshift docker build strategy added changelog entry Signed-off-by: bohmber --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd91dc6fd3..61199c818b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ After this we will switch probably to real [Semantic Versioning 2.0.0](http://se * Fix 1458: Support for from Image configuration in openshift docker build strategy * Fix 1466: Allow to configure noCache option for openshift docker build strategy * Fix 732: Added 'skip' options to goals. +* Fix 1466: Allow to configure noCache option for openshift docker build strategy ### 4.0.0-M2 (2018-12-14) * Fix 10: Make VolumeConfiguration more flexible From 37cdbafde4bca6adc1077a294244df51a90036eb Mon Sep 17 00:00:00 2001 From: bohmber Date: Thu, 10 Jan 2019 15:29:45 +0100 Subject: [PATCH 5/5] Allow to configure noCache option for openshift docker build strategy Signed-off-by: bohmber --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61199c818b..02da2f0548 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,6 @@ After this we will switch probably to real [Semantic Versioning 2.0.0](http://se * Fix 1460: Upgraded kubernetes client to 4.1.1 * Fix 690: Removes deprecated _legacyPortMapping_ property. * Fix 1458: Support for from Image configuration in openshift docker build strategy -* Fix 1466: Allow to configure noCache option for openshift docker build strategy * Fix 732: Added 'skip' options to goals. * Fix 1466: Allow to configure noCache option for openshift docker build strategy