diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..faac0e23 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.vscode/ +.venv/ +build/ +static/ +umap_project.egg-info/ +data/ diff --git a/.gitignore b/.gitignore index d236ae74..2dd0996e 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,8 @@ node_modules/* umap/static/umap/vendors site/* .pytest_cache/ +static/ +uploads/ ### Python ### # Byte-compiled / optimized / DLL files @@ -18,3 +20,6 @@ build/ dist/ *.egg-info/ +.env +.venv/ + diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..b4627221 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Remote Attach", + "type": "python", + "request": "attach", + "connect": { + "host": "localhost", + "port": 5678 + }, + "pathMappings": [ + { + "localRoot": "${workspaceFolder}/umap/", + "remoteRoot": "/srv/app/umap/" + } + ], + "justMyCode": false + } + ] +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index e8a523cf..34df0aee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,13 @@ FROM node:18 AS vendors -COPY . /srv/umap +COPY . /srv/app -WORKDIR /srv/umap +WORKDIR /srv/app RUN make installjs - RUN make vendors -FROM python:3.8-slim - -ENV PYTHONUNBUFFERED=1 \ - UMAP_SETTINGS=/srv/umap/umap/settings/docker.py \ - PORT=8000 - -RUN mkdir -p /srv/umap/data && \ - mkdir -p /srv/umap/uploads - -COPY . /srv/umap - -COPY --from=vendors /srv/umap/umap/static/umap/vendors /srv/umap/umap/static/umap/vendors - -WORKDIR /srv/umap +FROM python:3.8-slim as app_python RUN apt-get update && \ apt-get install -y --no-install-recommends \ @@ -42,10 +28,21 @@ RUN apt-get update && \ zlib1g-dev \ libfreetype6-dev \ liblcms2-dev \ - libwebp-dev \ - && \ - pip install --no-cache -r requirements-docker.txt && pip install . && \ - apt-get remove -y \ + libwebp-dev + +ENV PYTHONUNBUFFERED=1 \ + UMAP_SETTINGS=/srv/app/umap/settings/docker.py \ + PORT=8000 + +COPY . /srv/app +RUN mkdir -p /srv/app/data && \ + mkdir -p /srv/app/uploads +COPY --from=vendors /srv/app/umap/static/umap/vendors /srv/app/umap/static/umap/vendors + +WORKDIR /srv/app + +RUN pip install --no-cache -r requirements-docker.txt && pip install . +RUN apt-get remove -y \ binutils \ libproj-dev \ libffi-dev \ @@ -64,4 +61,10 @@ EXPOSE 8000 ENTRYPOINT ["/usr/bin/tini", "--"] -CMD ["/srv/umap/docker-entrypoint.sh"] +CMD ["/srv/app/docker-entrypoint.sh"] + +FROM app_python as app_python_debug + +WORKDIR /srv/app + +RUN pip install debugpy==1.6.7 diff --git a/docker-compose.override.yml b/docker-compose.override.yml new file mode 100644 index 00000000..8147feb0 --- /dev/null +++ b/docker-compose.override.yml @@ -0,0 +1,14 @@ +version: '2' + +services: + + app: + build: + target: app_python_debug + environment: + PYTHON_DEBUG: True + volumes: + - ./umap:/srv/app/umap + ports: + - 8000:8000 + - 5678:5678 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..90602663 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,28 @@ +version: '2' +services: + postgres: + image: postgis/postgis:14-3.2 + environment: + POSTGRES_PASSWORD: postgres + POSTGRES_USER: postgres + volumes: + - ./data:/var/lib/postgresql/data + redis: + image: redis:latest + app: + build: + context: . + target: app_python + environment: + DATABASE_URL: postgis://postgres:postgres@postgres/postgres + REDIS_URL: redis://redis:6379/0 + SECRET_KEY: some-long-and-weirdly-unrandom-secret-key + ALLOWED_HOSTS: "*" + SITE_URL: http://localhost:8000/ + LEAFLET_STORAGE_ALLOW_ANONYMOUS: true + depends_on: + - postgres + volumes: + - $PWD:/srv/umap + ports: + - "8000:8000" diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index cf4094f0..9e044821 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -27,5 +27,9 @@ umap collectstatic --noinput #umap storagei18n # compress static files umap compress -# run uWSGI -exec uwsgi --ini uwsgi.ini + +if [ "$PYTHON_DEBUG" = true ] ; then + python -m debugpy --listen 0.0.0.0:5678 manage.py runserver 0.0.0.0:8000 --nothreading --noreload +else + exec uwsgi --ini uwsgi.ini +fi diff --git a/requirements-docker.txt b/requirements-docker.txt index b1955e87..f4b99064 100644 --- a/requirements-docker.txt +++ b/requirements-docker.txt @@ -1,3 +1,3 @@ django-environ==0.4.1 -django-redis==4.7.0 -uwsgi==2.0.14 +django-redis==5.2.0 +uwsgi==2.0.21 diff --git a/umap/settings/dev.py b/umap/settings/dev.py index 9439e43b..327898ab 100644 --- a/umap/settings/dev.py +++ b/umap/settings/dev.py @@ -12,5 +12,6 @@ DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'umap', + 'SECRET_KEY': 'some-long-and-weirdly-unrandom-secret-key', } } diff --git a/umap/settings/docker.py b/umap/settings/docker.py index 097a35da..b405cc7e 100644 --- a/umap/settings/docker.py +++ b/umap/settings/docker.py @@ -13,9 +13,9 @@ env = environ.Env() SECRET_KEY = env('SECRET_KEY') INTERNAL_IPS = env.list('INTERNAL_IPS', default='127.0.0.1') -ALLOWED_HOSTS = env.list('ALLOWED_HOSTS', default='*') +ALLOWED_HOSTS = env.list('ALLOWED_HOSTS', default=['*']) -DEBUG = env.bool('DEBUG', default=False) +DEBUG = env.bool('PYTHON_DEBUG', default=False) ADMIN_EMAILS = env.list('ADMIN_EMAIL', default='') ADMINS = [(email, email) for email in ADMIN_EMAILS] @@ -111,10 +111,10 @@ EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' UMAP_USE_UNACCENT = False # For static deployment -STATIC_ROOT = '/srv/umap/static' +STATIC_ROOT = '/srv/app/static' # For users' statics (geojson mainly) -MEDIA_ROOT = '/srv/umap/uploads' +MEDIA_ROOT = '/srv/app/uploads' # Default map location for new maps LEAFLET_LONGITUDE = env.int('LEAFLET_LONGITUDE', default=2) diff --git a/uwsgi.ini b/uwsgi.ini index 2cf2c279..e42c8feb 100644 --- a/uwsgi.ini +++ b/uwsgi.ini @@ -6,5 +6,5 @@ vacuum = True max-requests = 5000 processes = 4 enable-threads = true -static-map = /static=/srv/umap/static -static-map = /uploads=/srv/umap/uploads +static-map = /static=/srv/app/static +static-map = /uploads=/srv/app/uploads