use of org.eclipse.jkube.kit.config.image.build.BuildConfiguration in project jkube by eclipse.
the class ConfigHelper method initImageConfiguration.
public static List<ImageConfiguration> initImageConfiguration(String apiVersion, Date buildTimeStamp, List<ImageConfiguration> images, ImageConfigResolver imageConfigResolver, KitLogger log, String filter, ConfigHelper.Customizer customizer, JKubeConfiguration jKubeConfiguration) {
List<ImageConfiguration> resolvedImages;
ImageNameFormatter imageNameFormatter = new ImageNameFormatter(jKubeConfiguration.getProject(), buildTimeStamp);
// Resolve images
resolvedImages = ConfigHelper.resolveImages(log, // Unresolved images
images, (ImageConfiguration image) -> imageConfigResolver.resolve(image, jKubeConfiguration.getProject()), // A filter which image to process
filter, // customizer (can be overwritten by a subclass)
customizer);
// Check for simple Dockerfile mode
if (isSimpleDockerFileMode(jKubeConfiguration.getBasedir())) {
File topDockerfile = getTopLevelDockerfile(jKubeConfiguration.getBasedir());
String defaultImageName = imageNameFormatter.format(getValueFromProperties(jKubeConfiguration.getProject().getProperties(), "jkube.image.name", "jkube.generator.name"));
if (resolvedImages.isEmpty()) {
resolvedImages.add(createSimpleDockerfileConfig(topDockerfile, defaultImageName));
} else if (resolvedImages.size() == 1 && resolvedImages.get(0).getBuildConfiguration() == null) {
resolvedImages.set(0, addSimpleDockerfileConfig(resolvedImages.get(0), topDockerfile));
}
}
// Initialize configuration and detect minimal API version
ConfigHelper.initAndValidate(resolvedImages, apiVersion, imageNameFormatter);
for (ImageConfiguration image : resolvedImages) {
BuildConfiguration buildConfiguration = image.getBuildConfiguration();
if (buildConfiguration != null && buildConfiguration.isDockerFileMode()) {
log.info("Using Dockerfile: %s", buildConfiguration.getDockerFile().getAbsolutePath());
log.info("Using Docker Context Directory: %s", buildConfiguration.getAbsoluteContextDirPath(jKubeConfiguration.getSourceDirectory(), jKubeConfiguration.getBasedir().getAbsolutePath()));
}
}
return resolvedImages;
}
use of org.eclipse.jkube.kit.config.image.build.BuildConfiguration in project jkube by eclipse.
the class DeploymentHandlerTest method before.
@Before
public void before() {
// volume config with name and multiple mount
mounts.add("/path/system");
mounts.add("/path/sys");
ports.add("8080");
ports.add("9090");
tags.add("latest");
tags.add("test");
VolumeConfig volumeConfig1 = VolumeConfig.builder().name("test").mounts(mounts).type("hostPath").path("/test/path").build();
volumes1.add(volumeConfig1);
// container name with alias
final BuildConfiguration buildImageConfiguration = BuildConfiguration.builder().ports(ports).from("fabric8/maven:latest").cleanup("try").tags(tags).compressionString("gzip").build();
ImageConfiguration imageConfiguration = ImageConfiguration.builder().name("test").alias("test-app").build(buildImageConfiguration).registry("docker.io").build();
images.add(imageConfiguration);
deploymentHandler = new DeploymentHandler(new PodTemplateHandler(new ContainerHandler(project.getProperties(), new GroupArtifactVersion("g", "a", "v"), probeHandler)));
}
use of org.eclipse.jkube.kit.config.image.build.BuildConfiguration in project jkube by eclipse.
the class AssemblyConfigurationUtilsTest method createDockerFileBuilder_withAssemblyAndFilesInSingleLayer_shouldReturnTransformedContent.
@Test
public void createDockerFileBuilder_withAssemblyAndFilesInSingleLayer_shouldReturnTransformedContent() {
// Given
final BuildConfiguration buildConfig = BuildConfiguration.builder().user("1000").maintainer("Alex").build();
final AssemblyConfiguration assemblyConfiguration = AssemblyConfiguration.builder().targetDir("/deployments").layer(Assembly.builder().id("layer-with-id").build()).layer(new Assembly()).build();
final Map<Assembly, List<AssemblyFileEntry>> layers = assemblyConfiguration.getLayers().stream().collect(Collectors.toMap(Function.identity(), a -> Collections.singletonList(new AssemblyFileEntry(new File(""), new File(""), null))));
layers.put(new Assembly(), Collections.emptyList());
// When
final String result = createDockerFileBuilder(buildConfig, assemblyConfiguration, layers).content();
// Then
assertThat(result).isEqualTo("FROM busybox\n" + "MAINTAINER Alex\n" + "COPY /layer-with-id/deployments /deployments/\n" + "VOLUME [\"/deployments\"]\n" + "USER 1000\n");
}
use of org.eclipse.jkube.kit.config.image.build.BuildConfiguration in project jkube by eclipse.
the class AssemblyConfigurationUtilsTest method createDockerFileBuilder_withAssemblyAndFiles_shouldReturnTransformedContent.
@Test
public void createDockerFileBuilder_withAssemblyAndFiles_shouldReturnTransformedContent() {
// Given
final BuildConfiguration buildConfig = BuildConfiguration.builder().putEnv("ENV_VAR", "VALUE").label("LABEL", "LABEL_VALUE").port("8080").user("1000").volume("VOLUME").runCmd("chown -R 1000:1000 /opt").maintainer("Alex").cmd(Arguments.builder().execArgument("sh").execArgument("-c").execArgument("server").build()).build();
final AssemblyConfiguration assemblyConfiguration = AssemblyConfiguration.builder().targetDir("/deployments").layer(Assembly.builder().id("layer-with-id").build()).layer(Assembly.builder().build()).build();
final Map<Assembly, List<AssemblyFileEntry>> layers = assemblyConfiguration.getLayers().stream().collect(Collectors.toMap(Function.identity(), a -> Collections.singletonList(new AssemblyFileEntry(new File(""), new File(""), null))));
// When
final String result = createDockerFileBuilder(buildConfig, assemblyConfiguration, layers).content();
// Then
assertThat(result).isEqualTo("FROM busybox\n" + "MAINTAINER Alex\n" + "ENV ENV_VAR=VALUE\n" + "LABEL LABEL=LABEL_VALUE\n" + "EXPOSE 8080\n" + "COPY /layer-with-id/deployments /deployments/\n" + "COPY /deployments /deployments/\n" + "RUN chown -R 1000:1000 /opt\n" + "VOLUME [\"/deployments\"]\n" + "VOLUME [\"VOLUME\"]\n" + "CMD [\"sh\",\"-c\",\"server\"]\n" + "USER 1000\n");
}
use of org.eclipse.jkube.kit.config.image.build.BuildConfiguration in project jkube by eclipse.
the class AssemblyManagerCreateDockerTarArchiveTest method withDockerfileInBaseDirectory.
@Test
public void withDockerfileInBaseDirectory() throws IOException {
// Given
final File dockerFile = new File(baseDirectory, "Dockerfile");
writeLineToFile(dockerFile, "FROM openjdk:jre");
final JKubeConfiguration configuration = createJKubeConfiguration();
final BuildConfiguration jKubeBuildConfiguration = BuildConfiguration.builder().dockerFileFile(dockerFile).dockerFile(dockerFile.getPath()).build();
// When
File dockerArchiveFile = assemblyManager.createDockerTarArchive("test-image", configuration, jKubeBuildConfiguration, prefixedLogger, null);
// Then
assertTargetHasDockerDirectories("test-image");
ArchiveAssertions.assertThat(dockerArchiveFile).isFile().hasName("docker-build.tar").hasSameContentAsDirectory(getExpectedDirectory("with-dockerfile-in-base-directory"));
assertDockerFile("test-image").hasContent("FROM openjdk:jre\n");
assertBuildDirectoryFileTree("test-image").containsExactlyInAnyOrder("Dockerfile", "maven", "maven/Dockerfile", "maven/test-0.1.0.jar", "maven/target", "maven/target/test-0.1.0.jar");
}
Aggregations