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

Make the Docker image "rootless" [WIP] #799

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ jobs:
run: docker compose build --build-arg DJANGO_SETTINGS_MODULE="config.settings.dev"

- name: Run Django tests
run: docker compose run -e DEBUG=false app coveraged-test
run: |
docker compose run -e DEBUG=false -u $(id -u):$(id -g) app coveraged-test

# Push on main
- name: Build and push (on main)
Expand Down
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,23 @@

ARG DJANGO_SETTINGS_MODULE

# Rootless
ARG USER=openhexa
ARG GROUP=openhexa
RUN groupadd --gid 1000 $GROUP &&\
useradd --gid 1000 --uid 1000 --no-create-home --home-dir /code --no-log-init --shell /bin/bash $USER &&\
passwd -d $USER

RUN chown -R $USER:$GROUP /code/
RUN mkdir /data && chown $USER:$GROUP /data
USER $USER:$GROUP

# Entry point
ARG WORKSPACE_STORAGE_LOCATION
ENV DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE}
ENV WORKSPACE_STORAGE_LOCATION=${WORKSPACE_STORAGE_LOCATION}
ENTRYPOINT ["/code/docker-entrypoint.sh"]
CMD start

Check warning on line 48 in Dockerfile

View workflow job for this annotation

GitHub Actions / Run test suite

JSON arguments recommended for ENTRYPOINT/CMD to prevent unintended behavior related to OS signals

JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals More info: https://docs.docker.com/go/dockerfile/rule/json-args-recommended/

FROM deps AS app
ARG DJANGO_SETTINGS_MODULE
Expand All @@ -49,6 +60,9 @@
ARG WORKSPACE_STORAGE_LOCATION
ENV DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE}
ENV WORKSPACE_STORAGE_LOCATION=${WORKSPACE_STORAGE_LOCATION}

USER root:root

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
apt-get update && \
apt-get install -y --no-install-recommends \
Expand All @@ -63,3 +77,8 @@
apt-get install -y --no-install-recommends docker-ce-cli && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Rootless
RUN groupadd --gid 999 docker
RUN usermod -aG docker $USER
USER $USER:$GROUP
Loading