Skip to content

Commit

Permalink
Setup production configuration (#26)
Browse files Browse the repository at this point in the history
* Fix build of package

* Allow configuration in production

* Configure sentry for error tracking

* fixup config application

* Provide a nixos module to run the app

* Make sure that build does not need ENV variables
  • Loading branch information
robbevp authored Oct 14, 2023
1 parent 40aff70 commit 4e720ec
Show file tree
Hide file tree
Showing 13 changed files with 599 additions and 198 deletions.
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ updates:
groups:
rubocop:
patterns:
- "rubocop"
- "rubocop-*"
sentry:
patterns:
- "sentry-*"
vite:
patterns:
- "vite*"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
with:
nix_path: nixpkgs=channel:nixos-23.05
- name: Lint with nixpkgs-fmt
run: nix-shell -p nixpkgs-fmt --run "nixpkgs-fmt --check flake.nix"
run: nix-shell -p nixpkgs-fmt --run "nixpkgs-fmt --check flake.nix module.nix"
precompile:
runs-on: ubuntu-latest
env:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@ node_modules
# Vite uses dotenv and suggests to ignore local-only env files. See
# https://vitejs.dev/guide/env-and-mode.html#env-files
*.local

6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ gem 'turbo-rails' # Use Turbo for progressive enhancement of requests
gem 'view_component' # Use ViewComponent to replace partials
gem 'vite_rails' # Use ViteRails to compile assets

group :production do
# Report issues in production
gem 'sentry-rails'
gem 'sentry-ruby'
end

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem 'debug', platforms: %i[mri mingw x64_mingw]
Expand Down
7 changes: 7 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ GEM
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
sentry-rails (5.10.0)
railties (>= 5.0)
sentry-ruby (~> 5.10.0)
sentry-ruby (5.10.0)
concurrent-ruby (~> 1.0, >= 1.0.2)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
Expand Down Expand Up @@ -344,6 +349,8 @@ DEPENDENCIES
rubocop-performance
rubocop-rails
selenium-webdriver
sentry-rails
sentry-ruby
simplecov
simplecov-cobertura
turbo-rails
Expand Down
29 changes: 29 additions & 0 deletions bin/vite
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'vite' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

bundle_binstub = File.expand_path("../bundle", __FILE__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("vite_ruby", "vite")
14 changes: 13 additions & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
# config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ]

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

# Include generic and useful information about system operation, but avoid logging too much
# information to avoid inadvertent exposure of personally identifiable information (PII).
Expand All @@ -65,6 +65,18 @@
# config.active_job.queue_name_prefix = "feed_reader_production"

config.action_mailer.perform_caching = false
config.action_mailer.default_options = { from: ENV.fetch('RAILS_MAILER_DEFAULT_FROM') }
config.action_mailer.default_url_options = { host: ENV.fetch('HOSTNAME', nil), port: false, protocol: 'https' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: ENV.fetch('RAILS_SMTP_ADDRESS'),
port: 587,
domain: ENV.fetch('RAILS_SMTP_DOMAIN'),
user_name: ENV.fetch('RAILS_SMTP_USER_NAME'),
password: ENV.fetch('RAILS_SMTP_PASSWORD'),
authentication: 'login',
enable_starttls_auto: true
}

# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
Expand Down
12 changes: 12 additions & 0 deletions config/initializers/sentry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

dsn = ENV.fetch('SENTRY_DSN', nil)

if dsn.present?
Sentry.init do |config|
config.dsn = dsn
config.breadcrumbs_logger = %i[active_support_logger http_logger]
# Disable performance monitoring
config.traces_sample_rate = 0
end
end
2 changes: 1 addition & 1 deletion config/storage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test:

local:
service: Disk
root: <%= Rails.root.join("storage") %>
root: <%= ENV['RAILS_STORAGE_PATH'] || Rails.root.join("storage") %>

# Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
# amazon:
Expand Down
Loading

0 comments on commit 4e720ec

Please sign in to comment.