Skip to content

Commit

Permalink
Configure Cloud66 for deployment (#3309)
Browse files Browse the repository at this point in the history
* Add back in 'My Profile' nav item for partners to set their name (#3231)

* Force node to stay at version 16 to deploy properly

* Add all cloud66 migration changes needed

* Remove unneccesary work around for turbo-rails since we are not releasing it yet

* Attempt fixing database connection on local db on staging
  • Loading branch information
edwinthinks authored Jan 8, 2023
1 parent 58814c5 commit 88c2bf2
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 40 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ gem 'httparty'
gem 'icalendar', require: false
# JSON Web Token encoding / decoding (e.g. for links in e-mails)
gem "jwt"
# Used to manage periodic cron-like jobs
gem "clockwork"

##### DEPENDENCY PINS ######
# These are gems that aren't used directly, only as dependencies for other gems.
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ GEM
launchy
childprocess (4.1.0)
choice (0.2.0)
clockwork (3.0.0)
activesupport
tzinfo
cocoon (1.2.15)
coderay (1.1.3)
concurrent-ruby (1.1.10)
Expand Down Expand Up @@ -634,6 +637,7 @@ DEPENDENCIES
bullet
capybara (~> 3.38)
capybara-screenshot
clockwork
cocoon
coverband
database_cleaner (= 1.8.5)
Expand Down
4 changes: 2 additions & 2 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
release: rails db:migrate
web: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}
custom_web: bundle exec puma
worker: bundle exec rails jobs:work
clock: bundle exec clockwork clock.rb
20 changes: 20 additions & 0 deletions clock.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require "rake"
require "clockwork"
require "clockwork/database_events"
require_relative "./config/boot"
require_relative "./config/environment"

module Clockwork
handler do |job|
puts "Running #{job}"
end

every(1.day, "Periodically reset seed data in staging", at: "00:00") do
if ENV["RAILS_ENV"] == "staging"
rake = Rake.application
rake.init
rake.load_rakefile
rake["reset_demo"].invoke
end
end
end
5 changes: 4 additions & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ development:

staging:
<<: *default
url: <%= ENV['DATABASE_URL'] %>
username: <%= ENV['POSTGRESQL_USERNAME'] %>
password: <%= ENV['POSTGRESQL_PASSWORD'] %>
database: <%= ENV['POSTGRESQL_DATABASE'] %>
host: <%= ENV['POSTGRESQL_ADDRESS'] %>

test:
<<: *default
Expand Down
2 changes: 1 addition & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,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 / Disabled since Cloud66 manages SSL and DNS redirects for us.
config.ssl_options = { hsts: false }

config.log_level = :info
Expand Down
2 changes: 1 addition & 1 deletion config/environments/staging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,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 / Disabled since Cloud66 manages SSL and DNS redirects for us.
config.ssl_options = { hsts: false }

config.log_level = :info
Expand Down
50 changes: 21 additions & 29 deletions config/puma.rb
Original file line number Diff line number Diff line change
@@ -1,47 +1,39 @@
# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers a minimum and maximum.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum, this matches the default thread size of Active Record.
# and maximum; this matches the default thread size of Active Record.
#
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
threads threads_count, threads_count

# Specifies the `port` that Puma will listen on to receive requests, default is 3000.
max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
threads min_threads_count, max_threads_count
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port ENV.fetch("PORT") { 3000 }

# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "development" }

# Specifies the `pidfile` that Puma will use.
#
pidfile ENV.fetch("PIDFILE") { "/tmp/web_server.pid" }
# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked webserver processes. If using threads and workers together
# Workers are forked web server processes. If using threads and workers together
# the concurrency of the application would be max `threads` * `workers`.
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }

workers ENV.fetch("WEB_CONCURRENCY") { 2 }
# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
# before forking the application. This takes advantage of Copy On Write
# process behavior so workers use less memory. If you use this option
# you need to make sure to reconnect any threads in the `on_worker_boot`
# block.
#
# preload_app!

# The code in the `on_worker_boot` will be called if you are using
# clustered mode by specifying a number of `workers`. After each worker
# process is booted this block will be run, if you are using `preload_app!`
# option you will want to use this block to reconnect to any threads
# or connections that may have been created at application boot, Ruby
# cannot share connections between processes.
#
# on_worker_boot do
# ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
# end

# process behavior so workers use less memory.
#
preload_app!
# Set the directory to Cloud 66 specific environment variable so that puma can follow symlinks to new code on redeployment
#
directory ENV.fetch("STACK_PATH") { "." }
# Make sure to bind to Cloud 66 specific socket so that NGINX can direct traffic here
#
bind ENV.fetch("BIND") { "unix:///tmp/web_server.sock" }
# Allow puma to be restarted by `rails restart` command.
plugin :tmp_restart
# plugin :tmp_restart
9 changes: 3 additions & 6 deletions lib/tasks/reset_demo.rake
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
desc "This task is called by the Heroku scheduler add-on to reset the demo periodically at everyday"
desc "Resets the database to default demo data"
task :reset_demo => :environment do
puts "Cleaning up the partner database..."
DatabaseCleaner[:active_record, { model: Partners::Base }]
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.clean
raise "Cannot run this in production" if Rails.env.production?

puts "Cleaning up the diaper database..."
puts "Cleaning up the database..."
DatabaseCleaner[:active_record, { model: ApplicationRecord }]
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.clean
Expand Down

0 comments on commit 88c2bf2

Please sign in to comment.