Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Artifact caching for Multi-stage Builds #36

Closed
awhitford opened this issue Jul 16, 2017 · 5 comments
Closed

Artifact caching for Multi-stage Builds #36

awhitford opened this issue Jul 16, 2017 · 5 comments

Comments

@awhitford
Copy link

I would love to use this for a multi-stage build, but the lack of a volume mount option for docker build poses a serious inefficiency due to the lack of artifact caching.

Are you aware of any good alternatives?

@mukhtar
Copy link

mukhtar commented Jul 20, 2017

Facing similar issue. This proposal if/when done will help address the issue.

@awhitford
Copy link
Author

Sadly, I don't see how that RUN --mount proposal will truly solve the problem. A Dockerfile may be built on a Windows machine, a Mac, or a Linux machine. The mount destination for MVN_REPO is a decision for the runner/builder, not the Dockerfile.

One idea that I can imagine is to declare a volume mount requirement. Imagine something like: REQUIRED_VOLUME MVN_REPO is declared that essentially says, Volume MVN_REPO needs to be defined. Then, that logical volume may be used in the Docker build (or run). If the volume is not defined, it could error out. I could see this feature useful for all sorts of reasons, like declaring a destination for log files or database content.

@sixcorners
Copy link

sixcorners commented Oct 5, 2017

Try using this

FROM maven
WORKDIR /usr/src/app
# /root/.m2 is a volume :(
ENV MAVEN_OPTS=-Dmaven.repo.local=../m2repo/
COPY pom.xml .
# v2.8 doesn't work :(
RUN mvn -B -e -C -T 1C org.apache.maven.plugins:maven-dependency-plugin:3.0.2:go-offline
COPY . .
RUN mvn -B -e -o -T 1C verify

FROM openjdk
COPY --from=0 /usr/src/app/target/*.jar ./

It caches the local repo like how the python onbuild Dockerfile does it. MAVEN_OPTS is needed because someone made /root/.m2/ a volume so stuff that goes in there doesn't get saved. verify is needed because "dependency:go-offline" doesn't work. You could probably just omit the "dependency:go-offline" part.
This sets it up so that changes to the pom.xml result in cache invalidation and redownload but other changes can just use the cache.

Edit: using a newer dependency:go-offline because the older one doesn't work.

@Algram
Copy link

Algram commented Dec 22, 2017

@sixcorners I am trying to do exactly the same thing you are doing, but for some reason my maven offline install fails and says it can't find the POM.xml for some maven internal projects. Have you had a similar problem?

@carlossg
Copy link
Owner

Now that .m2 is no longer a volume this should work

FROM maven:alpine
WORKDIR /usr/src/app
COPY pom.xml .
RUN mvn -B -e -C -T 1C org.apache.maven.plugins:maven-dependency-plugin:3.0.2:go-offline
COPY . .
RUN mvn -B -e -o -T 1C verify

FROM openjdk:alpine
COPY --from=0 /usr/src/app/target/*.jar ./

carlossg added a commit that referenced this issue Apr 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants