forked from eclipse-jkube/jkube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This pull request shall port the following PRs: fabric8io/fabric8-maven-plugin#1675 fabric8io/fabric8-maven-plugin#1734 fabric8io/fabric8-maven-plugin#1739 fabric8io/fabric8-maven-plugin#1740
- Loading branch information
1 parent
141f267
commit d1db55c
Showing
16 changed files
with
544 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
...build/service/docker/src/main/java/io/jkube/kit/build/service/docker/JibBuildService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package io.jkube.kit.build.service.docker; | ||
|
||
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.jkube.kit.build.maven.MavenBuildContext; | ||
import io.jkube.kit.build.service.docker.helper.DeepCopy; | ||
import io.jkube.kit.build.service.docker.helper.JibBuildServiceUtil; | ||
import io.jkube.kit.common.KitLogger; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Objects; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
public class JibBuildService { | ||
|
||
private KitLogger log; | ||
private BuildService.BuildContext dockerBuildContext; | ||
private MavenBuildContext mojoParameters; | ||
|
||
public JibBuildService(BuildService.BuildContext dockerBuildContext, MavenBuildContext mojoParameters, KitLogger log) { | ||
Objects.requireNonNull(dockerBuildContext, "dockerBuildContext"); | ||
this.dockerBuildContext = dockerBuildContext; | ||
this.mojoParameters = mojoParameters; | ||
this.log = log; | ||
} | ||
|
||
public void buildImage(ImageConfiguration imageConfiguration, boolean isOfflineMode) { | ||
try { | ||
doJibBuild(JibBuildServiceUtil.getJibBuildConfiguration(dockerBuildContext, mojoParameters, imageConfiguration, log), isOfflineMode); | ||
} catch (Exception ex) { | ||
throw new UnsupportedOperationException(ex); | ||
} | ||
} | ||
|
||
public JibContainer doJibBuild(JibBuildService.JibBuildConfiguration jibBuildConfiguration, boolean isOfflineMode) throws InvalidImageReferenceException, RegistryException, ExecutionException { | ||
return JibBuildServiceUtil.buildImage(jibBuildConfiguration, log, isOfflineMode); | ||
} | ||
|
||
public static class JibBuildConfiguration { | ||
private ImageConfiguration imageConfiguration; | ||
|
||
private ImageFormat imageFormat; | ||
|
||
private Credential credential; | ||
|
||
private Path fatJarPath; | ||
|
||
private String targetDir; | ||
|
||
private String outputDir; | ||
|
||
private JibBuildConfiguration() {} | ||
|
||
public ImageConfiguration getImageConfiguration() { return imageConfiguration; } | ||
|
||
public String getTargetDir() { | ||
return targetDir; | ||
} | ||
|
||
public String getOutputDir() { | ||
return outputDir; | ||
} | ||
|
||
public Credential getCredential() { | ||
return credential; | ||
} | ||
|
||
public Path getFatJar() { | ||
return fatJarPath; | ||
} | ||
|
||
public ImageFormat getImageFormat() { | ||
return imageFormat; | ||
} | ||
|
||
public static class Builder { | ||
private final JibBuildConfiguration configutil; | ||
private final KitLogger logger; | ||
|
||
public Builder(KitLogger logger) { | ||
this(null, logger); | ||
} | ||
|
||
public Builder(JibBuildConfiguration that, KitLogger logger) { | ||
this.logger = logger; | ||
if (that == null) { | ||
this.configutil = new JibBuildConfiguration(); | ||
} else { | ||
this.configutil = DeepCopy.copy(that); | ||
} | ||
} | ||
|
||
public Builder imageConfiguration(ImageConfiguration imageConfiguration) { | ||
configutil.imageConfiguration = imageConfiguration; | ||
return this; | ||
} | ||
|
||
public Builder imageFormat(ImageFormat imageFormat) { | ||
configutil.imageFormat = imageFormat; | ||
return this; | ||
} | ||
|
||
public Builder credential(Credential credential) { | ||
configutil.credential = credential; | ||
return this; | ||
} | ||
|
||
public Builder buildDirectory(String buildDir) { | ||
configutil.fatJarPath = JibBuildServiceUtil.getFatJar(buildDir, logger); | ||
return this; | ||
} | ||
|
||
public Builder targetDir(String targetDir) { | ||
configutil.targetDir = targetDir; | ||
return this; | ||
} | ||
|
||
public Builder outputDir(String outputDir) { | ||
configutil.outputDir = outputDir; | ||
return this; | ||
} | ||
|
||
public JibBuildConfiguration build() { | ||
return configutil; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.