Move development into docker
This makes working with related services like redis much easier, and helps start writing a production container
This commit is contained in:
parent
e87ed66a02
commit
97d786e969
7 changed files with 86 additions and 13 deletions
54
Dockerfile
Normal file
54
Dockerfile
Normal file
|
@ -0,0 +1,54 @@
|
|||
FROM node:16 as frontend
|
||||
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm ci --no-audit --progress=false
|
||||
|
||||
# Compile static files
|
||||
COPY ./scripts ./scripts
|
||||
COPY ./static/src ./static/src
|
||||
RUN npm run build
|
||||
|
||||
# The actual container
|
||||
FROM python:3.10 as production
|
||||
|
||||
ENV VIRTUAL_ENV=/venv
|
||||
|
||||
RUN useradd website --create-home && mkdir /app $VIRTUAL_ENV && chown -R website /app $VIRTUAL_ENV
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
ENV PATH=${POETRY_HOME}/bin:$VIRTUAL_ENV/bin:$PATH \
|
||||
PYTHONUNBUFFERED=1
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
USER website
|
||||
|
||||
RUN python -m venv $VIRTUAL_ENV
|
||||
COPY --chown=website requirements.txt ./
|
||||
RUN pip install --upgrade pip && pip install -r requirements.txt
|
||||
|
||||
COPY --chown=website --from=frontend ./static/build ./static/build
|
||||
|
||||
COPY --chown=website ./manage.py ./manage.py
|
||||
COPY --chown=website ./templates ./templates
|
||||
COPY --chown=website ./website ./website
|
||||
|
||||
RUN SECRET_KEY=none python manage.py collectstatic --noinput --clear -v3
|
||||
|
||||
# Just dev stuff
|
||||
FROM production as dev
|
||||
|
||||
# Swap user, so the following tasks can be run as root
|
||||
USER root
|
||||
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash - && apt-get install -y nodejs
|
||||
RUN apt-get install -y postgresql-client
|
||||
RUN curl -sSf https://just.systems/install.sh | bash -s -- --to /usr/bin
|
||||
|
||||
# Restore user
|
||||
USER website
|
||||
|
||||
COPY --chown=website dev-requirements.txt ./
|
||||
RUN pip install --upgrade pip && pip install -r dev-requirements.txt
|
||||
|
||||
CMD sleep infinity
|
Loading…
Add table
Add a link
Reference in a new issue