-
Notifications
You must be signed in to change notification settings - Fork 84
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
Dockerfile that builds with poetry #493
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9c8ecaa
Dockerfile that builds with poetry
4462712
Changelog
e9fc715
Don't rearrange lines unnecessarily
86be24f
Update Dockerfile
0bcbf2c
Update Dockerfile
a2d467f
Use `--disabled-login` and don't set a password
3e7f3ca
Tweak README
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,61 @@ | ||
# This Dockerfile installs Sydent from source, which is assumed to be in the current | ||
# working directory. The resulting image contains a single "sydent" user, and populates | ||
# their home area with "src" and "venv" directories. The entrypoint runs Sydent, | ||
# listening on port 8090. | ||
# | ||
# Step 1: Build sydent and install dependencies | ||
# | ||
FROM docker.io/python:3.8-slim as builder | ||
# Users must provide a persistent volume available to the container as `/data`. This | ||
# will contain Sydent's configuration and database. A blank configuration and database | ||
# file is created the first time Sydent runs. | ||
|
||
# Install dev packages | ||
RUN apt-get update && apt-get install -y \ | ||
build-essential | ||
# Step 1: install dependencies | ||
FROM docker.io/python:3.8-slim as builder | ||
|
||
# Add user sydent | ||
RUN addgroup --system --gid 993 sydent \ | ||
&& adduser --disabled-password --home /sydent --system --uid 993 --gecos sydent sydent \ | ||
&& echo "sydent:$(dd if=/dev/random bs=32 count=1 | base64)" | chpasswd | ||
&& adduser --disabled-login --system --uid 993 --gecos sydent sydent | ||
USER sydent:sydent | ||
|
||
# Install poetry | ||
RUN pip install --user poetry==1.1.12 | ||
|
||
# Copy resources | ||
COPY --chown=sydent:sydent ["res", "/sydent/res"] | ||
COPY --chown=sydent:sydent ["scripts", "/sydent/scripts"] | ||
COPY --chown=sydent:sydent ["sydent", "/sydent/sydent"] | ||
COPY --chown=sydent:sydent ["README.rst", "setup.cfg", "setup.py", "/sydent/"] | ||
# Copy source code and resources | ||
WORKDIR /home/sydent/src | ||
COPY --chown=sydent:sydent ["res", "res"] | ||
COPY --chown=sydent:sydent ["scripts", "scripts"] | ||
COPY --chown=sydent:sydent ["sydent", "sydent"] | ||
COPY --chown=sydent:sydent ["README.rst", "pyproject.toml", "poetry.lock", "./"] | ||
|
||
# Install dependencies | ||
USER sydent | ||
WORKDIR /sydent | ||
RUN pip install --user --upgrade pip setuptools sentry-sdk prometheus_client \ | ||
&& pip install --user . \ | ||
&& rm -rf /sydent/.cache \ | ||
&& find /sydent -name '*.pyc' -delete | ||
RUN python -m poetry install --no-dev --no-interaction | ||
|
||
# | ||
# Step 2: Reduce image size and layers | ||
# | ||
# Record dependencies for posterity | ||
RUN python -m poetry export -o requirements.txt | ||
|
||
# Make the virtualenv accessible for the final image | ||
RUN ln -s $(python -m poetry env info -p) /home/sydent/venv | ||
|
||
# Nuke bytecode files to keep the final image slim. | ||
RUN find /home/sydent/venv -type f -name '*.pyc' -delete | ||
|
||
# Step 2: Create runtime image | ||
FROM docker.io/python:3.8-slim | ||
|
||
# Add user sydent and create /data directory | ||
RUN addgroup --system --gid 993 sydent \ | ||
&& adduser --disabled-password --home /sydent --system --uid 993 --gecos sydent sydent \ | ||
&& echo "sydent:$(dd if=/dev/random bs=32 count=1 | base64)" | chpasswd \ | ||
&& adduser --disabled-login --home /sydent --system --uid 993 --gecos sydent sydent \ | ||
&& mkdir /data \ | ||
&& chown sydent:sydent /data | ||
|
||
# Copy sydent | ||
COPY --from=builder ["/sydent", "/sydent"] | ||
# Copy sydent and the virtualenv | ||
COPY --from=builder ["/home/sydent/src", "/home/sydent/src"] | ||
COPY --from=builder ["/home/sydent/venv", "/home/sydent/venv"] | ||
|
||
ENV SYDENT_CONF=/data/sydent.conf | ||
ENV SYDENT_PID_FILE=/data/sydent.pid | ||
ENV SYDENT_DB_PATH=/data/sydent.db | ||
|
||
WORKDIR /sydent | ||
WORKDIR /home/sydent | ||
USER sydent:sydent | ||
VOLUME ["/data"] | ||
EXPOSE 8090/tcp | ||
CMD [ "python", "-m", "sydent.sydent" ] | ||
CMD [ "venv/bin/python", "-m", "sydent.sydent" ] |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
Update Dockerfile to use a fixed poetry environment, rather than `pip install`ing the latest dependencies. |
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.
I realise this isn't yours, but on the line above, why are we creating a password for the sydent user?
It originally has a disabled password. There's no reason to set a static password ... is there?
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 wondered about this too. I removed this from the builder step (see line -13).
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.
Seems to have been added in #290; wasn't present in #80. No clues in either PR.
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 reckon we just remove it here as well. A password that is the same for every Sydent container doesn't seem to afford any security anyway.
I also notice
--disabled-login
is an option rather than--disabled-password
Excerpt from
/etc/shadow
:--disabled-login
sounds like it (!
) will also prevent SSH login using authorised keys. I guess we're not running an SSH daemon anyway, so it probably doesn't matter which one we use.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 password comes from /dev/random so I would expect it to be different every time you run build this container. I still think it's odd though.
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.
But if it gets uploaded to Docker Hub or something, everyone can then pull that and even crack the password hash if they're so keen. I'd pull it out — the password isn't even being given to anyone so I can't see how it's useful.
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.
Oh I see---good point. Yes, let's excise it