Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
Fix #1738: JibBuildConfiguration ignores BuildImageConfiguration.regi…
Browse files Browse the repository at this point in the history
…stry
  • Loading branch information
rohanKanojia committed Oct 18, 2019
1 parent 5b772a8 commit 9b2a241
Show file tree
Hide file tree
Showing 5 changed files with 271 additions and 190 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ After this we will switch probably to real [Semantic Versioning 2.0.0](http://se
* Fix #1732: Correctly replacing template placeholders in helm chart
* Fix #1734: Add logging during jib builds
* Fix #1696: Fix put operations for ImageStreams in ApplyService
* Fix #1738: JibBuildConfiguration ignores BuildImageConfiguration.registry
* Fix #1737: Wrong Jib output directory in Maven multi-module build

### 4.3.0 (04-10-2019)
* Updated custom-enricher sample
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@
package io.fabric8.maven.core.service.kubernetes;

import com.google.cloud.tools.jib.api.Credential;
import com.google.cloud.tools.jib.api.ImageFormat;
import com.google.cloud.tools.jib.api.InvalidImageReferenceException;
import com.google.cloud.tools.jib.api.JibContainer;
import com.google.cloud.tools.jib.api.RegistryException;
import io.fabric8.maven.core.service.BuildService;
import io.fabric8.maven.core.util.JibBuildServiceUtil;
import io.fabric8.maven.docker.config.Arguments;
import io.fabric8.maven.docker.config.BuildImageConfiguration;
import io.fabric8.maven.docker.config.ImageConfiguration;
import io.fabric8.maven.docker.util.DeepCopy;
import io.fabric8.maven.docker.util.ImageName;
import io.fabric8.maven.docker.util.Logger;
import io.fabric8.maven.docker.util.MojoParameters;

import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ExecutionException;

public class JibBuildService implements BuildService {

Expand All @@ -46,23 +47,7 @@ public JibBuildService (BuildServiceConfig config, Logger log) {
@Override
public void build(ImageConfiguration imageConfiguration) {
try {
BuildImageConfiguration buildImageConfiguration = imageConfiguration.getBuildConfiguration();
List<String> tags = buildImageConfiguration.getTags();

JibBuildService.JibBuildConfiguration jibBuildConfiguration;
String fullName = "";
if (tags.size() > 0) {
for (String tag : tags) {
if (tag != null) {
fullName = new ImageName(imageConfiguration.getName(), tag).getFullName();
}
}
} else {
fullName = new ImageName(imageConfiguration.getName(), null).getFullName();
}
log.info("Image tagging successful!");
jibBuildConfiguration = JibBuildServiceUtil.getJibBuildConfiguration(config, buildImageConfiguration, fullName, log);
JibBuildServiceUtil.buildImage(jibBuildConfiguration, log);
doJibBuild(JibBuildServiceUtil.getJibBuildConfiguration(config, imageConfiguration, log));
} catch (Exception ex) {
throw new UnsupportedOperationException(ex);
}
Expand All @@ -73,31 +58,32 @@ public void postProcess(BuildServiceConfig config) {

}

public static class JibBuildConfiguration {

private Map<String, String> envMap;
public JibContainer doJibBuild(JibBuildService.JibBuildConfiguration jibBuildConfiguration) throws InvalidImageReferenceException, RegistryException, ExecutionException {
return JibBuildServiceUtil.buildImage(jibBuildConfiguration, log);
}

private Credential credential;
public JibContainer doJibBuild(JibBuildService.JibBuildConfiguration jibBuildConfiguration, boolean isOfflineMode) throws InvalidImageReferenceException, RegistryException, ExecutionException {
return JibBuildServiceUtil.buildImage(jibBuildConfiguration, log, isOfflineMode);
}

private List<String> ports;
public static class JibBuildConfiguration {
private ImageConfiguration imageConfiguration;

private String from;
private ImageFormat imageFormat;

private String target;
private Credential credential;

private Path fatJarPath;

private Arguments entrypoint;

private String targetDir;

private String outputDir;

private MojoParameters mojoParameters;

private JibBuildConfiguration() {}

public Arguments getEntryPoint() {
return entrypoint;
}
public ImageConfiguration getImageConfiguration() { return imageConfiguration; }

public String getTargetDir() {
return targetDir;
Expand All @@ -107,29 +93,19 @@ public String getOutputDir() {
return outputDir;
}

public Map<String, String> getEnvMap() {
return envMap;
}

public Credential getCredential() {
return credential;
}

public List<String> getPorts() {
return ports;
}

public String getFrom() {
return from;
public Path getFatJar() {
return fatJarPath;
}

public String getTargetImage() {
return target;
public ImageFormat getImageFormat() {
return imageFormat;
}

public Path getFatJar() {
return fatJarPath;
}
public MojoParameters getMojoParameters() { return mojoParameters; }

public static class Builder {
private final JibBuildConfiguration configutil;
Expand All @@ -148,33 +124,23 @@ public Builder(JibBuildConfiguration that, Logger logger) {
}
}

public Builder envMap(Map<String, String> envMap) {
configutil.envMap = envMap;
return this;
}

public Builder credential(Credential credential) {
configutil.credential = credential;
public Builder mojoParameters(MojoParameters mojoParameters) {
configutil.mojoParameters = mojoParameters;
return this;
}

public Builder ports(List<String> ports) {
configutil.ports = ports;
public Builder imageConfiguration(ImageConfiguration imageConfiguration) {
configutil.imageConfiguration = imageConfiguration;
return this;
}

public Builder from(String from) {
configutil.from = from;
public Builder imageFormat(ImageFormat imageFormat) {
configutil.imageFormat = imageFormat;
return this;
}

public Builder targetImage(String imageName) {
configutil.target = imageName;
return this;
}

public Builder entrypoint(Arguments entrypoint) {
configutil.entrypoint = entrypoint;
public Builder credential(Credential credential) {
configutil.credential = credential;
return this;
}

Expand Down
Loading

0 comments on commit 9b2a241

Please sign in to comment.