Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Commit

Permalink
improve docker-compose configuration with thumbor
Browse files Browse the repository at this point in the history
  • Loading branch information
monodo committed Dec 5, 2023
1 parent de5e886 commit 1229d8c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
9 changes: 6 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Copy this to `.env` and adapt to your needs.

# Which docker-compose to load (ON PRODUCTION, USE ONLY docker-compose.yml !!)
# If you need to connect to thumbor image service, simply use:
# COMPOSE_FILE=docker-compose.yml:docker-compose.thumbor.yml
COMPOSE_FILE=docker-compose.yml:docker-compose.dev.yml
COMPOSE_PATH_SEPARATOR=:

Expand Down Expand Up @@ -93,6 +95,7 @@ LOCAL_TIME_ZONE_UTC=+1
SITE_DOMAIN=None
# Use thumbor service to resize images (used by Agenda module)
USE_THUMBOR=false
# Geocity network in order to communicate with other docker services on same host
# This has to be unique for multiple instance on same docker host
GEOCITY_NETWORK_NAME=geocity_network_dev
# URL of the thumbor service to use
# For dockerized thumbor service not exposed over the Internet, attache Geocity to its network with this override on top of this file:
# COMPOSE_FILE=docker-compose.yml:docker-compose.thumbor.yml
THUMBOR_SERVICE_URL="http://nginx-proxy"
13 changes: 13 additions & 0 deletions docker-compose.thumbor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Simple override in order to setup network for using thumbor image service
volumes:
static_root:

services:
web: # Name of this container should not be changed
networks:
- thumbor_network
networks:
# Use this network to communicate with thumbor image resize service
# More information here: https://gitlab.com/geocity/thumbor-service
thumbor_network:
external: true
4 changes: 1 addition & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ services:
LOCAL_TIME_ZONE_UTC:
SITE_DOMAIN:
USE_THUMBOR:
THUMBOR_SERVICE_URL:
ports:
- "${DJANGO_DOCKER_PORT}:9000"
networks:
- isolated
- default
- thumbor_network

# Builder for the geocity_qgis image.
qgis:
Expand Down Expand Up @@ -115,5 +115,3 @@ networks:
# Use this for containers that should only be able to communicate with Django
isolated:
name: ${ISOLATED_NETWORK_NAME}
thumbor_network:
external: true
5 changes: 3 additions & 2 deletions geocity/apps/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os

import requests
from constance import config
from django.conf import settings
from django.contrib.auth.models import AnonymousUser, User
from django.db.models import F, Prefetch, Q
Expand Down Expand Up @@ -521,12 +520,14 @@ def image_thumbor_display(request, submission_id, image_name):
thumbor_params += f"{width}x{height}/filters:format({format})"

if settings.USE_THUMBOR:
print(settings.THUMBOR_SERVICE_URL)
try:
response = requests.get(
f"{config.THUMBOR_SERVICE_URL}/{thumbor_params}/{image_url}"
f"{settings.THUMBOR_SERVICE_URL}/{thumbor_params}/{image_url}"
)
except requests.exceptions.RequestException as e:
response = requests.get(image_url)
print(e)
else:
response = requests.get(image_url)

Expand Down
10 changes: 3 additions & 7 deletions geocity/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@
# Allow REMOTE_USER Authentication
ALLOW_REMOTE_USER_AUTH = os.getenv("ALLOW_REMOTE_USER_AUTH", "false").lower() == "true"

# IBAN for UserProfile model
# Thumbor image service
USE_THUMBOR = os.getenv("USE_THUMBOR", "true").lower() == "true"
THUMBOR_SERVICE_URL = os.getenv("THUMBOR_SERVICE_URL", "None")

SITE_HTTPS = ENV == "PROD"

# Allow CORS in DEV, needed for development of geocity_front, where the frontend domain is different
Expand Down Expand Up @@ -270,7 +272,6 @@
"IP_WHITELIST",
"NETWORK_WHITELIST",
"LOGOUT_REDIRECT_HOSTNAME_WHITELIST",
"THUMBOR_SERVICE_URL",
),
}

Expand Down Expand Up @@ -416,11 +417,6 @@
"localhost,geocity.ch",
"Domaines autorisés à la redirection après logout",
),
"THUMBOR_SERVICE_URL": (
"http://nginx-proxy",
"URL du service thumbor (https://github.com/thumbor/thumbor), recommandé pour l'optimisation des images du module Agenda",
str,
),
}

TEMPLATES = [
Expand Down

0 comments on commit 1229d8c

Please sign in to comment.