diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..16f0ad8 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,11 @@ +{ + "name": "Existing Docker Compose", + "dockerComposeFile": ["../docker/dev/docker-compose.yml"], + "service": "web", + "workspaceFolder": "/app", + "settings": { + "terminal.integrated.defaultProfile.linux": "bash", + "python.pythonPath": "/usr/local/bin/python" + }, + "extensions": ["ms-python.python", "editorconfig.editorconfig"] +} diff --git a/.dockerignore b/.dockerignore new file mode 120000 index 0000000..3e4e48b --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.gitignore \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ce50fbf..198bd89 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -40,6 +40,12 @@ pip: - ./env/ expire_in: 30 mins +container: + image: docker:stable + stage: test + script: + - docker build -t website . + .python_test_template: &python_test_template image: python:3.10-slim stage: test diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8f8d6e8 --- /dev/null +++ b/Dockerfile @@ -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 diff --git a/Procfile b/Procfile index cdc7393..046b13e 100644 --- a/Procfile +++ b/Procfile @@ -2,5 +2,4 @@ web: ./manage.py runserver watch-js: npm run build:js -- --watch watch-css: npm run build:css -- --watch watch-contrib: ./scripts/copy-npm-contrib.sh; while inotifywait -e modify ./scripts/copy-npm-contrib.sh; do ./scripts/copy-npm-contrib.sh; done -docker: docker-compose -f docker/dev/docker-compose.yml up -rqworker: sleep 5 && ./manage.py rqworker --with-scheduler +rqworker: ./manage.py rqworker --with-scheduler diff --git a/docker/dev/docker-compose.yml b/docker/dev/docker-compose.yml index 36af809..7140671 100644 --- a/docker/dev/docker-compose.yml +++ b/docker/dev/docker-compose.yml @@ -1,6 +1,17 @@ version: '3.7' services: + web: + build: + context: ../../ + target: dev + environment: + - QUEUE_STORE_URL=redis://redis/0 + - DEBUG=true + - SECRET_KEY=super-secret-key + volumes: + - ../../:/app + depends_on: + - redis + redis: image: redis:6.0 - ports: - - 127.0.0.1:6379:6379 diff --git a/justfile b/justfile index 50d7bf2..27c520f 100644 --- a/justfile +++ b/justfile @@ -1,14 +1,5 @@ set dotenv-load -# Load virtualenv -export PATH := justfile_directory() + "/env/bin:" + env_var('PATH') -export PYTHONUNBUFFERED := "true" -export QUEUE_STORE_URL := "redis://localhost/0" - -# Dev environment -export DEBUG := "true" -export SECRET_KEY := "super-secret-key" - # Recipes @default: just --list