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

Respect disabling container-image build #22317

Merged
merged 1 commit into from
Dec 17, 2021
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
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