Skip to content

Commit

Permalink
doc: updated docs for merging build args from multiple sources
Browse files Browse the repository at this point in the history
Signed-off-by: l3002 <[email protected]>
  • Loading branch information
l3002 committed Jan 17, 2025
1 parent 53a68cc commit fe19aa8
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,21 @@ public class BuildArgResolverUtil {

private static final String ARG_PREFIX = "docker.buildArg.";

private BuildArgResolverUtil() { }
private BuildArgResolverUtil() {
}

/**
* Merges Docker Build Args from the following sources:
* Merges Docker Build Args from the following source in the mentioned order of precedence (moving from higher to lower precedence):
* <ul>
* <li>Build Args specified directly in ImageConfiguration</li>
* <li>Build Args specified via System Properties</li>
* <li>Build Args specified via Project Properties</li>
* <li>Build Args specified via Plugin configuration</li>
* <li>Docker Proxy Build Args detected from ~/.docker/config.json</li>
* </ul>
*
* <i><b>Note:</b> When identical Build Args are specified in multiple sources, their values are overridden according to the established order of precedence. A warning is also logged to highlight the Build Arg and the updated value.</i>
*
* @param imageConfig ImageConfiguration where to get the Build Args from.
* @param configuration {@link JKubeConfiguration}.
* @return a Map containing merged Build Args from all sources.
Expand All @@ -59,13 +63,16 @@ public static Map<String, String> mergeBuildArgsIncludingLocalDockerConfigProxyS
}

/**
* Merges Docker Build Args from the following sources:
* Merges Docker Build Args from the following source in the mentioned order of precedence (moving from higher to lower precedence):
* <ul>
* <li>Build Args specified directly in ImageConfiguration</li>
* <li>Build Args specified via System Properties</li>
* <li>Build Args specified via Project Properties</li>
* <li>Build Args specified via Plugin configuration</li>
* </ul>
*
* <i><b>Note:</b> When identical Build Args are specified in multiple sources, their values are overridden according to the established order of precedence. A warning is also logged to highlight the Build Arg and the updated value.</i>
*
* @param imageConfig ImageConfiguration where to get the Build Args from.
* @param configuration {@link JKubeConfiguration}.
* @return a Map containing merged Build Args from all sources.
Expand All @@ -90,8 +97,11 @@ private static Map<String, String> mergeBuildArgsFrom(List<Map<String, String>>
.flatMap(map -> map.entrySet().stream())
.forEach(entry -> {
if (buildArgs.containsKey(entry.getKey())) {
logger.warn(String.format("Multiple Build Args with the same key: %s=%s and %s=%s, overriding value of key to %s=%s", entry.getKey(),
buildArgs.get(entry.getKey()), entry.getKey(), entry.getValue(), entry.getKey(),entry.getValue()));
logger.warn(
String.format("Multiple Build Args with the same key: %s=%s and %s=%s, overriding value of key to %s=%s",
entry.getKey(), buildArgs.get(entry.getKey()), entry.getKey(), entry.getValue(), entry.getKey(),
entry.getValue())
);
}
buildArgs.put(entry.getKey(), entry.getValue());
});
Expand Down Expand Up @@ -133,9 +143,9 @@ private static Map<String, String> buildArgsFromDockerConfig() {
"ftpProxy", "ftp_proxy"
};

for(int index = 0; index < proxyMapping.length; index += 2) {
for (int index = 0; index < proxyMapping.length; index += 2) {
if (defaultProxyObj.containsKey(proxyMapping[index])) {
buildArgs.put(ARG_PREFIX + proxyMapping[index+1], defaultProxyObj.get(proxyMapping[index]));
buildArgs.put(ARG_PREFIX + proxyMapping[index + 1], defaultProxyObj.get(proxyMapping[index]));
}
}
}
Expand Down

0 comments on commit fe19aa8

Please sign in to comment.