Skip to content

Commit

Permalink
fix: respect disabling container-image build
Browse files Browse the repository at this point in the history
  • Loading branch information
iocanel committed Dec 17, 2021
1 parent 9d5f9cb commit 9e3b813
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ public void dockerBuildFromJar(DockerConfig dockerConfig,
@SuppressWarnings("unused") // used to ensure that the jar has been built
JarBuildItem jar) {

if (!containerImageConfig.build && !containerImageConfig.push && !buildRequest.isPresent()
&& !pushRequest.isPresent()) {
if (containerImageConfig.isBuildExplicitlyDisabled()) {
return;
}

if (!containerImageConfig.isBuildExplicitlyEnabled() && !containerImageConfig.isPushExplicitlyEnabled()
&& !buildRequest.isPresent() && !pushRequest.isPresent()) {
return;
}

Expand Down Expand Up @@ -104,8 +108,12 @@ public void dockerBuildFromNativeImage(DockerConfig dockerConfig,
// used to ensure that the native binary has been built
NativeImageBuildItem nativeImage) {

if (!containerImageConfig.build && !containerImageConfig.push && !buildRequest.isPresent()
&& !pushRequest.isPresent()) {
if (containerImageConfig.isBuildExplicitlyDisabled()) {
return;
}

if (!containerImageConfig.isBuildExplicitlyEnabled() && !containerImageConfig.isPushExplicitlyEnabled()
&& !buildRequest.isPresent() && !pushRequest.isPresent()) {
return;
}

Expand Down Expand Up @@ -151,7 +159,7 @@ private String createContainerImage(ContainerImageConfig containerImageConfig, D
createAdditionalTags(containerImageInfo.getImage(), containerImageInfo.getAdditionalImageTags(), dockerConfig);
}

if (pushRequested || containerImageConfig.push) {
if (pushRequested || containerImageConfig.isPushExplicitlyEnabled()) {
String registry = "docker.io";
if (!containerImageInfo.getRegistry().isPresent()) {
log.info("No container image registry was set, so 'docker.io' will be used");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public AvailableContainerImageExtensionBuildItem availability() {
public void appCDS(ContainerImageConfig containerImageConfig, JibConfig jibConfig,
BuildProducer<AppCDSContainerImageBuildItem> producer) {

if (!containerImageConfig.build && !containerImageConfig.push) {
if (!containerImageConfig.isBuildExplicitlyEnabled() && !containerImageConfig.isPushExplicitlyEnabled()) {
return;
}

Expand All @@ -110,8 +110,10 @@ public void buildFromJar(ContainerImageConfig containerImageConfig, JibConfig ji
Optional<AppCDSResultBuildItem> appCDSResult,
BuildProducer<ArtifactResultBuildItem> artifactResultProducer) {

Boolean buildContainerImage = containerImageConfig.build || buildRequest.isPresent();
Boolean pushContainerImage = containerImageConfig.push || pushRequest.isPresent();
Boolean buildContainerImage = containerImageConfig.isBuildExplicitlyEnabled()
|| (buildRequest.isPresent() && !containerImageConfig.isBuildExplicitlyDisabled());
Boolean pushContainerImage = containerImageConfig.isPushExplicitlyEnabled()
|| (pushRequest.isPresent() && !containerImageConfig.isPushExplicitlyDisabled());
if (!buildContainerImage && !pushContainerImage) {
return;
}
Expand Down Expand Up @@ -151,8 +153,10 @@ public void buildFromNative(ContainerImageConfig containerImageConfig, JibConfig
List<ContainerImageLabelBuildItem> containerImageLabels,
BuildProducer<ArtifactResultBuildItem> artifactResultProducer) {

Boolean buildContainerImage = containerImageConfig.build || buildRequest.isPresent();
Boolean pushContainerImage = containerImageConfig.push || pushRequest.isPresent();
Boolean buildContainerImage = containerImageConfig.isBuildExplicitlyEnabled()
|| (buildRequest.isPresent() && !containerImageConfig.isBuildExplicitlyDisabled());
Boolean pushContainerImage = containerImageConfig.isPushExplicitlyEnabled()
|| (pushRequest.isPresent() && !containerImageConfig.isPushExplicitlyDisabled());
if (!buildContainerImage && !pushContainerImage) {
return;
}
Expand Down Expand Up @@ -187,7 +191,7 @@ private JibContainer containerize(ContainerImageConfig containerImageConfig,
log.info("Starting container image build");
JibContainer container = jibContainerBuilder.containerize(containerizer);
log.infof("%s container image %s (%s)\n",
containerImageConfig.push ? "Pushed" : "Created",
containerImageConfig.isPushExplicitlyEnabled() ? "Pushed" : "Created",
container.getTargetImage(),
container.getDigest());
return container;
Expand All @@ -203,7 +207,7 @@ private Containerizer createContainerizer(ContainerImageConfig containerImageCon
ImageReference imageReference = ImageReference.of(containerImage.getRegistry().orElse(null),
containerImage.getRepository(), containerImage.getTag());

if (pushRequested || containerImageConfig.push) {
if (pushRequested || containerImageConfig.isPushExplicitlyEnabled()) {
if (!containerImageConfig.registry.isPresent()) {
log.info("No container image registry was set, so 'docker.io' will be used");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,12 @@ public void openshiftBuildFromJar(OpenshiftConfig openshiftConfig,
JarBuildItem jar) {

OpenshiftConfig config = mergeConfig(openshiftConfig, s2iConfig);
if (!containerImageConfig.build && !containerImageConfig.push && !buildRequest.isPresent()
&& !pushRequest.isPresent()) {
if (containerImageConfig.isBuildExplicitlyDisabled()) {
return;
}

if (!containerImageConfig.isBuildExplicitlyEnabled() && !containerImageConfig.isPushExplicitlyEnabled()
&& !buildRequest.isPresent() && !pushRequest.isPresent()) {
return;
}

Expand Down Expand Up @@ -283,8 +287,13 @@ public void openshiftBuildFromNative(OpenshiftConfig openshiftConfig, S2iConfig
NativeImageBuildItem nativeImage) {

OpenshiftConfig config = mergeConfig(openshiftConfig, s2iConfig);
if (!containerImageConfig.build && !containerImageConfig.push && !buildRequest.isPresent()
&& !pushRequest.isPresent()) {

if (containerImageConfig.isBuildExplicitlyDisabled()) {
return;
}

if (!containerImageConfig.isBuildExplicitlyEnabled() && !containerImageConfig.isPushExplicitlyEnabled()
&& !buildRequest.isPresent() && !pushRequest.isPresent()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,12 @@ public void s2iBuildFromJar(S2iConfig s2iConfig, ContainerImageConfig containerI
// used to ensure that the jar has been built
JarBuildItem jar) {

if (!containerImageConfig.build && !containerImageConfig.push && !buildRequest.isPresent()
&& !pushRequest.isPresent()) {
if (containerImageConfig.isBuildExplicitlyDisabled()) {
return;
}

if (!containerImageConfig.isBuildExplicitlyEnabled() && !containerImageConfig.isPushExplicitlyEnabled()
&& !buildRequest.isPresent() && !pushRequest.isPresent()) {
return;
}

Expand Down Expand Up @@ -212,8 +216,12 @@ public void s2iBuildFromNative(S2iConfig s2iConfig, ContainerImageConfig contain
BuildProducer<ArtifactResultBuildItem> artifactResultProducer,
NativeImageBuildItem nativeImage) {

if (!containerImageConfig.build && !containerImageConfig.push && !buildRequest.isPresent()
&& !pushRequest.isPresent()) {
if (containerImageConfig.isBuildExplicitlyDisabled()) {
return;
}

if (!containerImageConfig.isBuildExplicitlyEnabled() && !containerImageConfig.isPushExplicitlyEnabled()
&& !buildRequest.isPresent() && !pushRequest.isPresent()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ public class ContainerImageConfig {
* Whether or not a image build will be performed.
*/
@ConfigItem
public boolean build;
public Optional<Boolean> build;

/**
* Whether or not an image push will be performed.
*/
@ConfigItem
public boolean push;
public Optional<Boolean> push;

/**
* The name of the container image extension to use (e.g. docker, jib, s2i).
Expand All @@ -95,6 +95,22 @@ public class ContainerImageConfig {
@ConfigItem
public Optional<String> builder;

public boolean isBuildExplicitlyEnabled() {
return build.isPresent() && build.get();
}

public boolean isBuildExplicitlyDisabled() {
return build.isPresent() && !build.get();
}

public boolean isPushExplicitlyEnabled() {
return push.isPresent() && push.get();
}

public boolean isPushExplicitlyDisabled() {
return push.isPresent() && !push.get();
}

/**
* Since user.name which is default value can be uppercase and uppercase values are not allowed
* in the repository part of image references, we need to make the username lowercase.
Expand Down

0 comments on commit 9e3b813

Please sign in to comment.