mirror of
https://github.com/Evolix/chexpire.git
synced 2024-04-25 21:40:49 +02:00
Configure Capistrano
This commit is contained in:
parent
d9dfb0ee0f
commit
2ba184b442
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -31,3 +31,5 @@
|
|||
/node_modules
|
||||
yarn-debug.log*
|
||||
.yarn-integrity
|
||||
|
||||
/config/deploy/config.yml
|
||||
|
|
|
@ -13,6 +13,7 @@ AllCops:
|
|||
- 'app/admin/*'
|
||||
- 'tmp/*'
|
||||
- Gemfile
|
||||
- Capfile
|
||||
|
||||
Documentation:
|
||||
Enabled: false
|
||||
|
|
44
Capfile
Normal file
44
Capfile
Normal file
|
@ -0,0 +1,44 @@
|
|||
# Load DSL and set up stages
|
||||
require "capistrano/setup"
|
||||
|
||||
# Include default deployment tasks
|
||||
require "capistrano/deploy"
|
||||
|
||||
# Load the SCM plugin appropriate to your project:
|
||||
#
|
||||
# require "capistrano/scm/hg"
|
||||
# install_plugin Capistrano::SCM::Hg
|
||||
# or
|
||||
# require "capistrano/scm/svn"
|
||||
# install_plugin Capistrano::SCM::Svn
|
||||
# or
|
||||
require "capistrano/scm/git"
|
||||
install_plugin Capistrano::SCM::Git
|
||||
|
||||
# Include tasks from other gems included in your Gemfile
|
||||
#
|
||||
# For documentation on these, see for example:
|
||||
#
|
||||
# https://github.com/capistrano/rvm
|
||||
# https://github.com/capistrano/rbenv
|
||||
# https://github.com/capistrano/chruby
|
||||
# https://github.com/capistrano/bundler
|
||||
# https://github.com/capistrano/rails
|
||||
# https://github.com/capistrano/passenger
|
||||
#
|
||||
# require "capistrano/rvm"
|
||||
require "capistrano/rbenv"
|
||||
# require "capistrano/chruby"
|
||||
require "capistrano/bundler"
|
||||
# require "capistrano/rails/assets"
|
||||
require "capistrano/rails/migrations"
|
||||
# require "capistrano/passenger"
|
||||
require "capistrano/puma"
|
||||
install_plugin Capistrano::Puma # Default puma tasks
|
||||
# install_plugin Capistrano::Puma::Workers # if you want to control the workers (in cluster mode)
|
||||
# install_plugin Capistrano::Puma::Jungle # if you need the jungle tasks
|
||||
# install_plugin Capistrano::Puma::Monit # if you need the monit tasks
|
||||
# install_plugin Capistrano::Puma::Nginx # if you want to upload a nginx site template
|
||||
|
||||
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
|
||||
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
|
3
Gemfile
3
Gemfile
|
@ -48,6 +48,9 @@ group :development do
|
|||
|
||||
gem 'capistrano-rails'
|
||||
gem 'rubocop', '~> 0.56.0', require: false
|
||||
gem "capistrano", "~> 3.10", require: false
|
||||
gem "capistrano-rbenv", require: false
|
||||
gem 'capistrano3-puma', require: false
|
||||
end
|
||||
|
||||
group :test do
|
||||
|
|
10
Gemfile.lock
10
Gemfile.lock
|
@ -67,6 +67,13 @@ GEM
|
|||
capistrano-rails (1.3.1)
|
||||
capistrano (~> 3.1)
|
||||
capistrano-bundler (~> 1.1)
|
||||
capistrano-rbenv (2.1.3)
|
||||
capistrano (~> 3.1)
|
||||
sshkit (~> 1.3)
|
||||
capistrano3-puma (3.1.1)
|
||||
capistrano (~> 3.7)
|
||||
capistrano-bundler
|
||||
puma (~> 3.4)
|
||||
capybara (3.1.0)
|
||||
addressable
|
||||
mini_mime (>= 0.1.3)
|
||||
|
@ -232,7 +239,10 @@ DEPENDENCIES
|
|||
bcrypt (~> 3.1.7)
|
||||
bootsnap (>= 1.1.0)
|
||||
byebug
|
||||
capistrano (~> 3.10)
|
||||
capistrano-rails
|
||||
capistrano-rbenv
|
||||
capistrano3-puma
|
||||
capybara (>= 2.15, < 4.0)
|
||||
chromedriver-helper
|
||||
jbuilder (~> 2.5)
|
||||
|
|
|
@ -5,6 +5,10 @@ production:
|
|||
<<: *default
|
||||
host: "example.org"
|
||||
|
||||
staging:
|
||||
<<: *default
|
||||
host: "staging.example.org"
|
||||
|
||||
development:
|
||||
<<: *default
|
||||
host: "chexpire.local"
|
||||
|
|
|
@ -29,6 +29,13 @@ test:
|
|||
database: chexpire_test
|
||||
url: <%= ENV['DATABASE_URL'] %>
|
||||
|
||||
|
||||
staging:
|
||||
<<: *default
|
||||
database: chexpire_staging
|
||||
username: chexpire
|
||||
password: <%= ENV['CHEXPIRE_DATABASE_PASSWORD'] %>
|
||||
|
||||
# As with config/secrets.yml, you never want to store sensitive information,
|
||||
# like your database password, in your source code. If your source code is
|
||||
# ever seen by anyone, they now have access to your database.
|
||||
|
|
45
config/deploy.rb
Normal file
45
config/deploy.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
# config valid for current version and patch releases of Capistrano
|
||||
lock "~> 3.10.2"
|
||||
|
||||
set :application, "chexpire"
|
||||
set :repo_url, "https://github.com/Evolix/chexpire.git"
|
||||
|
||||
# Default branch is :master
|
||||
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
|
||||
|
||||
# Default deploy_to directory is /var/www/my_app_name
|
||||
# configured by environment
|
||||
# set :deploy_to, "/var/www/my_app_name"
|
||||
|
||||
set :rbenv_ruby, File.read('.ruby-version').strip
|
||||
|
||||
# Default value for :format is :airbrussh.
|
||||
# set :format, :airbrussh
|
||||
|
||||
# You can configure the Airbrussh format using :format_options.
|
||||
# These are the defaults.
|
||||
# set :format_options, command_output: true, log_file: "log/capistrano.log", color: :auto, truncate: :auto
|
||||
|
||||
# Default value for :pty is false
|
||||
# set :pty, true
|
||||
|
||||
# Default value for :linked_files is []
|
||||
append :linked_files,
|
||||
"config/chexpire.yml",
|
||||
"config/database.yml",
|
||||
"config/secrets.yml"
|
||||
|
||||
# Default value for linked_dirs is []
|
||||
# append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/system"
|
||||
|
||||
# Default value for default_env is {}
|
||||
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
|
||||
|
||||
# Default value for local_user is ENV['USER']
|
||||
# set :local_user, -> { `git config user.name`.chomp }
|
||||
|
||||
# Default value for keep_releases is 5
|
||||
# set :keep_releases, 5
|
||||
|
||||
# Uncomment the following to require manually verifying the host key before first deploy.
|
||||
# set :ssh_options, verify_host_key: :secure
|
21
config/deploy/config.example.yml
Normal file
21
config/deploy/config.example.yml
Normal file
|
@ -0,0 +1,21 @@
|
|||
staging:
|
||||
deploy_to: /var/www/my_app_name
|
||||
servers:
|
||||
-
|
||||
host: staging.example.com
|
||||
user: deploy
|
||||
roles:
|
||||
- app
|
||||
- db
|
||||
- web
|
||||
|
||||
production:
|
||||
deploy_to: /var/www/my_app_name
|
||||
servers:
|
||||
-
|
||||
host: www.example.com
|
||||
user: deploy
|
||||
roles:
|
||||
- app
|
||||
- db
|
||||
- web
|
66
config/deploy/production.rb
Normal file
66
config/deploy/production.rb
Normal file
|
@ -0,0 +1,66 @@
|
|||
# server-based syntax
|
||||
# ======================
|
||||
# Defines a single server with a list of roles and multiple properties.
|
||||
# You can define all roles on a single server, or split them:
|
||||
|
||||
config = YAML::load_file(File.join(__dir__, 'config.yml')).fetch("production")
|
||||
|
||||
config.fetch("servers").each do |sc|
|
||||
server sc.fetch("host"), user: sc.fetch("user"), roles: sc.fetch("roles")
|
||||
# server "example.com", user: "deploy", roles: %w{app web}, other_property: :other_value
|
||||
# server "db.example.com", user: "deploy", roles: %w{db}
|
||||
end
|
||||
|
||||
# Default deploy_to directory is /var/www/my_app_name
|
||||
set :deploy_to, config.fetch("deploy_to")
|
||||
|
||||
# role-based syntax
|
||||
# ==================
|
||||
|
||||
# Defines a role with one or multiple servers. The primary server in each
|
||||
# group is considered to be the first unless any hosts have the primary
|
||||
# property set. Specify the username and a domain or IP for the server.
|
||||
# Don't use `:all`, it's a meta role.
|
||||
|
||||
# role :app, %w{deploy@example.com}, my_property: :my_value
|
||||
# role :web, %w{user1@primary.com user2@additional.com}, other_property: :other_value
|
||||
# role :db, %w{deploy@example.com}
|
||||
|
||||
|
||||
|
||||
# Configuration
|
||||
# =============
|
||||
# You can set any configuration variable like in config/deploy.rb
|
||||
# These variables are then only loaded and set in this stage.
|
||||
# For available Capistrano configuration variables see the documentation page.
|
||||
# http://capistranorb.com/documentation/getting-started/configuration/
|
||||
# Feel free to add new variables to customise your setup.
|
||||
|
||||
|
||||
|
||||
# Custom SSH Options
|
||||
# ==================
|
||||
# You may pass any option but keep in mind that net/ssh understands a
|
||||
# limited set of options, consult the Net::SSH documentation.
|
||||
# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
|
||||
#
|
||||
# Global options
|
||||
# --------------
|
||||
# set :ssh_options, {
|
||||
# keys: %w(/home/rlisowski/.ssh/id_rsa),
|
||||
# forward_agent: false,
|
||||
# auth_methods: %w(password)
|
||||
# }
|
||||
#
|
||||
# The server-based syntax can be used to override options:
|
||||
# ------------------------------------
|
||||
# server "example.com",
|
||||
# user: "user_name",
|
||||
# roles: %w{web app},
|
||||
# ssh_options: {
|
||||
# user: "user_name", # overrides user setting above
|
||||
# keys: %w(/home/user_name/.ssh/id_rsa),
|
||||
# forward_agent: false,
|
||||
# auth_methods: %w(publickey password)
|
||||
# # password: "please use keys"
|
||||
# }
|
68
config/deploy/staging.rb
Normal file
68
config/deploy/staging.rb
Normal file
|
@ -0,0 +1,68 @@
|
|||
require 'yaml'
|
||||
# server-based syntax
|
||||
# ======================
|
||||
# Defines a single server with a list of roles and multiple properties.
|
||||
# You can define all roles on a single server, or split them:
|
||||
|
||||
config = YAML::load_file(File.join(__dir__, 'config.yml')).fetch("staging")
|
||||
|
||||
config.fetch("servers").each do |sc|
|
||||
server sc.fetch("host"), user: sc.fetch("user"), roles: sc.fetch("roles")
|
||||
# server "example.com", user: "deploy", roles: %w{app web}, other_property: :other_value
|
||||
# server "db.example.com", user: "deploy", roles: %w{db}
|
||||
end
|
||||
|
||||
# Default deploy_to directory is /var/www/my_app_name
|
||||
set :deploy_to, config.fetch("deploy_to")
|
||||
set :branch, "staging"
|
||||
|
||||
# role-based syntax
|
||||
# ==================
|
||||
|
||||
# Defines a role with one or multiple servers. The primary server in each
|
||||
# group is considered to be the first unless any hosts have the primary
|
||||
# property set. Specify the username and a domain or IP for the server.
|
||||
# Don't use `:all`, it's a meta role.
|
||||
|
||||
# role :app, %w{deploy@example.com}, my_property: :my_value
|
||||
# role :web, %w{user1@primary.com user2@additional.com}, other_property: :other_value
|
||||
# role :db, %w{deploy@example.com}
|
||||
|
||||
|
||||
|
||||
# Configuration
|
||||
# =============
|
||||
# You can set any configuration variable like in config/deploy.rb
|
||||
# These variables are then only loaded and set in this stage.
|
||||
# For available Capistrano configuration variables see the documentation page.
|
||||
# http://capistranorb.com/documentation/getting-started/configuration/
|
||||
# Feel free to add new variables to customise your setup.
|
||||
|
||||
|
||||
|
||||
# Custom SSH Options
|
||||
# ==================
|
||||
# You may pass any option but keep in mind that net/ssh understands a
|
||||
# limited set of options, consult the Net::SSH documentation.
|
||||
# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
|
||||
#
|
||||
# Global options
|
||||
# --------------
|
||||
# set :ssh_options, {
|
||||
# keys: %w(/home/rlisowski/.ssh/id_rsa),
|
||||
# forward_agent: false,
|
||||
# auth_methods: %w(password)
|
||||
# }
|
||||
#
|
||||
# The server-based syntax can be used to override options:
|
||||
# ------------------------------------
|
||||
# server "example.com",
|
||||
# user: "user_name",
|
||||
# roles: %w{web app},
|
||||
# ssh_options: {
|
||||
# user: "user_name", # overrides user setting above
|
||||
# keys: %w(/home/user_name/.ssh/id_rsa),
|
||||
# forward_agent: false,
|
||||
# auth_methods: %w(publickey password)
|
||||
# # password: "please use keys"
|
||||
# }
|
93
config/environments/staging.rb
Normal file
93
config/environments/staging.rb
Normal file
|
@ -0,0 +1,93 @@
|
|||
Rails.application.configure do
|
||||
# Verifies that versions and hashed value of the package contents in the project's package.json
|
||||
config.webpacker.check_yarn_integrity = false
|
||||
# Settings specified here will take precedence over those in config/application.rb.
|
||||
|
||||
# Code is not reloaded between requests.
|
||||
config.cache_classes = true
|
||||
|
||||
# Eager load code on boot. This eager loads most of Rails and
|
||||
# your application in memory, allowing both threaded web servers
|
||||
# and those relying on copy on write to perform better.
|
||||
# Rake tasks automatically ignore this option for performance.
|
||||
config.eager_load = true
|
||||
|
||||
# Full error reports are disabled and caching is turned on.
|
||||
config.consider_all_requests_local = false
|
||||
config.action_controller.perform_caching = true
|
||||
|
||||
# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
|
||||
# or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
|
||||
config.require_master_key = false
|
||||
|
||||
# Disable serving static files from the `/public` folder by default since
|
||||
# Apache or NGINX already handles this.
|
||||
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
|
||||
|
||||
# Compress JavaScripts and CSS.
|
||||
config.assets.js_compressor = :uglifier
|
||||
# config.assets.css_compressor = :sass
|
||||
|
||||
# Do not fallback to assets pipeline if a precompiled asset is missed.
|
||||
config.assets.compile = false
|
||||
|
||||
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
|
||||
|
||||
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
|
||||
# config.action_controller.asset_host = 'http://assets.example.com'
|
||||
|
||||
# Specifies the header that your server uses for sending files.
|
||||
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
|
||||
# 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 = :local
|
||||
|
||||
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
||||
config.force_ssl = true
|
||||
|
||||
# Use the lowest log level to ensure availability of diagnostic information
|
||||
# when problems arise.
|
||||
config.log_level = :debug
|
||||
|
||||
# Prepend all log lines with the following tags.
|
||||
config.log_tags = [ :request_id ]
|
||||
|
||||
# Use a different cache store in production.
|
||||
# config.cache_store = :mem_cache_store
|
||||
|
||||
# Use a real queuing backend for Active Job (and separate queues per environment)
|
||||
# config.active_job.queue_adapter = :resque
|
||||
# config.active_job.queue_name_prefix = "chexpire_#{Rails.env}"
|
||||
|
||||
config.action_mailer.perform_caching = false
|
||||
|
||||
# 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.
|
||||
# config.action_mailer.raise_delivery_errors = false
|
||||
|
||||
config.action_mailer.default_url_options = { host: config.chexpire.fetch("host") }
|
||||
|
||||
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
||||
# the I18n.default_locale when a translation cannot be found).
|
||||
config.i18n.fallbacks = true
|
||||
|
||||
# Send deprecation notices to registered listeners.
|
||||
config.active_support.deprecation = :notify
|
||||
|
||||
# Use default logging formatter so that PID and timestamp are not suppressed.
|
||||
config.log_formatter = ::Logger::Formatter.new
|
||||
|
||||
# Use a different logger for distributed setups.
|
||||
# require 'syslog/logger'
|
||||
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
|
||||
|
||||
if ENV["RAILS_LOG_TO_STDOUT"].present?
|
||||
logger = ActiveSupport::Logger.new(STDOUT)
|
||||
logger.formatter = config.log_formatter
|
||||
config.logger = ActiveSupport::TaggedLogging.new(logger)
|
||||
end
|
||||
|
||||
# Do not dump schema after migrations.
|
||||
config.active_record.dump_schema_after_migration = false
|
||||
end
|
|
@ -66,3 +66,12 @@ production:
|
|||
|
||||
# Cache manifest.json for performance
|
||||
cache_manifest: true
|
||||
|
||||
staging:
|
||||
<<: *default
|
||||
|
||||
# Production depends on precompilation of packs prior to booting for performance.
|
||||
compile: false
|
||||
|
||||
# Cache manifest.json for performance
|
||||
cache_manifest: true
|
||||
|
|
36
script/to_production
Executable file
36
script/to_production
Executable file
|
@ -0,0 +1,36 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
[ -n "$DEBUG" ] && set -x
|
||||
|
||||
# git name-rev is fail
|
||||
CURRENT=`git rev-parse --abbrev-ref HEAD`
|
||||
TIMESTAMP=`date +"%s"`
|
||||
|
||||
echo "👀 Fetching git repository information…"
|
||||
git fetch origin --quiet
|
||||
|
||||
CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`
|
||||
CURRENT_HEAD=`git rev-parse HEAD`
|
||||
ORIGIN_HEAD=`git rev-parse origin/master`
|
||||
|
||||
if [ "master" != "${CURRENT_BRANCH}" ]; then
|
||||
echo "😕 Only master can be deployed to production"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ${CURRENT_HEAD} != ${ORIGIN_HEAD} ]; then
|
||||
echo "😕 Local master is not up to date with origin"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
read -p "👉 Deploy master to production ? (y/N) " confirmed
|
||||
|
||||
if [ "${confirmed}" != "y" ]; then
|
||||
echo "😞 Abort, bye."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
bundle exec cap production deploy
|
||||
|
||||
echo "😎 Done !"
|
9
script/to_staging
Executable file
9
script/to_staging
Executable file
|
@ -0,0 +1,9 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
[ -n "$DEBUG" ] && set -x
|
||||
|
||||
git branch -f staging
|
||||
git push --force origin staging
|
||||
|
||||
bundle exec cap staging deploy
|
Loading…
Reference in a new issue