-
Notifications
You must be signed in to change notification settings - Fork 6k
General dockerfile cleanup #6836
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…ld efficiency
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
FROM jimschubert/8-jdk-alpine-mvn:1.0 | ||
|
||
COPY docker-entrypoint.sh /usr/local/bin/ | ||
|
||
ENV GEN_DIR /opt/swagger-codegen | ||
|
||
RUN set -x && \ | ||
apk add --no-cache bash | ||
|
||
RUN mkdir /opt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line could be changed to https://docs.docker.com/engine/reference/builder/#workdir
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iirc, WORKDIR is evaluated and created after COPY. Do you know if this has changed? I can play around with it when I'm not in mobile. Also, in the past, COPY did not work the same as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WORKDIR https://docs.docker.com/engine/reference/builder/#workdir
COPY https://docs.docker.com/engine/reference/builder/#copy
If any change is to be made to the existing Dockerfile, the following FROM jimschubert/8-jdk-alpine-mvn:1.0
# install OS packages; should only change when new packages required
# or when the base image is updated.
RUN apk add --no-cache bash
# only changes if the value of GEN_DIR is changed
ENV GEN_DIR /opt/swagger-codegen
WORKDIR ${GEN_DIR}
# most frequent change as it includes the entire context
# copies all of the contents of ./modules/ to the directory created
# by the COPY command 'modules/'. This means if any new modules
# are added then they will get included.
COPY ./modules/ ${GEN_DIR}/modules/
VOLUME ${MAVEN_HOME}/.m2/repository
# most costly to execute from a time perspective
RUN mvn -am -pl "modules/swagger-codegen-cli" package
# least likely to change but if any higher in the file it could result in the maven build running
COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["build"] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kenjones-cisco I'm a little confused by your proposal, so I'd like to clarify a bit. Is your suggestion basically to move Also, are you suggesting to include only Being that I also have some questions about your comments.
I don't understand this. The layer of the image doesn't change if you pass
I don't understand what this means. The addition of the entry point is 899B. It only matters that it comes after the
…and we were tweaking However, regardless of where this instruction is in the dockerfile, the maven build will always run when you run tl;dr I think your proposal would work if we add the Also, I've realized that running with the default CMD of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yeah it makes sense that it sets the working directory for all following instructions, otherwise that wouldn't really be intuitive. I've always used absolute paths for copy, so never had to consider WORKDIR there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kenjones-cisco played around with this a bit, samples and other unnecessary files are already excluded by the dockerignore. Also, in addition to Here's a working example:
Yet, because almost everything else is already excluded, we receive very little gains from restructuring the file in this way (top is built with my changes above, bottom is built from master):
So, in the end... I think the only worthwhile change to the Dockerfile would be to change the CMD to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would agree, the WORKDIR change and ADD -> COPY are good changes. The one way that breaking apart the COPY instructions is positive is related to layer caching. When you do Otherwise from a size perspective, there will not be any change or real value especially if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. re: breaking apart modules into layers do you think this is worth it? It'll benefit is who pull the latest tag often. I think that's beneficial enough to eat the additional maintenance (although this would be minimal as a cli container). I've can make the changes in a separate PR, if you agree. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed! |
||
|
||
ADD . ${GEN_DIR} | ||
COPY . ${GEN_DIR} | ||
|
||
VOLUME ${MAVEN_HOME}/.m2/repository | ||
|
||
WORKDIR ${GEN_DIR} | ||
|
||
RUN mvn -am -pl "modules/swagger-codegen-cli" package | ||
|
||
COPY docker-entrypoint.sh /usr/local/bin/ | ||
|
||
ENTRYPOINT ["docker-entrypoint.sh"] | ||
|
||
CMD ["build"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
COPY should be after
apk add
otherwise a change to the file would result in not using the cache install of OS packages.