From 8435d6b22bb1cbcc25c8576c308cc9efb7106363 Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Tue, 25 Jun 2024 18:28:50 +0530 Subject: [PATCH] fix: add missing properties to PropertyConfigResolver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + Remove ENV_RUN field from ConfigKey enum as it’s related to Docker Maven Plugin’s run configuration that has been removed from JKube codebase. + Add missing properties for the following fields: - `registry` -> `jkube.container-image.registry` - `buildpacksBuilderImage` -> `jkube.container-image.buildpacksBuilderImage` - `createImageOptions` -> `jkube.container-image.createImageOptions` - `assembly.name` -> `jkube.container-image.assembly.name` - `assembly.excludeFinalOutputArtifact` -> `jkube.container-image.assembly.excludeFinalOutputArtifact` Signed-off-by: Rohan Kumar --- .../build/api/config/property/ConfigKey.java | 5 +++- .../property/PropertyConfigResolver.java | 5 ++++ .../property/PropertyConfigResolverTest.java | 30 +++++++++++++++++++ .../main/asciidoc/inc/build/_assembly.adoc | 4 +-- .../asciidoc/inc/build/_configuration.adoc | 4 +-- .../asciidoc/inc/image/_configuration.adoc | 2 +- 6 files changed, 44 insertions(+), 6 deletions(-) diff --git a/jkube-kit/build/api/src/main/java/org/eclipse/jkube/kit/build/api/config/property/ConfigKey.java b/jkube-kit/build/api/src/main/java/org/eclipse/jkube/kit/build/api/config/property/ConfigKey.java index 053c7911a7..9756e4a980 100644 --- a/jkube-kit/build/api/src/main/java/org/eclipse/jkube/kit/build/api/config/property/ConfigKey.java +++ b/jkube-kit/build/api/src/main/java/org/eclipse/jkube/kit/build/api/config/property/ConfigKey.java @@ -23,16 +23,20 @@ public enum ConfigKey { ALIAS, ARGS(ValueCombinePolicy.MERGE), + ASSEMBLY_NAME("assembly.name"), ASSEMBLY_TARGET_DIR("assembly.targetDir"), ASSEMBLY_EXPORT_TARGET_DIR("assembly.exportTargetDir"), ASSEMBLY_PERMISSIONS("assembly.permissions"), ASSEMBLY_USER("assembly.user"), ASSEMBLY_MODE("assembly.mode"), ASSEMBLY_TARLONGFILEMODE("assembly.tarLongFileMode"), + ASSEMBLY_EXCLUDE_FINAL_OUTPUT_ARTIFACT("assembly.excludeFinalOutputArtifact"), + BUILDPACKS_BUILDER_IMAGE("buildpacksBuilderImage"), BUILD_OPTIONS, CLEANUP, NOCACHE, CACHEFROM, + CREATE_IMAGE_OPTIONS("createImageOptions"), OPTIMISE, CMD, CONTEXT_DIR, @@ -41,7 +45,6 @@ public enum ConfigKey { ENTRYPOINT, ENV, ENV_BUILD("envBuild", ValueCombinePolicy.MERGE), - ENV_RUN("envRun", ValueCombinePolicy.MERGE), FILTER, FROM, FROM_EXT, diff --git a/jkube-kit/build/api/src/main/java/org/eclipse/jkube/kit/build/api/config/property/PropertyConfigResolver.java b/jkube-kit/build/api/src/main/java/org/eclipse/jkube/kit/build/api/config/property/PropertyConfigResolver.java index 7c7b885d9a..a99b049e64 100644 --- a/jkube-kit/build/api/src/main/java/org/eclipse/jkube/kit/build/api/config/property/PropertyConfigResolver.java +++ b/jkube-kit/build/api/src/main/java/org/eclipse/jkube/kit/build/api/config/property/PropertyConfigResolver.java @@ -49,6 +49,7 @@ public final ImageConfiguration resolve(ImageConfiguration fromConfig, JavaProje return ImageConfiguration.builder() .name(valueProvider.getString(ConfigKey.NAME, fromConfig.getName())) .alias(valueProvider.getString(ConfigKey.ALIAS, fromConfig.getAlias())) + .registry(valueProvider.getString(ConfigKey.REGISTRY, fromConfig.getRegistry())) .build(extractBuildConfiguration(fromConfig, valueProvider)) .watch(extractWatchConfig(fromConfig, valueProvider)) .build(); @@ -66,10 +67,12 @@ private BuildConfiguration extractBuildConfiguration(ImageConfiguration fromConf final BuildConfiguration config = fromConfig.getBuild() != null ? fromConfig.getBuild() : new BuildConfiguration(); return config.toBuilder() + .buildpacksBuilderImage(valueProvider.getString(ConfigKey.BUILDPACKS_BUILDER_IMAGE, valueOrNull(config, BuildConfiguration::getBuildpacksBuilderImage))) .cmd(extractArguments(valueProvider, ConfigKey.CMD, valueOrNull(config, BuildConfiguration::getCmd))) .cleanup(valueProvider.getString(ConfigKey.CLEANUP, valueOrNull(config, BuildConfiguration::getCleanup))) .nocache(valueProvider.getBoolean(ConfigKey.NOCACHE, valueOrNull(config, BuildConfiguration::getNocache))) .clearCacheFrom().cacheFrom(valueProvider.getList(ConfigKey.CACHEFROM, valueOr(config, BuildConfiguration::getCacheFrom, Collections.emptyList()))) + .createImageOptions(valueProvider.getMap(ConfigKey.CREATE_IMAGE_OPTIONS, valueOrNull(config, BuildConfiguration::getCreateImageOptions))) .optimise(valueProvider.getBoolean(ConfigKey.OPTIMISE, valueOrNull(config, BuildConfiguration::getOptimise))) .entryPoint(extractArguments(valueProvider, ConfigKey.ENTRYPOINT, valueOrNull(config, BuildConfiguration::getEntryPoint))) .assembly(extractAssembly(valueOrNull(config, BuildConfiguration::getAssembly), valueProvider)) @@ -104,12 +107,14 @@ private BuildConfiguration extractBuildConfiguration(ImageConfiguration fromConf private AssemblyConfiguration extractAssembly(AssemblyConfiguration originalConfig, ValueProvider valueProvider) { final AssemblyConfiguration config = originalConfig != null ? originalConfig : new AssemblyConfiguration(); return config.toBuilder() + .name(valueProvider.getString(ConfigKey.ASSEMBLY_NAME, valueOrNull(originalConfig, AssemblyConfiguration::getName))) .targetDir(valueProvider.getString(ConfigKey.ASSEMBLY_TARGET_DIR, valueOrNull(originalConfig, AssemblyConfiguration::getTargetDir))) .exportTargetDir(valueProvider.getBoolean(ConfigKey.ASSEMBLY_EXPORT_TARGET_DIR, valueOrNull(originalConfig, AssemblyConfiguration::getExportTargetDir))) .permissionsString(valueProvider.getString(ConfigKey.ASSEMBLY_PERMISSIONS, valueOrNull(originalConfig, AssemblyConfiguration::getPermissionsRaw))) .user(valueProvider.getString(ConfigKey.ASSEMBLY_USER, valueOrNull(originalConfig, AssemblyConfiguration::getUser))) .modeString(valueProvider.getString(ConfigKey.ASSEMBLY_MODE, valueOrNull(originalConfig, AssemblyConfiguration::getModeRaw))) .tarLongFileMode(valueProvider.getString(ConfigKey.ASSEMBLY_TARLONGFILEMODE, valueOrNull(originalConfig, AssemblyConfiguration::getTarLongFileMode))) + .excludeFinalOutputArtifact(valueProvider.getBoolean(ConfigKey.ASSEMBLY_EXCLUDE_FINAL_OUTPUT_ARTIFACT, Optional.ofNullable(valueOrNull(originalConfig, AssemblyConfiguration::isExcludeFinalOutputArtifact)).orElse(false))) .build(); } diff --git a/jkube-kit/build/api/src/test/java/org/eclipse/jkube/kit/build/api/config/property/PropertyConfigResolverTest.java b/jkube-kit/build/api/src/test/java/org/eclipse/jkube/kit/build/api/config/property/PropertyConfigResolverTest.java index b3e3545ea0..ab57a9274f 100644 --- a/jkube-kit/build/api/src/test/java/org/eclipse/jkube/kit/build/api/config/property/PropertyConfigResolverTest.java +++ b/jkube-kit/build/api/src/test/java/org/eclipse/jkube/kit/build/api/config/property/PropertyConfigResolverTest.java @@ -77,6 +77,11 @@ void setUp() { javaProject.getProperties().put("jkube.container-image.platforms.1", "linux/amd64"); javaProject.getProperties().put("jkube.container-image.platforms.2", "linux/arm64"); javaProject.getProperties().put("jkube.container-image.healthcheck.interval", "10s"); + javaProject.getProperties().put("jkube.container-image.registry", "example-registry.io"); + javaProject.getProperties().put("jkube.container-image.buildpacksBuilderImage", "custom-pack-builder-image:latest"); + javaProject.getProperties().put("jkube.container-image.createImageOptions.platform", "linux/amd64"); + javaProject.getProperties().put("jkube.container-image.assembly.name", "assembly1"); + javaProject.getProperties().put("jkube.container-image.assembly.excludeFinalOutputArtifact", "false"); } @Test @@ -167,6 +172,31 @@ void setsPlatforms() { void setsHealthCheckInterval() { assertThat(resolved.getBuild().getHealthCheck().getInterval()).isEqualTo("10s"); } + + @Test + void setsRegistry() { + assertThat(resolved.getRegistry()).isEqualTo("example-registry.io"); + } + + @Test + void setsCreateImageOptions() { + assertThat(resolved.getBuild().getCreateImageOptions()).containsEntry("platform", "linux/amd64"); + } + + @Test + void setsBuildPackBuilderImage() { + assertThat(resolved.getBuild().getBuildpacksBuilderImage()).isEqualTo("custom-pack-builder-image:latest"); + } + + @Test + void setsAssemblyName() { + assertThat(resolved.getBuild().getAssembly().getName()).isEqualTo("assembly1"); + } + + @Test + void setsAssemblyExcludeFinalOutputArtifact() { + assertThat(resolved.getBuild().getAssembly().isExcludeFinalOutputArtifact()).isFalse(); + } } @Nested diff --git a/jkube-kit/doc/src/main/asciidoc/inc/build/_assembly.adoc b/jkube-kit/doc/src/main/asciidoc/inc/build/_assembly.adoc index 80554d2e60..a64ab52588 100644 --- a/jkube-kit/doc/src/main/asciidoc/inc/build/_assembly.adoc +++ b/jkube-kit/doc/src/main/asciidoc/inc/build/_assembly.adoc @@ -14,7 +14,7 @@ logic (see <> for more details). | Assembly name, which is `maven` by default. This name is used for the archives and directories created during the build. This directory holds the files specified by the assembly. If an <> is used then this name is also the relative directory which contains the assembly files. -| +| `jkube.container-image.assembly.name` | *targetDir* | Directory under which the files and artifacts contained in the assembly will be copied within the container. @@ -40,7 +40,7 @@ logic (see <> for more details). | *excludeFinalOutputArtifact* | By default, the project's final artifact will be included in the assembly, set this flag to true in case the artifact should be excluded from the assembly. -| +| `jkube.container-image.assembly.excludeFinalOutputArtifact` | *mode* a| Mode how the assembled files should be collected: diff --git a/jkube-kit/doc/src/main/asciidoc/inc/build/_configuration.adoc b/jkube-kit/doc/src/main/asciidoc/inc/build/_configuration.adoc index fb01d11b27..a966d221bf 100644 --- a/jkube-kit/doc/src/main/asciidoc/inc/build/_configuration.adoc +++ b/jkube-kit/doc/src/main/asciidoc/inc/build/_configuration.adoc @@ -30,7 +30,7 @@ https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#build-imag These options map to the ones listed as query parameters in the https://docs.docker.com/engine/api/v1.41/#operation/ImageCreate[Docker Remote API] and are restricted to simple options (e.g.: fromImage, fromSrc, platform). -| +| `jkube.container-image.createImageOptions` | *cleanup* | Cleanup dangling (untagged) images after each build (including any containers created from them). Default is `try` which tries to remove the old image, but doesn't fail the build if this is not possible because e.g. the image is still used by a running container. Use `remove` if you want to fail the build and `none` if no cleanup is requested. @@ -90,7 +90,7 @@ endif::[] | Configure https://buildpacks.io/docs/for-platform-operators/concepts/builder/[BuildPack builder] OCI image for BuildPack Build. This field is applicable only in `buildpacks` build strategy. This overrides builder image specified in local `~/.pack/config.toml`. If not specified this defaults to `null`. This field is only applicable for `buildpacks` build strategy. -| +| `jkube.container-image.buildpacksBuilderImage` | [[build-config-from-ext]]**fromExt** a| Extended definition for a base image. This field holds a map of defined in `key = "value"` format. The known keys are: diff --git a/jkube-kit/doc/src/main/asciidoc/inc/image/_configuration.adoc b/jkube-kit/doc/src/main/asciidoc/inc/image/_configuration.adoc index d4eb24e6af..5a279b4c5f 100644 --- a/jkube-kit/doc/src/main/asciidoc/inc/image/_configuration.adoc +++ b/jkube-kit/doc/src/main/asciidoc/inc/image/_configuration.adoc @@ -17,7 +17,7 @@ | <> | Registry to use for this image. If the `name` already contains a registry this takes precedence. See <> for more details. -| +| `jkube.container-image.registry` | <> |