Skip to content

Commit

Permalink
Add new build parameter: "defaultExclusion"
Browse files Browse the repository at this point in the history
This commit introduces a new build parameter, "defaultExclusion," within the build properties of the plugin. The current behavior of the plugin is to build a Docker archive with default exclusion rules, which exclude hidden files. However, the Docker CLI includes hidden files by default.

With the addition of the "defaultExclusion" parameter, users can now control whether hidden files should be excluded during the Docker archive build process. This parameter provides flexibility and allows users to align the plugin's behavior with their specific requirements.
  • Loading branch information
thuva9872 authored and rohanKanojia committed Oct 23, 2023
1 parent 522cb80 commit f228f64
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ChangeLog
* **0.44-SNAPSHOT**:
- Add new option "useDefaultExclusion" for build configuration to handle exclusion of hidden files ([1708](https://github.com/fabric8io/docker-maven-plugin/issues/1708))

* **0.43.4** (2023-08-18):
- Always pass `--config` option for latest versions of Docker CLI ([1701](https://github.com/fabric8io/docker-maven-plugin/issues/1701))
Expand Down
3 changes: 3 additions & 0 deletions src/main/asciidoc/inc/build/_configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ a| Scan the archive specified in `dockerArchive` and find the actual repository

| *workdir*
| Directory to change to when starting the container.

| *useDefaultExcludes*
| If set to true this plugin won't include any hidden files in the docker image.
|===

From this configuration this Plugin creates an in-memory Dockerfile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public TarArchiver customize(TarArchiver archiver) throws IOException {
// Interpolated Dockerfile is already added as it was created into the output directory when
// using dir dir mode
excludeDockerfile(fileSet, dockerFile);

fileSet.setUsingDefaultExcludes(buildConfig.useDefaultExcludes());
// If the content is added as archive, then we need to add the Dockerfile from the builddir
// directly to docker.tar (as the output builddir is not picked up in archive mode)
if (isArchive(assemblyConfigurations)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ public class BuildImageConfiguration implements Serializable {
@Parameter
private Map<String,String> buildOptions;

//Default file exclusions
@Parameter
private Boolean useDefaultExcludes;

/**
* Map specifying the create image options to provide to the docker daemon when pulling or importing an image.
*
Expand Down Expand Up @@ -407,6 +411,11 @@ public boolean skipPush() {
return skipPush != null ? skipPush : false;
}

public boolean useDefaultExcludes() {

return useDefaultExcludes != null ? useDefaultExcludes : true;
}

public Boolean getNoCache() {
return noCache != null ? noCache : nocache;
}
Expand All @@ -427,6 +436,11 @@ public Boolean getSkipPush() {
return skipPush;
}

public Boolean getUseDefaultExcludes() {

return useDefaultExcludes;
}

public ArchiveCompression getCompression() {
return compression;
}
Expand Down Expand Up @@ -729,6 +743,12 @@ public Builder createImageOptions(Map<String, String> createImageOptions) {
return this;
}

public Builder useDefaultExcludes(Boolean useDefaultExcludes) {

config.useDefaultExcludes = useDefaultExcludes;
return this;
}

public BuildImageConfiguration build() {
return config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public enum ConfigKey {
STOP_NAME_PATTERN,
COPY_NAME_PATTERN,
TAGS(ValueCombinePolicy.Merge),
USE_DEFAULT_EXCLUDES,
TMPFS,
ULIMITS,
USER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ private BuildImageConfiguration extractBuildConfiguration(ImageConfiguration fro
.dockerFile(valueProvider.getString(DOCKER_FILE, config.getDockerFileRaw()))
.dockerFileDir(valueProvider.getString(DOCKER_FILE_DIR, config.getDockerFileDirRaw()))
.buildOptions(valueProvider.getMap(BUILD_OPTIONS, config.getBuildOptions()))
.useDefaultExcludes(valueProvider.getBoolean(USE_DEFAULT_EXCLUDES, config.getUseDefaultExcludes()))
.filter(valueProvider.getString(FILTER, config.getFilterRaw()))
.user(valueProvider.getString(USER, config.getUser()))
.healthCheck(extractHealthCheck(config.getHealthCheck(), valueProvider))
Expand Down

0 comments on commit f228f64

Please sign in to comment.