Skip to content
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ EXPOSE 8000/tcp

COPY start_NEMO_in_Docker.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/start_NEMO_in_Docker.sh
# Add non-root user
RUN addgroup --system --gid 963 nemo && \
adduser --system --home /home/nemo --shell /usr/bin/bash --gid 963 --uid 963 --comment "NEMO user" nemo
Comment on lines +33 to +34
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is there a reason why we cannot define the PGID and PUID here as ENV and then use them with adduser and addgroup?

CMD ["start_NEMO_in_Docker.sh"]
21 changes: 20 additions & 1 deletion Dockerfile.splash_pad
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,24 @@ WORKDIR /nemo
ENV REMOTE_USER="captain"
EXPOSE 8000/tcp

# Non-root user
RUN addgroup --system --gid 963 nemo && \
adduser --system --home /home/nemo --shell /usr/bin/bash --gid 963 --uid 963 --comment "NEMO user" nemo
RUN chown -R nemo:nemo /nemo
RUN chown -R nemo:nemo /var/run/
ENV PGID=963
ENV PUID=963

COPY --chmod=755 <<EOT /splash.sh
#!/bin/bash
set -e
# We have to start systemd jobs manually here unfortunately
CMD (cd /nemo/systemd && ls *.timer) | sed -e 's/\.timer$//' | xargs -t -I % systemctl start % ; exec django-admin runserver 0.0.0.0:8000
(cd /nemo/systemd && ls *.timer) | sed -e 's/\.timer$//' | xargs -t -I % systemctl start %
# Setting User and Group id
groupmod -o -g "$PGID" nemo
usermod -o -u "$PUID" -g "$PGID" nemo
# Starting NEMO
echo "Running NEMO as user '$(id nemo)'"
exec su nemo -c "django-admin runserver 0.0.0.0:8000"
EOT
CMD ["/splash.sh"]
19 changes: 15 additions & 4 deletions start_NEMO_in_Docker.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash

# Exit if any of following commands fails
set -e

Expand All @@ -10,11 +9,23 @@ else
echo "No additional Python packages to install."
fi

# Set the PUID and PGID environment variables
PUID=${PUID:-963}
PGID=${PGID:-963}
# Change the user and group IDs
groupmod -o -g "$PGID" nemo
usermod -o -u "$PUID" -g "$PGID" nemo
if [ -n "$PUID" ]; then
# Change the ownership of the application directory
chown -R nemo:nemo /nemo
fi
echo "Running NEMO as user '$(id nemo)'"

# Collect static files
django-admin collectstatic --no-input --clear
su nemo -c "django-admin collectstatic --no-input --clear"

# Run migrations to create or update the database
django-admin migrate
su nemo -c "django-admin migrate"

# Run NEMO
exec gunicorn --config=/etc/gunicorn_configuration.py NEMO.wsgi:application
exec su nemo -c "gunicorn --config=/etc/gunicorn_configuration.py NEMO.wsgi:application"