-
Notifications
You must be signed in to change notification settings - Fork 161
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
Use slim node images to reduce download and running size #549
Merged
lognaturel
merged 9 commits into
getodk:next
from
spwoodcock:build/optimise-service-dockerfile
Dec 9, 2023
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b8ace39
build: optimise central backend (service) dockerfile
spwoodcock 79ec540
build: service dockerfile copy files after apt install
spwoodcock 1b43259
build: pin node version 18 --> 18.17
spwoodcock 4cafcff
build: update maintainer label, remove healthcheck
spwoodcock a6d57e3
Use node version 20.10
lognaturel 35bd780
Use slim base images for nginx and secrets
lognaturel cac1ec4
Merge branch 'next' into build/optimise-service-dockerfile
lognaturel 8aa8ebc
Use opencontainer labels, bring back EXPOSE
lognaturel 7c3e7a1
Remove labels that aren't used by GHCR
lognaturel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
FROM node:20.10 | ||
FROM node:20.10-slim | ||
|
||
COPY files/enketo/generate-secrets.sh ./ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,69 @@ | ||
ARG node_version=20.10 | ||
FROM node:${node_version} as intermediate | ||
|
||
|
||
|
||
FROM node:${node_version}-slim as pgdg | ||
RUN apt-get update \ | ||
&& apt-get install -y --no-install-recommends \ | ||
ca-certificates \ | ||
curl \ | ||
gpg \ | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
&& update-ca-certificates | ||
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ $(grep -oP 'VERSION_CODENAME=\K\w+' /etc/os-release)-pgdg main" \ | ||
| tee /etc/apt/sources.list.d/pgdg.list \ | ||
&& curl https://www.postgresql.org/media/keys/ACCC4CF8.asc \ | ||
| gpg --dearmor > /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg | ||
|
||
|
||
|
||
FROM node:${node_version}-slim as intermediate | ||
RUN apt-get update \ | ||
&& apt-get install -y --no-install-recommends \ | ||
git \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
COPY . . | ||
RUN mkdir /tmp/sentry-versions | ||
RUN git describe --tags --dirty > /tmp/sentry-versions/central | ||
WORKDIR server | ||
WORKDIR /server | ||
RUN git describe --tags --dirty > /tmp/sentry-versions/server | ||
WORKDIR ../client | ||
WORKDIR /client | ||
RUN git describe --tags --dirty > /tmp/sentry-versions/client | ||
|
||
FROM node:${node_version} | ||
|
||
WORKDIR /usr/odk | ||
|
||
RUN apt-get update && apt-get install wait-for-it && rm -rf /var/lib/apt/lists/* | ||
FROM node:${node_version}-slim | ||
|
||
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ $(grep -oP 'VERSION_CODENAME=\K\w+' /etc/os-release)-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list && \ | ||
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor > /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg && \ | ||
apt-get update && \ | ||
apt-get install -y cron gettext postgresql-client-14 | ||
ARG node_version | ||
LABEL org.opencontainers.image.source="https://github.com/getodk/central" | ||
|
||
COPY files/service/crontab /etc/cron.d/odk | ||
WORKDIR /usr/odk | ||
|
||
COPY server/package*.json ./ | ||
|
||
RUN npm clean-install --omit=dev --legacy-peer-deps --no-audit --fund=false --update-notifier=false | ||
COPY --from=pgdg /etc/apt/sources.list.d/pgdg.list \ | ||
/etc/apt/sources.list.d/pgdg.list | ||
COPY --from=pgdg /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg \ | ||
/etc/apt/trusted.gpg.d/apt.postgresql.org.gpg | ||
RUN apt-get update \ | ||
&& apt-get install -y --no-install-recommends \ | ||
gpg \ | ||
cron \ | ||
wait-for-it \ | ||
gettext \ | ||
procps \ | ||
postgresql-client-14 \ | ||
netcat-traditional \ | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
&& npm clean-install --omit=dev --legacy-peer-deps --no-audit \ | ||
--fund=false --update-notifier=false | ||
|
||
COPY server/ ./ | ||
COPY files/service/scripts/ ./ | ||
|
||
COPY files/service/config.json.template /usr/share/odk/ | ||
COPY files/service/crontab /etc/cron.d/odk | ||
COPY files/service/odk-cmd /usr/bin/ | ||
|
||
COPY --from=intermediate /tmp/sentry-versions/ ./sentry-versions | ||
|
||
EXPOSE 8383 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The original PR description states that
EXPOSE
is deprecated. I see no evidence of this: https://docs.docker.com/engine/reference/builder/#exposeThere 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.
Expose is for documenting the port the builder of the image intends to publish. It doesn't actually publish it, so maybe that's the confusion? Either way, agreed that we can leave this.
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.
Sorry, my mistake!
I always leave out EXPOSE and prefer a LABEL, as expose doesn't actually do anything to the image.
Using a label allows a user to
docker inspect
to easily know which port they need to bind.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.
It's not a bad idea. Is it used anywhere else? Or documented somewhere as a best practice?
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.
Not as far as I can see!
For a long time LABEL had no standard set, so it's good to see opencontainers create one.
I added the port label from my own frustrations with using other images.
If the author doesn't have a label, then I had to hunt down either the dockerfile (if they use EXPOSE) or the application config to find the port.
Updates in my knowledge
LABEL and ENV no longer require multiline definition. It's more readable to use individual lines.
EXPOSE is now used by both docker and podman
-P
flag, to map all exposed ports to random ports on the host (does not seem useful to me, but maybe to some?).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.
Thanks again for getting these improvements in!
When doing
docker inspect
, doesn'tConfig/ExposedPorts
show the ports that were specified withEXPOSE
?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.
You are correct!
That's an oversight from me.
I thought that
EXPOSE
was a useless command for years.By the looks of it, it is actually a nice way to document via the metadata.
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.
I think so! And downstream tools could use it programmatically, hopefully to do more useful things than random port binding. 😄 🤷🏻♀️ It's also very possible that
Config/ExposedPorts
is relatively new. There's a lot to learn and keep track of!