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

Add skipPush option to build image configuration (#1243) #1368

Merged
merged 5 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions src/main/asciidoc/inc/build/_configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ a| Scan the archive specified in `dockerArchive` and find the actual repository
| *skip*
| if set to true disables building of the image. This config option is best used together with a maven property

| *skipPush*
| if set to true disables pushing of the image. This config option is best used together with a maven property

| *skipTag*
| If set to `true` this plugin won't add any tags to images. Property: `docker.skip.tag`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ public class BuildImageConfiguration implements Serializable {
@Parameter
private Boolean skip;

@Parameter
private Boolean skipPush;

@Parameter
private ArchiveCompression compression = ArchiveCompression.none;

Expand Down Expand Up @@ -325,6 +328,10 @@ public boolean skip() {
return skip != null ? skip : false;
}

public boolean skipPush() {
return skipPush != null ? skipPush : false;
}

public Boolean getNoCache() {
return noCache != null ? noCache : nocache;
}
Expand All @@ -337,6 +344,10 @@ public Boolean getSkip() {
return skip;
}

public Boolean getSkipPush() {
return skipPush;
}

public ArchiveCompression getCompression() {
return compression;
}
Expand Down Expand Up @@ -583,6 +594,11 @@ public Builder skip(Boolean skip) {
return this;
}

public Builder skipPush(Boolean skipPush) {
config.skipPush = skipPush;
return this;
}

public Builder buildOptions(Map<String,String> buildOptions) {
config.buildOptions = buildOptions;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public enum ConfigKey {
SECURITY_OPTS,
SHMSIZE,
SKIP_BUILD("skip.build"),
SKIP_PUSH,
SKIP_RUN("skip.run"),
STOP_NAME_PATTERN,
TAGS(ValueCombinePolicy.Merge),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ private BuildImageConfiguration extractBuildConfiguration(ImageConfiguration fro
.maintainer(valueProvider.getString(MAINTAINER, config == null ? null : config.getMaintainer()))
.workdir(valueProvider.getString(WORKDIR, config == null ? null : config.getWorkdir()))
.skip(valueProvider.getBoolean(SKIP_BUILD, config == null ? null : config.getSkip()))
.skipPush(valueProvider.getBoolean(SKIP_PUSH, config == null ? null : config.getSkipPush()))
.imagePullPolicy(valueProvider.getString(IMAGE_PULL_POLICY_BUILD, config == null ? null : config.getImagePullPolicy()))
.contextDir(valueProvider.getString(CONTEXT_DIR, config == null ? null : config.getContextDirRaw()))
.dockerArchive(valueProvider.getString(DOCKER_ARCHIVE, config == null ? null : config.getDockerArchiveRaw()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public void pushImages(Collection<ImageConfiguration> imageConfigs,
int retries, RegistryConfig registryConfig, boolean skipTag) throws DockerAccessException, MojoExecutionException {
for (ImageConfiguration imageConfig : imageConfigs) {
BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
if (buildConfig.skipPush()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know there is a test missing in RegistryServiceTest for pushImages, but it would be cool if you could add one to test this change, too (then the Sonar check would be happy, too). It shouldn't be hard to add, as it should work the same as the pull test, too.

log.info("%s : Skipped pushing", imageConfig.getDescription());
continue;
}

String name = imageConfig.getName();
if (buildConfig != null) {
String configuredRegistry = EnvUtil.firstRegistryOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ public void testSkipBuild() {
assertFalse(resolveExternalImageConfig(new String[] {k(ConfigKey.NAME), "image", k(ConfigKey.FROM), "busybox"}).getBuildConfiguration().skip());
}

@Test
public void testSkipPush() {
assertFalse(resolveExternalImageConfig(getSkipTestData(ConfigKey.SKIP_PUSH, false)).getBuildConfiguration().skipPush());
assertTrue(resolveExternalImageConfig(getSkipTestData(ConfigKey.SKIP_PUSH, true)).getBuildConfiguration().skipPush());

assertFalse(resolveExternalImageConfig(new String[] {k(ConfigKey.NAME), "image", k(ConfigKey.FROM), "busybox"}).getBuildConfiguration().skipPush());
}

@Test
public void testSkipRun() {
assertFalse(resolveExternalImageConfig(getSkipTestData(ConfigKey.SKIP_RUN, false)).getRunConfiguration().skip());
Expand Down