Skip to content

Commit 8840355

Browse files
committed
Change to using a root user for local development
This fixes an issue that was happening where Vite and other JS related tools where throwing write permission errors when running because the web service would create files as non-privileged app user and then JS tools would run as a non-privileged user and then try to write to directories owned by root.
1 parent 195aae4 commit 8840355

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# CHANGELOG
22

33

4+
## 2023-06-01
5+
6+
### Changed
7+
8+
* Changed to using a root user for local development. This fixes an issue that was happening where Vite and other JS
9+
related tools where throwing write permission errors when running because the web service would create files as a
10+
non-privileged app user and then JS tools would run as a non-privileged user and then try to write to
11+
directories owned by root.
12+
13+
414
## 2023-06-01
515

616
### Changed

config/bash/bashrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# Color prompt
2+
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
3+
4+
# Colorize `ls` output
5+
export SHELL=/bin/bash
6+
export LS_OPTIONS='--color=auto'
7+
eval "`dircolors`"
8+
alias ls='ls $LS_OPTIONS'
9+
alias ll='ls $LS_OPTIONS -l'
10+
alias l='ls $LS_OPTIONS -lA'
11+
112
# some more ls aliases
213
alias ll='ls -l'
314
alias la='ls -A'

config/docker/Dockerfile.web

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ RUN apt-get update \
3838
&& echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen \
3939
&& echo "LANG=en_US.UTF-8" > /etc/locale.conf \
4040
&& locale-gen en_US.UTF-8 \
41-
&& rm -rf /var/lib/apt/lists/*
41+
&& rm -rf /var/lib/apt/lists/* \
42+
&& echo "\nsource /srv/app/config/bash/bashrc" >> /root/.bashrc
4243

4344
ENV VIRTUAL_ENV=/opt/venv
4445
ENV LANG=en_US.UTF-8 \
@@ -51,14 +52,8 @@ ENV LANG=en_US.UTF-8 \
5152

5253
WORKDIR /srv/app
5354

54-
RUN set -ex \
55-
&& groupadd -r app && useradd --uid=1000 --create-home --home-dir=/home/app --no-log-init -r -g app app \
56-
&& echo "\nsource ./config/bash/bashrc" >> /home/app/.bashrc
57-
5855
COPY --from=python-requirements --chown=app:app $VIRTUAL_ENV $VIRTUAL_ENV
5956

60-
USER app
61-
6257
EXPOSE 8000/tcp 8001/tcp
6358

6459
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
@@ -88,14 +83,16 @@ FROM dev as prod
8883

8984
WORKDIR /srv/app
9085

91-
USER root
86+
RUN set -ex \
87+
&& groupadd -r app --gid=1000 && useradd --uid=1000 --create-home --home-dir=/home/app --no-log-init -r -g app app \
88+
&& echo "\nsource ./config/bash/bashrc" >> /home/app/.bashrc
89+
90+
COPY --chown=app:app . .
9291

93-
COPY . .
92+
USER app
9493

9594
RUN SECRET_KEY=e python manage.py collectstatic --no-input
9695

9796
COPY --from=js_assets --chown=app:app /srv/app/public/static/ ./collected_static
9897

99-
USER app
100-
10198
CMD ["uwsgi", "--ini", "config/uwsgi.ini", "--http", "0.0.0.0:8080"]

0 commit comments

Comments
 (0)