diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index be80af5a..899ab12d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -21,9 +21,7 @@ build: ENV: dev script: # - docker build -t re2o . --target=postgres - - cp -n cotisations/templates/cotisations/invoice.html templates/default_invoice.html - - cp -n cotisations/templates/cotisations/voucher.html templates/default_voucher.html - - docker compose run --build re2o poetry run python manage.py test + - docker compose -f docker-compose-dev.yml run --env RUN_TESTS=yes re2o lint: image: python:3 diff --git a/dev-requirements.txt b/dev-requirements.txt index 89da7573..ed1d54aa 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -305,6 +305,9 @@ gitdb==4.0.11 ; python_version >= "3.8" and python_version < "4.0" \ gitpython==3.1.42 ; python_version >= "3.8" and python_version < "4.0" \ --hash=sha256:1bf9cd7c9e7255f77778ea54359e54ac22a72a5b51288c457c881057b7bb9ecd \ --hash=sha256:2d99869e0fef71a73cbd242528105af1d6c1b108c60dfabd994bf292f76c3ceb +gunicorn==21.2.0 ; python_version >= "3.8" and python_version < "4.0" \ + --hash=sha256:3213aa5e8c24949e792bcacfc176fef362e7aac80b76c56f6b5122bf350722f0 \ + --hash=sha256:88ec8bff1d634f98e61b9f65bc4bf3cd918a90806c6f5c48bc5603849ec81033 html5lib==1.1 ; python_version >= "3.8" and python_version < "4.0" \ --hash=sha256:0d78f8fde1c230e99fe37986a60526d7049ed4bf8a9fadbad5f00e22e58e041d \ --hash=sha256:b2e5b40261e20f354d198eae92afc10d750afb487ed5e50f9c4eaf07c184146f diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml new file mode 100644 index 00000000..d1a21782 --- /dev/null +++ b/docker-compose-dev.yml @@ -0,0 +1,36 @@ +version: "3" + +volumes: + database_data: + driver: local + +services: + db: + image: postgres:latest + volumes: + - database_data:/var/lib/postgresql/data + environment: + - POSTGRES_DB=postgres + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + + re2o: + build: + context: . + dockerfile: ./docker/Dockerfile-re2o + target: postgres-dev + depends_on: + - db + ports: + - "8000:8000" + volumes: + - .:/code + environment: + - POSTGRES_DB=postgres + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + - SUPERUSER_LOGIN=admin + - SUPERUSER_PASS=admin + - SUPERUSER_EMAIL=admin@example.net + - ENV=dev + entrypoint: ./docker/docker-entrypoint-dev.sh \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index deb29c0d..880d40c4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,11 +17,8 @@ services: re2o: build: context: . + dockerfile: ./docker/Dockerfile-re2o target: postgres - volumes: - - .:/code - ports: - - "8000:8000" depends_on: - db environment: @@ -31,4 +28,12 @@ services: - SUPERUSER_LOGIN=admin - SUPERUSER_PASS=admin - SUPERUSER_EMAIL=admin@example.net - - ENV=dev \ No newline at end of file + + nginx: + build: + context: . + dockerfile: ./docker/Dockerfile-nginx + volumes: + - ./media:/media + ports: + - "80:80" \ No newline at end of file diff --git a/docker/Dockerfile-nginx b/docker/Dockerfile-nginx new file mode 100644 index 00000000..d95e40dd --- /dev/null +++ b/docker/Dockerfile-nginx @@ -0,0 +1,13 @@ +FROM python:3.9-bullseye AS build +ENV PYTHONUNBUFFERED=1 +RUN pip install poetry +WORKDIR /code +RUN apt-get update && apt-get install -y --no-install-recommends gettext-base gettext libpq-dev +COPY . /code/ +RUN poetry install --extras "postgresql" +RUN ENV=dev DATABASE_URL='' poetry run python manage.py collectstatic --noinput +RUN poetry run python manage.py compilemessages + +FROM nginx +COPY ./docker/nginx.conf /etc/nginx/conf.d/default.conf +COPY --from=build /code/static_files /static \ No newline at end of file diff --git a/Dockerfile b/docker/Dockerfile-re2o similarity index 56% rename from Dockerfile rename to docker/Dockerfile-re2o index f4db5a56..55e3dd6e 100644 --- a/Dockerfile +++ b/docker/Dockerfile-re2o @@ -2,8 +2,7 @@ FROM python:3.9-bullseye AS base ENV PYTHONUNBUFFERED=1 RUN pip install poetry WORKDIR /code -RUN apt-get update && apt-get install -y --no-install-recommends gettext-base libpq-dev graphviz -COPY pyproject.toml poetry.lock /code/ +RUN apt-get update && apt-get install -y --no-install-recommends gettext-base gettext libpq-dev graphviz COPY . /code/ CMD ./docker/docker-entrypoint.sh @@ -12,13 +11,29 @@ ENV DEBIAN_FRONTEND=noninteractive RUN apt-get install -y --no-install-recommends libldap-dev slapd libsasl2-dev FROM base AS mysql -RUN poetry install --with dev --extras "mysql" +RUN poetry install --extras "mysql" FROM base AS postgres -RUN poetry install --with dev --extras "postgresql" +RUN poetry install --extras "postgresql" FROM ldap AS mysql-ldap -RUN poetry install --with dev --extras "mysql ldap" +RUN poetry install --extras "mysql ldap" FROM ldap AS postgres-ldap +RUN poetry install --extras "postgresql ldap" + +FROM base AS mysql-dev +ENV RUN_TESTS=no +RUN poetry install --with dev --extras "mysql" + +FROM base AS postgres-dev +ENV RUN_TESTS=no +RUN poetry install --with dev --extras "postgresql" + +FROM ldap AS mysql-ldap-dev +ENV RUN_TESTS=no +RUN poetry install --with dev --extras "mysql ldap" + +FROM ldap AS postgres-ldap-dev +ENV RUN_TESTS=no RUN poetry install --with dev --extras "postgresql ldap" \ No newline at end of file diff --git a/docker/docker-entrypoint-dev.sh b/docker/docker-entrypoint-dev.sh new file mode 100755 index 00000000..3012f132 --- /dev/null +++ b/docker/docker-entrypoint-dev.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +set -euo pipefail + +cp -n cotisations/templates/cotisations/invoice.html templates/default_invoice.html +cp -n cotisations/templates/cotisations/voucher.html templates/default_voucher.html + +AUTOMIGRATE=${AUTOMIGRATE:-yes} + +if [ "$AUTOMIGRATE" != "skip" ]; then + poetry run python manage.py migrate --noinput +fi + +poetry run python manage.py collectstatic -c --noinput +poetry run python manage.py compilemessages + +cat <= "3.8" and python_version < "4.0" \ gitpython==3.1.42 ; python_version >= "3.8" and python_version < "4.0" \ --hash=sha256:1bf9cd7c9e7255f77778ea54359e54ac22a72a5b51288c457c881057b7bb9ecd \ --hash=sha256:2d99869e0fef71a73cbd242528105af1d6c1b108c60dfabd994bf292f76c3ceb +gunicorn==21.2.0 ; python_version >= "3.8" and python_version < "4.0" \ + --hash=sha256:3213aa5e8c24949e792bcacfc176fef362e7aac80b76c56f6b5122bf350722f0 \ + --hash=sha256:88ec8bff1d634f98e61b9f65bc4bf3cd918a90806c6f5c48bc5603849ec81033 html5lib==1.1 ; python_version >= "3.8" and python_version < "4.0" \ --hash=sha256:0d78f8fde1c230e99fe37986a60526d7049ed4bf8a9fadbad5f00e22e58e041d \ --hash=sha256:b2e5b40261e20f354d198eae92afc10d750afb487ed5e50f9c4eaf07c184146f @@ -329,6 +332,9 @@ netaddr==1.2.1 ; python_version >= "3.8" and python_version < "4.0" \ oscrypto==1.3.0 ; python_version >= "3.8" and python_version < "4.0" \ --hash=sha256:2b2f1d2d42ec152ca90ccb5682f3e051fb55986e1b170ebde472b133713e7085 \ --hash=sha256:6f5fef59cb5b3708321db7cca56aed8ad7e662853351e7991fcf60ec606d47a4 +packaging==23.2 ; python_version >= "3.8" and python_version < "4.0" \ + --hash=sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5 \ + --hash=sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7 pillow==8.4.0 ; python_version >= "3.8" and python_version < "4.0" \ --hash=sha256:066f3999cb3b070a95c3652712cffa1a748cd02d60ad7b4e485c3748a04d9d76 \ --hash=sha256:0a0956fdc5defc34462bb1c765ee88d933239f9a94bc37d132004775241a7585 \ diff --git a/mysql-requirements.txt b/mysql-requirements.txt index 20fec501..2ebece67 100644 --- a/mysql-requirements.txt +++ b/mysql-requirements.txt @@ -235,6 +235,9 @@ gitdb==4.0.11 ; python_version >= "3.8" and python_version < "4.0" \ gitpython==3.1.42 ; python_version >= "3.8" and python_version < "4.0" \ --hash=sha256:1bf9cd7c9e7255f77778ea54359e54ac22a72a5b51288c457c881057b7bb9ecd \ --hash=sha256:2d99869e0fef71a73cbd242528105af1d6c1b108c60dfabd994bf292f76c3ceb +gunicorn==21.2.0 ; python_version >= "3.8" and python_version < "4.0" \ + --hash=sha256:3213aa5e8c24949e792bcacfc176fef362e7aac80b76c56f6b5122bf350722f0 \ + --hash=sha256:88ec8bff1d634f98e61b9f65bc4bf3cd918a90806c6f5c48bc5603849ec81033 html5lib==1.1 ; python_version >= "3.8" and python_version < "4.0" \ --hash=sha256:0d78f8fde1c230e99fe37986a60526d7049ed4bf8a9fadbad5f00e22e58e041d \ --hash=sha256:b2e5b40261e20f354d198eae92afc10d750afb487ed5e50f9c4eaf07c184146f @@ -336,6 +339,9 @@ netaddr==1.2.1 ; python_version >= "3.8" and python_version < "4.0" \ oscrypto==1.3.0 ; python_version >= "3.8" and python_version < "4.0" \ --hash=sha256:2b2f1d2d42ec152ca90ccb5682f3e051fb55986e1b170ebde472b133713e7085 \ --hash=sha256:6f5fef59cb5b3708321db7cca56aed8ad7e662853351e7991fcf60ec606d47a4 +packaging==23.2 ; python_version >= "3.8" and python_version < "4.0" \ + --hash=sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5 \ + --hash=sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7 pillow==8.4.0 ; python_version >= "3.8" and python_version < "4.0" \ --hash=sha256:066f3999cb3b070a95c3652712cffa1a748cd02d60ad7b4e485c3748a04d9d76 \ --hash=sha256:0a0956fdc5defc34462bb1c765ee88d933239f9a94bc37d132004775241a7585 \ diff --git a/poetry.lock b/poetry.lock index f0704164..3d91ad65 100644 --- a/poetry.lock +++ b/poetry.lock @@ -670,6 +670,26 @@ gitdb = ">=4.0.1,<5" [package.extras] test = ["black", "coverage[toml]", "ddt (>=1.1.1,!=1.4.3)", "mock", "mypy", "pre-commit", "pytest (>=7.3.1)", "pytest-cov", "pytest-instafail", "pytest-mock", "pytest-sugar"] +[[package]] +name = "gunicorn" +version = "21.2.0" +description = "WSGI HTTP Server for UNIX" +optional = false +python-versions = ">=3.5" +files = [ + {file = "gunicorn-21.2.0-py3-none-any.whl", hash = "sha256:3213aa5e8c24949e792bcacfc176fef362e7aac80b76c56f6b5122bf350722f0"}, + {file = "gunicorn-21.2.0.tar.gz", hash = "sha256:88ec8bff1d634f98e61b9f65bc4bf3cd918a90806c6f5c48bc5603849ec81033"}, +] + +[package.dependencies] +packaging = "*" + +[package.extras] +eventlet = ["eventlet (>=0.24.1)"] +gevent = ["gevent (>=1.4.0)"] +setproctitle = ["setproctitle"] +tornado = ["tornado (>=0.2)"] + [[package]] name = "html5lib" version = "1.1" @@ -2165,4 +2185,4 @@ postgresql = ["psycopg2"] [metadata] lock-version = "2.0" python-versions = ">=3.8,<4.0" -content-hash = "35c7fcf4285d44bb7287cb8d9573f327beec53c61979faae77a8c077c2560930" +content-hash = "f50b5e6d4c12f6c66b56d79a0999d353df86a887d003d3059a206b1373da5b7f" diff --git a/postgresql-requirements.txt b/postgresql-requirements.txt index 651bfcf9..fc3d7f35 100644 --- a/postgresql-requirements.txt +++ b/postgresql-requirements.txt @@ -235,6 +235,9 @@ gitdb==4.0.11 ; python_version >= "3.8" and python_version < "4.0" \ gitpython==3.1.42 ; python_version >= "3.8" and python_version < "4.0" \ --hash=sha256:1bf9cd7c9e7255f77778ea54359e54ac22a72a5b51288c457c881057b7bb9ecd \ --hash=sha256:2d99869e0fef71a73cbd242528105af1d6c1b108c60dfabd994bf292f76c3ceb +gunicorn==21.2.0 ; python_version >= "3.8" and python_version < "4.0" \ + --hash=sha256:3213aa5e8c24949e792bcacfc176fef362e7aac80b76c56f6b5122bf350722f0 \ + --hash=sha256:88ec8bff1d634f98e61b9f65bc4bf3cd918a90806c6f5c48bc5603849ec81033 html5lib==1.1 ; python_version >= "3.8" and python_version < "4.0" \ --hash=sha256:0d78f8fde1c230e99fe37986a60526d7049ed4bf8a9fadbad5f00e22e58e041d \ --hash=sha256:b2e5b40261e20f354d198eae92afc10d750afb487ed5e50f9c4eaf07c184146f @@ -326,6 +329,9 @@ netaddr==1.2.1 ; python_version >= "3.8" and python_version < "4.0" \ oscrypto==1.3.0 ; python_version >= "3.8" and python_version < "4.0" \ --hash=sha256:2b2f1d2d42ec152ca90ccb5682f3e051fb55986e1b170ebde472b133713e7085 \ --hash=sha256:6f5fef59cb5b3708321db7cca56aed8ad7e662853351e7991fcf60ec606d47a4 +packaging==23.2 ; python_version >= "3.8" and python_version < "4.0" \ + --hash=sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5 \ + --hash=sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7 pillow==8.4.0 ; python_version >= "3.8" and python_version < "4.0" \ --hash=sha256:066f3999cb3b070a95c3652712cffa1a748cd02d60ad7b4e485c3748a04d9d76 \ --hash=sha256:0a0956fdc5defc34462bb1c765ee88d933239f9a94bc37d132004775241a7585 \ diff --git a/pyproject.toml b/pyproject.toml index 285e8d32..fd097454 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,6 +62,7 @@ xhtml2pdf = "^0.2.6" pylint-django = {version = "^2.5.5", optional=true} pylint = {version = "^3.1.0", optional=true} python-decouple = "^3.8" +gunicorn = "^21.2.0" [tool.poetry.extras] mysql = ["mysqlclient"] diff --git a/requirements.txt b/requirements.txt index f1157374..1dfab524 100644 --- a/requirements.txt +++ b/requirements.txt @@ -235,6 +235,9 @@ gitdb==4.0.11 ; python_version >= "3.8" and python_version < "4.0" \ gitpython==3.1.42 ; python_version >= "3.8" and python_version < "4.0" \ --hash=sha256:1bf9cd7c9e7255f77778ea54359e54ac22a72a5b51288c457c881057b7bb9ecd \ --hash=sha256:2d99869e0fef71a73cbd242528105af1d6c1b108c60dfabd994bf292f76c3ceb +gunicorn==21.2.0 ; python_version >= "3.8" and python_version < "4.0" \ + --hash=sha256:3213aa5e8c24949e792bcacfc176fef362e7aac80b76c56f6b5122bf350722f0 \ + --hash=sha256:88ec8bff1d634f98e61b9f65bc4bf3cd918a90806c6f5c48bc5603849ec81033 html5lib==1.1 ; python_version >= "3.8" and python_version < "4.0" \ --hash=sha256:0d78f8fde1c230e99fe37986a60526d7049ed4bf8a9fadbad5f00e22e58e041d \ --hash=sha256:b2e5b40261e20f354d198eae92afc10d750afb487ed5e50f9c4eaf07c184146f @@ -326,6 +329,9 @@ netaddr==1.2.1 ; python_version >= "3.8" and python_version < "4.0" \ oscrypto==1.3.0 ; python_version >= "3.8" and python_version < "4.0" \ --hash=sha256:2b2f1d2d42ec152ca90ccb5682f3e051fb55986e1b170ebde472b133713e7085 \ --hash=sha256:6f5fef59cb5b3708321db7cca56aed8ad7e662853351e7991fcf60ec606d47a4 +packaging==23.2 ; python_version >= "3.8" and python_version < "4.0" \ + --hash=sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5 \ + --hash=sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7 pillow==8.4.0 ; python_version >= "3.8" and python_version < "4.0" \ --hash=sha256:066f3999cb3b070a95c3652712cffa1a748cd02d60ad7b4e485c3748a04d9d76 \ --hash=sha256:0a0956fdc5defc34462bb1c765ee88d933239f9a94bc37d132004775241a7585 \