wip: make Redis service optional in Docker image

Co-authored-by: David Larlet <david@larlet.fr>
This commit is contained in:
Yohan Boniface 2025-04-03 17:12:12 +02:00
parent d72debdeb2
commit 023645a160
6 changed files with 44 additions and 32 deletions

View file

@ -6,7 +6,6 @@ RUN apt-get update && \
tini \ tini \
sqlite3 \ sqlite3 \
libpq-dev \ libpq-dev \
redis-server \
gdal-bin \ gdal-bin \
&& \ && \
apt-get autoremove -y && \ apt-get autoremove -y && \

View file

@ -1,5 +1,15 @@
services: services:
# Usefull only to use the real time collaboration
redis:
image: redis:latest
healthcheck:
test: ["CMD-SHELL", "redis-cli ping | grep PONG"]
interval: 1s
timeout: 3s
retries: 5
command: ["redis-server"]
db: db:
healthcheck: healthcheck:
test: [ "CMD-SHELL", "pg_isready -U postgres" ] test: [ "CMD-SHELL", "pg_isready -U postgres" ]
@ -14,7 +24,9 @@ services:
depends_on: depends_on:
db: db:
condition: service_healthy condition: service_healthy
image: umap/umap:2.0.2 redis:
condition: service_healthy
image: umap/umap:2.9.3
ports: ports:
- "${PORT-8000}:8000" - "${PORT-8000}:8000"
environment: environment:
@ -23,6 +35,8 @@ services:
- SITE_URL=https://umap.local/ - SITE_URL=https://umap.local/
- UMAP_ALLOW_ANONYMOUS=True - UMAP_ALLOW_ANONYMOUS=True
- DEBUG=1 - DEBUG=1
- WEBSOCKET_ENABLED=1
- REDIS_URL=redis://redis:6379
volumes: volumes:
- data:/srv/umap/uploads - data:/srv/umap/uploads

View file

@ -2,7 +2,6 @@
set -eo pipefail set -eo pipefail
source /venv/bin/activate source /venv/bin/activate
service redis-server start
# collect static files # collect static files
umap collectstatic --noinput umap collectstatic --noinput
@ -11,4 +10,4 @@ umap wait_for_database
# then migrate the database # then migrate the database
umap migrate umap migrate
# run the server # run the server
exec uvicorn --proxy-headers --no-access-log umap.asgi:application exec uvicorn --proxy-headers --no-access-log --host 0.0.0.0 umap.asgi:application

View file

@ -1,26 +0,0 @@
[uwsgi]
http = :$(PORT)
home = /venv
module = umap.wsgi:application
master = True
vacuum = True
max-requests = 5000
processes = 4
enable-threads = true
static-map = /static=/srv/umap/static
static-map = /uploads=/srv/umap/uploads
buffer-size = 32768
; Run the websocket server only when the env variable
; WEBSOCKET_ENABLED is set to True.
; This is enough for the base docker image, but does not
; take into account the settings as the source of truth.
if-env = WEBSOCKET_ENABLED
websocket_enabled = %(_)
endif =
if-opt = websocket_enabled=True
print = Starting the Websocket Server (WEBSOCKET_ENABLED=%(websocket_enabled))
attach-daemon = umap run_websocket_server
endif =
lazy-apps = true

View file

@ -14,7 +14,7 @@ services:
app: app:
# Check https://hub.docker.com/r/umap/umap/tags to find the latest version # Check https://hub.docker.com/r/umap/umap/tags to find the latest version
image: umap/umap:2.0.2 image: umap/umap:2.9.3
ports: ports:
# modify the external port (8001, on the left) if desired, but make sure it matches SITE_URL, below # modify the external port (8001, on the left) if desired, but make sure it matches SITE_URL, below
- "8001:8000" - "8001:8000"
@ -64,3 +64,29 @@ And run it with:
```bash ```bash
podman run -v ./umap.conf:/tmp/umap.conf -e UMAP_SETTINGS=/tmp/umap.conf -it --network host umap podman run -v ./umap.conf:/tmp/umap.conf -e UMAP_SETTINGS=/tmp/umap.conf -it --network host umap
``` ```
## Real time collaboration
To enable real time collaboration when using Docker, a Redis service must be added. Something like this in `docker-compose.py` world:
```yaml title="docker-compose.yml"
services
redis:
image: redis:latest
healthcheck:
test: ["CMD-SHELL", "redis-cli ping | grep PONG"]
command: ["redis-server"]
app:
depends_on:
redis:
condition: service_healthy
environment:
- WEBSOCKET_ENABLED=1
- REDIS_URL=redis://redis:6379
```

View file

@ -346,4 +346,4 @@ WEBSOCKET_ENABLED = env.bool("WEBSOCKET_ENABLED", default=False)
WEBSOCKET_BACK_HOST = env("WEBSOCKET_BACK_HOST", default="localhost") WEBSOCKET_BACK_HOST = env("WEBSOCKET_BACK_HOST", default="localhost")
WEBSOCKET_BACK_PORT = env.int("WEBSOCKET_BACK_PORT", default=8001) WEBSOCKET_BACK_PORT = env.int("WEBSOCKET_BACK_PORT", default=8001)
REDIS_URL = "redis://localhost:6379" REDIS_URL = env("REDIS_URL", default="redis://localhost:6379")