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

Commit

Permalink
Jib refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Devang Gaur committed Jan 6, 2020
1 parent c065082 commit acc895c
Show file tree
Hide file tree
Showing 10 changed files with 498 additions and 337 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ After this we will switch probably to real [Semantic Versioning 2.0.0](http://se
* Fix #797: spring-boot generator can not handle multi-profile configuration
* Fix #1751: Build Names are suffixed with -*s2i regardless of build strategy
* Fix #1755: Spring boot enricher does not produce a proper heath check and liveness check path when "/" is used.

* Refator #1766: Jib Refactor
### 4.3.1 (18-10-2019)
* Updated Kubernetes client to 4.6.1
* Fix #1725: Update jackson to 2.10.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public interface BuildService {
*/
void postProcess(BuildServiceConfig config);

default BuildServiceConfig getBuildServiceConfig() {
return null;
}
/**
* Class to hold configuration parameters for the building service.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
*/
package io.fabric8.maven.core.service.kubernetes;

import com.google.cloud.tools.jib.api.Credential;
import com.google.cloud.tools.jib.api.RegistryImage;
import io.fabric8.maven.core.service.BuildService;
import io.fabric8.maven.core.util.JibBuildServiceUtil;
import io.fabric8.maven.core.util.JibServiceUtil;
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 java.nio.file.Path;
Expand All @@ -46,23 +44,8 @@ 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);
JibBuildService.JibBuildConfiguration jibBuildConfiguration = JibServiceUtil.getJibBuildConfiguration(config, imageConfiguration, log);
JibServiceUtil.buildImage(jibBuildConfiguration, log);
} catch (Exception ex) {
throw new UnsupportedOperationException(ex);
}
Expand All @@ -73,15 +56,22 @@ public void postProcess(BuildServiceConfig config) {

}

@Override
public BuildServiceConfig getBuildServiceConfig() {
return config;
}

public static class JibBuildConfiguration {

private Map<String, String> envMap;

private Credential credential;
private Map<String, String> labels;

private List<String> volumes;

private List<String> ports;

private String from;
private RegistryImage from;

private String target;

Expand All @@ -93,6 +83,8 @@ public static class JibBuildConfiguration {

private String outputDir;

private String workDir;

private JibBuildConfiguration() {}

public Arguments getEntryPoint() {
Expand All @@ -111,15 +103,15 @@ public Map<String, String> getEnvMap() {
return envMap;
}

public Credential getCredential() {
return credential;
}
public Map<String, String> getLabels() { return labels; }

public List<String> getVolumes() { return volumes; }

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

public String getFrom() {
public RegistryImage getFrom() {
return from;
}

Expand All @@ -131,8 +123,10 @@ public Path getFatJar() {
return fatJarPath;
}

public String getWorkDir() { return workDir; }

public static class Builder {
private final JibBuildConfiguration configutil;
private final JibBuildConfiguration jibBuildConfiguration;
private final Logger logger;

public Builder(Logger logger) {
Expand All @@ -142,59 +136,68 @@ public Builder(Logger logger) {
public Builder(JibBuildConfiguration that, Logger logger) {
this.logger = logger;
if (that == null) {
this.configutil = new JibBuildConfiguration();
this.jibBuildConfiguration = new JibBuildConfiguration();
} else {
this.configutil = DeepCopy.copy(that);
this.jibBuildConfiguration = DeepCopy.copy(that);
}
}

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

public Builder credential(Credential credential) {
configutil.credential = credential;
public Builder labels(Map<String, String> labels) {
jibBuildConfiguration.labels = labels;
return this;
}

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

public Builder from(String from) {
configutil.from = from;
public Builder from(RegistryImage from) {
jibBuildConfiguration.from = from;
return this;
}

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

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

public Builder buildDirectory(String buildDir) {
configutil.fatJarPath = JibBuildServiceUtil.getFatJar(buildDir, logger);
jibBuildConfiguration.fatJarPath = JibServiceUtil.getFatJar(buildDir, logger);
return this;
}

public Builder workingDirectory(String workDir) {
jibBuildConfiguration.workDir = workDir;
return this;
}

public Builder targetDir(String targetDir) {
configutil.targetDir = targetDir;
jibBuildConfiguration.targetDir = targetDir;
return this;
}

public Builder outputDir(String outputDir) {
configutil.outputDir = outputDir;
jibBuildConfiguration.outputDir = outputDir;
return this;
}

public JibBuildConfiguration build() {
return configutil;
return jibBuildConfiguration;
}
}
}
Expand Down
Loading

0 comments on commit acc895c

Please sign in to comment.