From c05402b6f3f6386f29021e14d27661f8f2cc5490 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Fri, 7 Nov 2025 23:50:18 +0100 Subject: [PATCH] Allow S3 storage backend to be used in self-hosted instances --- CHANGELOG.md | 1 + config/environments/development.rb | 4 ++-- config/environments/production.rb | 4 ++-- config/environments/staging.rb | 2 +- config/storage.yml | 3 ++- docker/.env.example | 8 ++++---- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5f46f21..a0a6c870 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Changed - Removed useless system tests and cover map functionality with Playwright e2e tests instead. +- S3 storage now can be used in self-hosted instances as well. Set STORAGE_BACKEND environment variable to "s3" and provide AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION, AWS_BUCKET and AWS_ENDPOINT_URL environment variables to configure it. - Number of family members on self-hosted instances is no longer limited. - Export to GPX now adds adds speed and course to each point if they are available. - `docker-compose.yml` file updated to provide sensible defaults for self-hosted production environment. diff --git a/config/environments/development.rb b/config/environments/development.rb index c940de0e..4b5e99bf 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -86,7 +86,7 @@ Rails.application.configure do # Raise error when a before_action's only/except options reference missing actions config.action_controller.raise_on_missing_callback_actions = true - hosts = ENV.fetch('APPLICATION_HOSTS', 'localhost').split(',') + hosts = ENV.fetch('APPLICATION_HOSTS', 'localhost').split(',').map(&:strip) config.action_mailer.default_url_options = { host: ENV['DOMAIN'] || hosts.first, port: ENV.fetch('PORT', 3000) } @@ -99,5 +99,5 @@ Rails.application.configure do config.lograge.enabled = true config.lograge.formatter = Lograge::Formatters::Json.new - config.active_storage.service = ENV['SELF_HOSTED'] == 'true' ? :local : :s3 + config.active_storage.service = ENV.fetch('STORAGE_BACKEND', :local) end diff --git a/config/environments/production.rb b/config/environments/production.rb index 1e4b392a..146ec651 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -43,7 +43,7 @@ Rails.application.configure do # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX # Store uploaded files on the local file system (see config/storage.yml for options). - config.active_storage.service = ENV['SELF_HOSTED'] == 'true' ? :local : :s3 + config.active_storage.service = ENV.fetch('STORAGE_BACKEND', :local) config.silence_healthcheck_path = '/api/v1/health' @@ -101,7 +101,7 @@ Rails.application.configure do # ] # Skip DNS rebinding protection for the health check endpoint. config.host_authorization = { exclude: ->(request) { request.path == "/api/v1/health" } } - hosts = ENV.fetch('APPLICATION_HOSTS', 'localhost').split(',') + hosts = ENV.fetch('APPLICATION_HOSTS', 'localhost').split(',').map(&:strip) config.action_mailer.default_url_options = { host: ENV['DOMAIN'] } config.hosts.concat(hosts) if hosts.present? diff --git a/config/environments/staging.rb b/config/environments/staging.rb index ded741dc..cd248041 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -101,7 +101,7 @@ Rails.application.configure do # ] # Skip DNS rebinding protection for the health check endpoint. config.host_authorization = { exclude: ->(request) { request.path == '/api/v1/health' } } - hosts = ENV.fetch('APPLICATION_HOSTS', 'localhost').split(',') + hosts = ENV.fetch('APPLICATION_HOSTS', 'localhost').split(',').map(&:strip) config.action_mailer.default_url_options = { host: ENV['DOMAIN'] } config.hosts.concat(hosts) if hosts.present? diff --git a/config/storage.yml b/config/storage.yml index 0d9a1fec..78b402ab 100644 --- a/config/storage.yml +++ b/config/storage.yml @@ -7,13 +7,14 @@ local: root: <%= Rails.root.join("storage") %> # Only load S3 config if not in test environment -<% if !Rails.env.test? && ENV['AWS_ACCESS_KEY_ID'] && ENV['AWS_SECRET_ACCESS_KEY'] && ENV['AWS_REGION'] && ENV['AWS_BUCKET'] %> +<% if !Rails.env.test? && ENV['AWS_ACCESS_KEY_ID'] && ENV['AWS_SECRET_ACCESS_KEY'] && ENV['AWS_REGION'] && ENV['AWS_BUCKET'] && ENV['AWS_ENDPOINT_URL'] %> s3: service: S3 access_key_id: <%= ENV.fetch("AWS_ACCESS_KEY_ID") %> secret_access_key: <%= ENV.fetch("AWS_SECRET_ACCESS_KEY") %> region: <%= ENV.fetch("AWS_REGION") %> bucket: <%= ENV.fetch("AWS_BUCKET") %> + endpoint: <%= ENV.fetch("AWS_ENDPOINT_URL") %> <% end %> # Remember not to checkin your GCS keyfile to a repository diff --git a/docker/.env.example b/docker/.env.example index cfd1c6be..5c3dd46d 100644 --- a/docker/.env.example +++ b/docker/.env.example @@ -16,10 +16,7 @@ RAILS_ENV=development POSTGRES_USER=postgres POSTGRES_PASSWORD=password -# Database name - will default to dawarich_${RAILS_ENV} -# For development: dawarich_development -# For staging: dawarich_staging -# For production: dawarich_production +# Database name POSTGRES_DB=dawarich_development # Database connection settings (used by Rails app) @@ -63,6 +60,9 @@ SELF_HOSTED=true # Store geodata (reverse geocoding results) STORE_GEODATA=true +# Storage backend (local or s3) +STORAGE_BACKEND=local + # ============================================================================= # SECURITY # =============================================================================