Allow S3 storage backend to be used in self-hosted instances

This commit is contained in:
Eugene Burmakin 2025-11-07 23:50:18 +01:00
parent 98a157bd0b
commit c05402b6f3
6 changed files with 12 additions and 10 deletions

View file

@ -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.

View file

@ -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

View file

@ -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?

View file

@ -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?

View file

@ -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

View file

@ -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
# =============================================================================