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

add env variable for THUMBOR and allow to set network name in .env #899

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ LOCATIONS_SEARCH_API="https://api3.geo.admin.ch/rest/services/api/SearchServer"
LOCATIONS_SEARCH_API_DETAILS="https://api3.geo.admin.ch/rest/services/api/MapServer/ch.bfs.gebaeude_wohnungs_register/"
# Local directory on docker host for temporary storage of archive folders
ARCHIVE_DIR=
# Isolated network for print service
# This has to be unique for multiple instance on same docker host
ISOLATED_NETWORK_NAME=geocity_isolated_1
# IBAN for user profile, true will show in submission detail and section author
Expand All @@ -90,3 +91,8 @@ PAYMENT_PROCESSING_TEST_ENVIRONMENT=true
LOCAL_TIME_ZONE_UTC=+1
# Use "localhost" in local
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
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,5 @@ networks:
isolated:
name: ${ISOLATED_NETWORK_NAME}
geocity_network:
name: geocity_network
name: ${GEOCITY_NETWORK_NAME}
driver: bridge
13 changes: 8 additions & 5 deletions geocity/apps/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,14 @@ def image_thumbor_display(request, submission_id, image_name):

thumbor_params += f"{width}x{height}/filters:format({format})"

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

mime_type = get_mime_type(response.content)
Expand Down
3 changes: 3 additions & 0 deletions geocity/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
# Allow REMOTE_USER Authentication
ALLOW_REMOTE_USER_AUTH = os.getenv("ALLOW_REMOTE_USER_AUTH", "false").lower() == "true"

# IBAN for UserProfile model
USE_THUMBOR = os.getenv("USE_THUMBOR", "false").lower() == "true"

SITE_HTTPS = ENV == "PROD"

# Allow CORS in DEV, needed for development of geocity_front, where the frontend domain is different
Expand Down