diff --git a/caretech/map/Dockerfile b/caretech/map/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..af41e8c576bf58a4326a3ea64bf86159cfc73213 --- /dev/null +++ b/caretech/map/Dockerfile @@ -0,0 +1,59 @@ +FROM python:3.8-buster + +ARG UMAP_VERSION=1.2.1 + +ENV PYTHONUNBUFFERED=1 \ + UMAP_SETTINGS=/srv/umap/settings.py \ + PORT=8000 + +# Create a user account and group to run uMap +RUN mkdir -p /srv/umap/{data,uploads} && \ + chown -R 10001:10001 /srv/umap && \ + groupadd --gid 10001 umap && \ + useradd --no-create-home --uid 10001 --gid 10001 --home-dir /srv/umap umap + +# Install dependencies +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + binutils \ + libproj-dev \ + gdal-bin \ + build-essential \ + curl \ + libpq-dev \ + postgresql-client \ + gettext \ + libffi-dev \ + libtiff5-dev \ + libjpeg62-turbo-dev \ + zlib1g-dev \ + libfreetype6-dev \ + liblcms2-dev \ + libwebp-dev \ + unzip && \ + apt-get autoremove -y && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +WORKDIR /srv/umap + +COPY requirements-docker.txt . + +# Get uMap +pip install umap-project=${UMAP_VERSION} + +# Install Docker dependencies +pip install -r requirements-docker.txt + +COPY entrypoint.sh . +COPY settings.py . + +RUN chmod +x entrypoint.sh +RUN chown -R umap:umap . + +USER umap + +EXPOSE 8000 + +ENTRYPOINT [ "/srv/umap/entrypoint.sh" ] +CMD [ "umap", "runserver", "0.0.0.0:8000" ] diff --git a/caretech/map/docker-compose.yml b/caretech/map/docker-compose.yml new file mode 100644 index 0000000000000000000000000000000000000000..be70ecbec0d35d2433c124e810beb9e47769f69d --- /dev/null +++ b/caretech/map/docker-compose.yml @@ -0,0 +1,58 @@ +version: '3.7' + +volumes: + app: + name: umap-caretech + db: + name: umap-db-caretech + redis: + name: umap-redis-caretech + +networks: + proxy: + external: true + db: + name: umap-caretech + +services: + app: + image: registry.picasoft.net/pica-umap:1.2.1 + build: . + container_name: umap-caretech + env_file: ./secrets/umap.secrets + environment: + - REDIS_URL=redis://redis:6379/0 + - SITE_URL=https://carte.caretech.picasoft.net + # Do not allow non-authenticated users to create maps + - LEAFLET_STORAGE_ALLOW_ANONYMOUS=False + volumes: + - app:/srv/umap + labels: + traefik.http.routers.etherpad-app.entrypoints: websecure + traefik.http.routers.etherpad-app.rule: Host(`carte.caretech.picasoft.net`) + traefik.http.services.etherpad-app.loadbalancer.server.port: 8000 + traefik.enable: true + networks: + - proxy + - db + + db: + image: postgis/postgis:12-3.0-alpine + container_name: umap-db-caretech + environment: + POSTGRES_DB: caretech + env_file: ./secrets/db.secrets + volumes: + - db:/var/lib/postgresql/data + networks: + - db + restart: unless-stopped + + redis: + image: redis:6 + container_name: umap-redis-caretech + volumes: + - redis:/data + networks: + - db + restart: unless-stopped diff --git a/caretech/map/entrypoint.sh b/caretech/map/entrypoint.sh new file mode 100644 index 0000000000000000000000000000000000000000..fc926ab5d696a4acb3d61c8e0eb5555de482072c --- /dev/null +++ b/caretech/map/entrypoint.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +set -eo pipefail + +# default variables +: "${SLEEP:=1}" +: "${TRIES:=60}" + +function wait_for_database {( + echo "Waiting for database to respond..." + tries=0 + while true; do + [[ $tries -lt $TRIES ]] || return + (echo "from django.db import connection; connection.connect()" | umap shell) >/dev/null 2>&1 + [[ $? -eq 0 ]] && return + sleep $SLEEP + tries=$((tries + 1)) + done +)} + +# first wait for the database +wait_for_database +# then migrate the database +umap migrate +# then collect static files +umap collectstatic --noinput +# create languagae files +umap storagei18n +# compress static files +umap compress +# run uWSGI +exec uwsgi --ini uwsgi.ini diff --git a/caretech/map/requirements-docker.txt b/caretech/map/requirements-docker.txt new file mode 100644 index 0000000000000000000000000000000000000000..b1955e873312fb2b079575f6c42411cf7cbe79fe --- /dev/null +++ b/caretech/map/requirements-docker.txt @@ -0,0 +1,3 @@ +django-environ==0.4.1 +django-redis==4.7.0 +uwsgi==2.0.14 diff --git a/caretech/map/secrets/db.secrets.example b/caretech/map/secrets/db.secrets.example new file mode 100644 index 0000000000000000000000000000000000000000..5f36d5873959a63a464d9ba8ba7a1decde0acd8e --- /dev/null +++ b/caretech/map/secrets/db.secrets.example @@ -0,0 +1,2 @@ +POSTGRES_USER=user +POSTGRES_PASSWORD=password diff --git a/caretech/map/secrets/umap.secrets.example b/caretech/map/secrets/umap.secrets.example new file mode 100644 index 0000000000000000000000000000000000000000..ad750c0814bb91d8282ed687243ceae4e5d5c286 --- /dev/null +++ b/caretech/map/secrets/umap.secrets.example @@ -0,0 +1,9 @@ +# Very long and random key +SECRET_KEY= +# Email, comma-separated +ADMIN_EMAIL= +# Database URL +DATABASE_URL=postgis://user:password@umap-db-caretech/caretech +# OpenStreetMap token +OPENSTREETMAP_KEY= +OPENSTREETMAP_SECRET= diff --git a/caretech/map/settings.py b/caretech/map/settings.py new file mode 100644 index 0000000000000000000000000000000000000000..3f49a3ce01a4c3a600c3feb429ba509aa1e94a21 --- /dev/null +++ b/caretech/map/settings.py @@ -0,0 +1,107 @@ +# -*- coding:utf-8 -*- +""" +Settings for Docker development +Use this file as a base for your local development settings and copy +it to umap/settings/local.py. It should not be checked into +your code repository. +""" +import environ +from umap.settings.base import * + +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='*') + +DEBUG = env.bool('DEBUG', default=False) + +ADMIN_EMAILS = env.list('ADMIN_EMAIL', default='') +ADMINS = [(email, email) for email in ADMIN_EMAILS] +MANAGERS = ADMINS + +DATABASES = { + 'default': env.db() +} + +COMPRESS_ENABLED = True +COMPRESS_OFFLINE = True + +LANGUAGE_CODE = 'fr' + +# Set to False if login into django account should not be possible. You can +# administer accounts in the admin interface. +ENABLE_ACCOUNT_LOGIN = env.bool('ENABLE_ACCOUNT_LOGIN', default=True) + +AUTHENTICATION_BACKENDS = () + +# We need email to associate with other Oauth providers +SOCIAL_AUTH_OPENSTREETMAP_KEY = env('OPENSTREETMAP_KEY', default='') +SOCIAL_AUTH_OPENSTREETMAP_SECRET = env('OPENSTREETMAP_SECRET', default='') +if SOCIAL_AUTH_OPENSTREETMAP_KEY and SOCIAL_AUTH_OPENSTREETMAP_SECRET: + AUTHENTICATION_BACKENDS += ( + 'social_core.backends.openstreetmap.OpenStreetMapOAuth', + ) + +AUTHENTICATION_BACKENDS += ( + 'django.contrib.auth.backends.ModelBackend', +) + +MIDDLEWARE_CLASSES += ( + 'social_django.middleware.SocialAuthExceptionMiddleware', +) + +SOCIAL_AUTH_RAISE_EXCEPTIONS = False +SOCIAL_AUTH_BACKEND_ERROR_URL = "/" + +# If you want to add a playgroud map, add its primary key +# UMAP_DEMO_PK = 204 +# If you want to add a showcase map on the home page, add its primary key +# UMAP_SHOWCASE_PK = 1156 +# Add a baner to warn people this instance is not production ready. +UMAP_DEMO_SITE = False + +# Whether to allow non authenticated people to create maps. +LEAFLET_STORAGE_ALLOW_ANONYMOUS = env.bool( + 'LEAFLET_STORAGE_ALLOW_ANONYMOUS', + default=False, +) + +# This setting will exclude empty maps (in fact, it will exclude all maps where +# the default center has not been updated) +UMAP_EXCLUDE_DEFAULT_MAPS = False + +# How many maps should be showcased on the main page resp. on the user page +UMAP_MAPS_PER_PAGE = 5 +# How many maps should be showcased on the user page, if owner +UMAP_MAPS_PER_PAGE_OWNER = 10 + +SITE_URL = env('SITE_URL') +SHORT_SITE_URL = env('SHORT_SITE_URL', default=None) + +CACHES = {'default': env.cache('REDIS_URL', default='locmem://')} + +# POSTGIS_VERSION = (2, 1, 0) +EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' + +# You need to unable accent extension before using UMAP_USE_UNACCENT +# python manage.py dbshell +# CREATE EXTENSION unaccent; +UMAP_USE_UNACCENT = False + +# For static deployment +STATIC_ROOT = '/srv/umap/static' + +# For users' statics (geojson mainly) +MEDIA_ROOT = '/srv/umap/uploads' + +# Default map location for new maps +LEAFLET_LONGITUDE = env.int('LEAFLET_LONGITUDE', default=2) +LEAFLET_LATITUDE = env.int('LEAFLET_LATITUDE', default=51) +LEAFLET_ZOOM = env.int('LEAFLET_ZOOM', default=6) + +# Number of old version to keep per datalayer. +LEAFLET_STORAGE_KEEP_VERSIONS = env.int( + 'LEAFLET_STORAGE_KEEP_VERSIONS', + default=10, +) diff --git a/caretech/wiki/docker-compose.yml b/caretech/wiki/docker-compose.yml index 792d94b12f841b1fa42280ef555fd4aaea3e7bd1..9b504842cb7ad6b941a8c4542f338738c313e590 100644 --- a/caretech/wiki/docker-compose.yml +++ b/caretech/wiki/docker-compose.yml @@ -1,8 +1,8 @@ version: '3.7' volumes: - wiki-caretech: - name: wiki-caretech + db: + name: wiki-caretech-db networks: proxy: @@ -33,7 +33,7 @@ services: image: postgres:12-alpine container_name: wiki-db-caretech volumes: - - wiki-caretech:/var/lib/postgresql/data + - db:/var/lib/postgresql/data env_file: ./secrets/db.secrets networks: - db