Browse Source

production step1

main
pvincent 4 months ago
parent
commit
bc25880c0d
  1. 16
      app/extra/toto.rb
  2. 38
      bin/prod
  3. 10
      config/application.rb
  4. 7
      config/database.yml
  5. 19
      config/environments/development.rb
  6. 15
      config/environments/production.rb

16
app/extra/toto.rb

@ -1,16 +0,0 @@
module Extra
# Toto est fluo
class Toto
def ok; end
# this is a barman
def bar(ahaha, bzazaza, crezre)
puts "#{ahaha}#{bzazaza}#{crezre}"
end
def candel
bar('a', 'aezeaz')
Toto
end
end
end

38
bin/prod

@ -0,0 +1,38 @@
#!/usr/bin/bash
set -Eeuo pipefail
SECRET_KEY_BASE=TOTO_EST_FLUO
## FUNCTIONS
function check_sudo_user {
if [[ $(id -u) -eq 0 ]] || groups | grep -q sudo; then
sudo --validate --prompt='sudo privilege required for further processing: '
else
>&2 echo 'current user not in the `sudo` group, aborted!'
exit 10
fi
}
function fetch_latest_version {
sudo rm -rf /opt/egr
sudo cp -r /home/pvincent/easy-going-rails /opt/egr
sudo rm -rf /opt/egr/tmp/*
sudo chown -R pvincent:pvincent /opt/egr
}
function bundle_and_populate {
cd /opt/egr
bundle install
DATABASE_HOST=ct1.lxd RAILS_ENV=production SECRET_KEY_BASE=$SECRET_KEY_BASE rails db:migrate
DATABASE_HOST=ct1.lxd RAILS_ENV=production SECRET_KEY_BASE=$SECRET_KEY_BASE rails assets:precompile
}
function systemd_restart {
DATABASE_HOST=ct1.lxd RAILS_ENV=production SECRET_KEY_BASE=$SECRET_KEY_BASE rails server --port 7000
}
## MAIN
check_sudo_user
fetch_latest_version
bundle_and_populate
systemd_restart

10
config/application.rb

@ -15,7 +15,7 @@ module EasyGoingRails
# Please, add to the `ignore` list any other `lib` subdirectories that do
# not contain `.rb` files, or that should not be reloaded or eager loaded.
# Common ones are `templates`, `generators`, or `middleware`, for example.
config.autoload_lib(ignore: %w[assets tasks])
config.autoload_lib(ignore: %w[assets tasks formatters hot_constants monkey_patches])
# main application title defined from current module name, see module above
config.application_title = module_parent.to_s.titleize
@ -27,6 +27,12 @@ module EasyGoingRails
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")
#
# Customized Semantic Logger
config.rails_semantic_logger.semantic = false
config.rails_semantic_logger.started = true
config.rails_semantic_logger.processing = true
config.rails_semantic_logger.rendered = true
config.rails_semantic_logger.add_file_appender = false
end
end

7
config/database.yml

@ -1,5 +1,4 @@
---
default: &default
host: <%= ENV.fetch("DATABASE_HOST") { 'localhost' } %>
database: &db_name <%= ENV.fetch("DATABASE_NAME") { 'easy-going-rails' } %>
@ -12,6 +11,12 @@ default: &default
development:
<<: *default
production:
<<: *default
database: &db_prod easy-going-rails_prod
user: *db_prod
password: *db_prod
test:
<<: *default
database: easy-going-rails_test

19
config/environments/development.rb

@ -74,19 +74,6 @@ Rails.application.configure do # rubocop:disable Metrics/BlockLength
# Raise error when a before_action's only/except options reference missing actions
config.action_controller.raise_on_missing_callback_actions = true
# Customized Semantic Logger
config.rails_semantic_logger.semantic = false
config.rails_semantic_logger.started = true
config.rails_semantic_logger.processing = true
config.rails_semantic_logger.rendered = true
config.rails_semantic_logger.add_file_appender = false
require Rails.root.join('lib', 'formatters', 'ansi_formatter')
formatter = AnsiFormatter.new
config.semantic_logger.add_appender(io: $stdout,
formatter:,
filter: ->(log) { !formatter.reject(log) })
routes.default_url_options[:port] = ARGV[1] # ie: Procfile.dev --port PORT
routes.default_url_options[:host] = '127.0.0.1'
@ -94,4 +81,10 @@ Rails.application.configure do # rubocop:disable Metrics/BlockLength
require Rails.root.join('lib', 'hot_constants', 'live_constants')
LiveConstants.reload!
end
require Rails.root.join('lib', 'formatters', 'ansi_formatter')
formatter = AnsiFormatter.new
config.semantic_logger.add_appender(io: $stdout,
formatter:,
filter: ->(log) { !formatter.reject(log) })
end

15
config/environments/production.rb

@ -1,4 +1,4 @@
require "active_support/core_ext/integer/time"
require 'active_support/core_ext/integer/time'
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
@ -49,20 +49,19 @@ Rails.application.configure do
# 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)
.tap { |logger| logger.formatter = ::Logger::Formatter.new }
.then { |logger| ActiveSupport::TaggedLogging.new(logger) }
# Semantic Logger in syslog only!
require Rails.root.join('lib', 'formatters', 'basic_formatter')
config.semantic_logger.add_appender(appender: :syslog, formatter: BasicFormatter.new)
# Prepend all log lines with the following tags.
config.log_tags = [ :request_id ]
# config.log_tags = [:request_id]
# Info include generic and useful information about system operation, but avoids logging too much
# information to avoid inadvertent exposure of personally identifiable information (PII). If you
# want to log everything, set the level to "debug".
config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info")
config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info')
# Use a different cache store in production.
# config.cache_store = :mem_cache_store

Loading…
Cancel
Save