Skip to content

Commit

Permalink
flyio - set up fly.io with app.sway.vote including dns in cloudflare,…
Browse files Browse the repository at this point in the history
… rake task for backing up db + downloading new seed data - ex. locales
  • Loading branch information
dcordz committed Jun 7, 2024
1 parent 749cc0f commit e0cae71
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ class Application < Rails::Application
config.time_zone = 'UTC'
# config.eager_load_paths << Rails.root.join("extras")

config.force_ssl = true
config.force_ssl = false
end
end
7 changes: 5 additions & 2 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
# config.assume_ssl = true

# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = true
config.force_ssl = false

# Log to STDOUT by default
config.logger = ActiveSupport::Logger.new(STDOUT)
Expand Down Expand Up @@ -98,7 +98,10 @@
# https://guides.rubyonrails.org/security.html#dns-rebinding-and-host-header-attacks
config.hosts = [
# "example.com", # Allow requests from example.com
/.*\.sway\.vote/ # Allow requests from subdomains like `www.example.com`
/.*\.sway\.vote/, # Allow requests from subdomains like `www.example.com`
/.*\.fly\.dev/, # Allow requests from subdomains like `www.example.com`
'localhost',
'127.0.0.1'
]
# Skip DNS rebinding protection for the default health check endpoint.
config.host_authorization = { exclude: ->(request) { request.path == "/up" } }
Expand Down
4 changes: 3 additions & 1 deletion fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ console_command = '/rails/bin/rails console'
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
min_machines_running = 1
max_machines_running = 3

[http_service.concurrency]
type = "requests"
Expand Down Expand Up @@ -51,6 +52,7 @@ console_command = '/rails/bin/rails console'
X-Forwarded-Proto = 'https'

[[vm]]
#memory = '256mb'
memory = '1gb'
cpu_kind = 'shared'
cpus = 1
7 changes: 7 additions & 0 deletions lib/sway_google_cloud_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ def generate_put_signed_url_v4(bucket_name:, file_name:, content_type:)
)
end

def upload_file(bucket_name:, bucket_file_path:, local_file_path:)
return unless bucket_name && bucket_file_path && local_file_path

bucket = storage.bucket bucket_name, skip_lookup: true
bucket.create_file local_file_path, bucket_file_path
end

def download_file(bucket_name:, bucket_file_path:, local_file_path:)
return unless bucket_name && bucket_file_path && local_file_path

Expand Down
5 changes: 4 additions & 1 deletion lib/tasks/sway.rake
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ namespace :sway do
download_directory(bucket_name: 'sway-sqlite', bucket_directory_name: 'geojson', local_directory_name: 'storage')

if File.exist? 'storage/production.sqlite3'
puts 'Skip getting db from bucket.'
puts 'Uploading production.db to google storage as backup.'
upload_file(bucket_name: 'sway-sqlite', bucket_file_path: 'production.sqlite3',
local_file_path: 'storage/production.sqlite3')
else
puts 'Getting production.db from google storage backup.'
download_file(bucket_name: 'sway-sqlite', bucket_file_path: 'production.sqlite3',
local_file_path: 'storage/production.sqlite3')
end
Expand Down

0 comments on commit e0cae71

Please sign in to comment.