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

non root user in docker entry #162

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ FROM python:3.8-buster
RUN set -e \
&& apt-get update \
&& apt-get install -y --no-install-recommends sqlite3 \
&& apt-get update && apt-get install -y gosu \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

ARG UNAME=liquid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call this arg $USER_NAME too so it has the same name as the env below

ARG UID=666
ARG GID=666
RUN groupadd -g $GID -o $UNAME
RUN useradd -m -u $UID -g $GID -o -s /bin/bash $UNAME

RUN mkdir -p /app
WORKDIR /app

Expand All @@ -15,10 +22,19 @@ RUN set -e \

ADD liquidcore ./liquidcore
ADD manage.py dockercmd ./
ADD docker-entrypoint.sh ./

ENV PYTHONUNBUFFERED 1

ENV DATA_DIR "/app/var"
ENV USER_NAME $UNAME
ENV UID $UID
ENV GID $GID

VOLUME /app/var

RUN SECRET_KEY=x ./manage.py collectstatic

CMD ./dockercmd
ENTRYPOINT ["/app/docker-entrypoint.sh"]

CMD /app/dockercmd
11 changes: 11 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash -ex

if [[ ! -d "$DATA_DIR" ]]; then
exit 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this ever happen? I mean sure, if you don't mount the directory, but we do mount it. I think you can remove this check, let it crash later naturally when doing migrate.

fi

./manage.py initialize
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This command only runs migrate (it used to do a lot more) - so you can remove that file and replace this line with ./manage.py migrate.


chown -R $UID:$GID $DATA_DIR
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this service, since it only has one file on it, it's OK to always run a chown -R. For other repositories that may have a lot of data under the volume, you can't use -R every container boot because it would take a lot of time


exec gosu $USER_NAME "$@"
2 changes: 0 additions & 2 deletions dockercmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/bin/bash -ex

./manage.py initialize
# exec ./manage.py runserver 0.0.0.0:8000
exec waitress-serve --port 8000 liquidcore.site.wsgi:application