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 all commits
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 install -y gosu \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

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

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 $USER_NAME
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
9 changes: 9 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash -ex

./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


gosu $USER_NAME ./manage.py migrate

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