Skip to content

Commit

Permalink
fix: add missing properties to PropertyConfigResolver
Browse files Browse the repository at this point in the history
+ 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 <[email protected]>
  • Loading branch information
rohanKanojia authored Jun 25, 2024
1 parent 060503a commit 8435d6b
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -41,7 +45,6 @@ public enum ConfigKey {
ENTRYPOINT,
ENV,
ENV_BUILD("envBuild", ValueCombinePolicy.MERGE),
ENV_RUN("envRun", ValueCombinePolicy.MERGE),
FILTER,
FROM,
FROM_EXT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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))
Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions jkube-kit/doc/src/main/asciidoc/inc/build/_assembly.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ logic (see <<jkube-plugin, JKube Plugin>> 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 <<external-dockerfile,external Dockerfile>> 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.
Expand All @@ -40,7 +40,7 @@ logic (see <<jkube-plugin, JKube Plugin>> 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:
Expand Down
4 changes: 2 additions & 2 deletions jkube-kit/doc/src/main/asciidoc/inc/build/_configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

| <<registry, *registry*>>
| Registry to use for this image. If the `name` already contains a registry this takes precedence. See <<registry,Registry handling>> for more details.
|
| `jkube.container-image.registry`

| <<config-image-build, *build*>>
|
Expand Down

0 comments on commit 8435d6b

Please sign in to comment.