wrenidm icon indicating copy to clipboard operation
wrenidm copied to clipboard

Directory .git is not ignored in Docker build

Open RoBobik opened this issue 1 year ago • 0 comments

Directory .git is not excluded from the Docker build context.

Since the Dockerfile contains COPY . ., it also invalidates the build cache if you, for example, run git fetch (or your IDE does it for you in the background).

The .git dir cannot be simply added to .dockerignore because it is used in openidm-system/pom.xml for injecting branch name and commit id into org.forgerock.openidm.core.ServerConstants. When you try to do so anyway, the build fails on this error:

[ERROR] Failed to execute goal org.jboss.maven.plugins:maven-injection-plugin:1.0.2:bytecode (default) on project openidm-system: Execution default of goal org.jboss.maven.plugins:maven-injection-plugin:1.0.2:bytecode failed: Cannot invoke "String.length()" because "str" is null -> [Help 1]

See #116 in which the following change was introduced:

- <expression>${git.closest.tag.name}</expression>
+ <expression>${env.BUILD_TAG}</expression>

Perhaps we should take the other variables from build env as well (pass it from CI), or try to configure (if possible) a fallback for git-commit-id-plugin. Other alternatives may also be possible.

RoBobik avatar Feb 06 '24 13:02 RoBobik