Merge branch 'r-1902001-01' of https://gitlab.com/code2lab/SXRestaurant into r-1902001-01
This commit is contained in:
9
Capfile
9
Capfile
@@ -22,10 +22,15 @@ require "capistrano/bundler"
|
|||||||
require "capistrano/rails"
|
require "capistrano/rails"
|
||||||
require "capistrano/rails/assets"
|
require "capistrano/rails/assets"
|
||||||
require "capistrano/rails/migrations"
|
require "capistrano/rails/migrations"
|
||||||
# require "capistrano/passenger"
|
require "capistrano/scm/git"
|
||||||
|
install_plugin Capistrano::SCM::Git
|
||||||
|
|
||||||
|
require 'capistrano/puma'
|
||||||
|
install_plugin Capistrano::Puma, load_hooks: false # Default puma tasks
|
||||||
|
install_plugin Capistrano::Puma::Monit # if you need the monit tasks
|
||||||
|
install_plugin Capistrano::Puma::Jungle # if you need the jungle tasks
|
||||||
|
|
||||||
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
|
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
|
||||||
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
|
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
|
||||||
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
|
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
|
||||||
Dir.glob('lib/capistrano/**/*.rb').each { |r| import r }
|
Dir.glob('lib/capistrano/**/*.rb').each { |r| import r }
|
||||||
|
|
||||||
|
|||||||
5
Gemfile
5
Gemfile
@@ -1,5 +1,5 @@
|
|||||||
source 'https://rubygems.org'
|
source 'https://rubygems.org'
|
||||||
ruby '2.3.1'
|
|
||||||
git_source(:github) do |repo_name|
|
git_source(:github) do |repo_name|
|
||||||
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
|
||||||
"https://github.com/#{repo_name}.git"
|
"https://github.com/#{repo_name}.git"
|
||||||
@@ -44,7 +44,7 @@ gem 'mini_magick'
|
|||||||
gem 'jquery-fileupload-rails', '~> 0.4.7'
|
gem 'jquery-fileupload-rails', '~> 0.4.7'
|
||||||
|
|
||||||
#Report and Printing gems
|
#Report and Printing gems
|
||||||
gem 'cups'
|
#gem 'cups' #remove for cloud installation
|
||||||
gem 'prawn'
|
gem 'prawn'
|
||||||
gem 'prawn-table'
|
gem 'prawn-table'
|
||||||
gem 'prawn-qrcode'
|
gem 'prawn-qrcode'
|
||||||
@@ -114,6 +114,7 @@ group :development do
|
|||||||
gem 'capistrano-bundler'
|
gem 'capistrano-bundler'
|
||||||
gem 'capistrano-rails'
|
gem 'capistrano-rails'
|
||||||
gem 'capistrano-rbenv', github: "capistrano/rbenv"
|
gem 'capistrano-rbenv', github: "capistrano/rbenv"
|
||||||
|
gem 'capistrano3-puma'
|
||||||
end
|
end
|
||||||
|
|
||||||
group :test do
|
group :test do
|
||||||
|
|||||||
43
Gemfile.lock
43
Gemfile.lock
@@ -62,7 +62,7 @@ GEM
|
|||||||
builder (3.2.3)
|
builder (3.2.3)
|
||||||
byebug (11.0.1)
|
byebug (11.0.1)
|
||||||
cancancan (1.17.0)
|
cancancan (1.17.0)
|
||||||
capistrano (3.10.1)
|
capistrano (3.11.2)
|
||||||
airbrussh (>= 1.0.0)
|
airbrussh (>= 1.0.0)
|
||||||
i18n
|
i18n
|
||||||
rake (>= 10.0.0)
|
rake (>= 10.0.0)
|
||||||
@@ -72,6 +72,10 @@ GEM
|
|||||||
capistrano-rails (1.4.0)
|
capistrano-rails (1.4.0)
|
||||||
capistrano (~> 3.1)
|
capistrano (~> 3.1)
|
||||||
capistrano-bundler (~> 1.1)
|
capistrano-bundler (~> 1.1)
|
||||||
|
capistrano3-puma (3.1.1)
|
||||||
|
capistrano (~> 3.7)
|
||||||
|
capistrano-bundler
|
||||||
|
puma (~> 3.4)
|
||||||
carrierwave (1.3.1)
|
carrierwave (1.3.1)
|
||||||
activemodel (>= 4.0.0)
|
activemodel (>= 4.0.0)
|
||||||
activesupport (>= 4.0.0)
|
activesupport (>= 4.0.0)
|
||||||
@@ -89,7 +93,6 @@ GEM
|
|||||||
concurrent-ruby (1.1.5)
|
concurrent-ruby (1.1.5)
|
||||||
connection_pool (2.2.2)
|
connection_pool (2.2.2)
|
||||||
crass (1.0.5)
|
crass (1.0.5)
|
||||||
cups (0.1.10)
|
|
||||||
database_cleaner (1.7.0)
|
database_cleaner (1.7.0)
|
||||||
diff-lcs (1.3)
|
diff-lcs (1.3)
|
||||||
erubi (1.9.0)
|
erubi (1.9.0)
|
||||||
@@ -99,8 +102,8 @@ GEM
|
|||||||
factory_girl_rails (4.9.0)
|
factory_girl_rails (4.9.0)
|
||||||
factory_girl (~> 4.9.0)
|
factory_girl (~> 4.9.0)
|
||||||
railties (>= 3.0.0)
|
railties (>= 3.0.0)
|
||||||
faker (2.5.0)
|
faker (2.6.0)
|
||||||
i18n (~> 1.6.0)
|
i18n (>= 1.6, < 1.8)
|
||||||
ffi (1.11.1)
|
ffi (1.11.1)
|
||||||
filterrific (5.2.1)
|
filterrific (5.2.1)
|
||||||
font-awesome-rails (4.7.0.5)
|
font-awesome-rails (4.7.0.5)
|
||||||
@@ -140,7 +143,7 @@ GEM
|
|||||||
listen (3.0.8)
|
listen (3.0.8)
|
||||||
rb-fsevent (~> 0.9, >= 0.9.4)
|
rb-fsevent (~> 0.9, >= 0.9.4)
|
||||||
rb-inotify (~> 0.9, >= 0.9.7)
|
rb-inotify (~> 0.9, >= 0.9.7)
|
||||||
loofah (2.3.0)
|
loofah (2.3.1)
|
||||||
crass (~> 1.0.2)
|
crass (~> 1.0.2)
|
||||||
nokogiri (>= 1.5.9)
|
nokogiri (>= 1.5.9)
|
||||||
mail (2.7.1)
|
mail (2.7.1)
|
||||||
@@ -223,23 +226,23 @@ GEM
|
|||||||
chunky_png (~> 1.0)
|
chunky_png (~> 1.0)
|
||||||
rqrcode_core (~> 0.1.0)
|
rqrcode_core (~> 0.1.0)
|
||||||
rqrcode_core (0.1.0)
|
rqrcode_core (0.1.0)
|
||||||
rspec-core (3.8.2)
|
rspec-core (3.9.0)
|
||||||
rspec-support (~> 3.8.0)
|
rspec-support (~> 3.9.0)
|
||||||
rspec-expectations (3.8.5)
|
rspec-expectations (3.9.0)
|
||||||
diff-lcs (>= 1.2.0, < 2.0)
|
diff-lcs (>= 1.2.0, < 2.0)
|
||||||
rspec-support (~> 3.8.0)
|
rspec-support (~> 3.9.0)
|
||||||
rspec-mocks (3.8.2)
|
rspec-mocks (3.9.0)
|
||||||
diff-lcs (>= 1.2.0, < 2.0)
|
diff-lcs (>= 1.2.0, < 2.0)
|
||||||
rspec-support (~> 3.9.0)
|
rspec-support (~> 3.9.0)
|
||||||
rspec-rails (3.9.0)
|
rspec-rails (3.9.0)
|
||||||
actionpack (>= 3.0)
|
actionpack (>= 3.0)
|
||||||
activesupport (>= 3.0)
|
activesupport (>= 3.0)
|
||||||
railties (>= 3.0)
|
railties (>= 3.0)
|
||||||
rspec-core (~> 3.8.0)
|
rspec-core (~> 3.9.0)
|
||||||
rspec-expectations (~> 3.8.0)
|
rspec-expectations (~> 3.9.0)
|
||||||
rspec-mocks (~> 3.8.0)
|
rspec-mocks (~> 3.9.0)
|
||||||
rspec-support (~> 3.8.0)
|
rspec-support (~> 3.9.0)
|
||||||
rspec-support (3.8.3)
|
rspec-support (3.9.0)
|
||||||
ruby-ole (1.2.12.2)
|
ruby-ole (1.2.12.2)
|
||||||
rubyzip (1.0.0)
|
rubyzip (1.0.0)
|
||||||
sass (3.7.4)
|
sass (3.7.4)
|
||||||
@@ -265,10 +268,9 @@ GEM
|
|||||||
simple_form (5.0.1)
|
simple_form (5.0.1)
|
||||||
actionpack (>= 5.0)
|
actionpack (>= 5.0)
|
||||||
activemodel (>= 5.0)
|
activemodel (>= 5.0)
|
||||||
spreadsheet (1.2.4)
|
spreadsheet (1.2.5)
|
||||||
ruby-ole (>= 1.0)
|
ruby-ole (>= 1.0)
|
||||||
spring (2.0.2)
|
spring (2.1.0)
|
||||||
activesupport (>= 4.2)
|
|
||||||
spring-watcher-listen (2.0.1)
|
spring-watcher-listen (2.0.1)
|
||||||
listen (>= 2.7, < 4.0)
|
listen (>= 2.7, < 4.0)
|
||||||
spring (>= 1.2, < 3.0)
|
spring (>= 1.2, < 3.0)
|
||||||
@@ -322,10 +324,10 @@ DEPENDENCIES
|
|||||||
capistrano-bundler
|
capistrano-bundler
|
||||||
capistrano-rails
|
capistrano-rails
|
||||||
capistrano-rbenv!
|
capistrano-rbenv!
|
||||||
|
capistrano3-puma
|
||||||
carrierwave (~> 1.0)
|
carrierwave (~> 1.0)
|
||||||
chartkick
|
chartkick
|
||||||
coffee-rails (~> 4.2)
|
coffee-rails (~> 4.2)
|
||||||
cups
|
|
||||||
database_cleaner
|
database_cleaner
|
||||||
factory_girl_rails (~> 4.0)
|
factory_girl_rails (~> 4.0)
|
||||||
faker
|
faker
|
||||||
@@ -370,8 +372,5 @@ DEPENDENCIES
|
|||||||
web-console (>= 3.3.0)
|
web-console (>= 3.3.0)
|
||||||
whenever
|
whenever
|
||||||
|
|
||||||
RUBY VERSION
|
|
||||||
ruby 2.3.1p112
|
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
2.0.2
|
2.0.2
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
|
|
||||||
<div class="form-inputs p-l-25">
|
<div class="form-inputs p-l-25">
|
||||||
<%= f.input :name,:input_html=>{:class=>"col-md-9"} %>
|
<%= f.input :name,:input_html=>{:class=>"col-md-9"} %>
|
||||||
<%= f.input :is_active,:input_html=>{:class=>"col-md-9"} %>
|
<%= f.input :is_active,:input_html=>{:class=>"col-md-9"}, as: :boolean %>
|
||||||
<%= f.input :is_ordering,:input_html=>{:class=>"col-md-9"} %>
|
<%= f.input :is_ordering,:input_html=>{:class=>"col-md-9"}, as: :boolean %>
|
||||||
<div class="row checkboxes ">
|
<div class="row checkboxes ">
|
||||||
<div class="col-md-2">
|
<div class="col-md-2">
|
||||||
<label class="control-label"><abbr title="required">*</abbr> Valid Day</label>
|
<label class="control-label"><abbr title="required">*</abbr> Valid Day</label>
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-actions p-l-20">
|
<div class="form-actions p-l-20">
|
||||||
@@ -58,7 +58,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
|
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
@@ -81,7 +81,7 @@
|
|||||||
2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.menu_txt") %> <br>
|
2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.menu_txt") %> <br>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
@@ -114,4 +114,3 @@
|
|||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
100
config/deploy.rb
100
config/deploy.rb
@@ -1,20 +1,106 @@
|
|||||||
lock "3.10.1"
|
# config valid only for current version of Capistrano
|
||||||
|
lock '3.11.2'
|
||||||
|
|
||||||
set :application, "zsai"
|
set :application, 'SmartsalesSX'
|
||||||
set :repo_url, 'git@bitbucket.org:code2lab/sxrestaurant.git'
|
|
||||||
|
|
||||||
set :deploy_user, 'deploy'
|
set :deploy_user, 'deploy'
|
||||||
|
set :deploy_to, '/home/deploy/apps/SmartsalesSX'
|
||||||
|
|
||||||
set :rbenv_type, :global
|
# setup repo details
|
||||||
|
#set :scm, :git
|
||||||
|
set :repo_url, 'git@gitlab.com:code2lab/SXRestaurant.git'
|
||||||
|
|
||||||
|
# setup rbenv.
|
||||||
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
|
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
|
||||||
|
|
||||||
set :rbenv_map_bins, %w{rake gem bundle ruby rails}
|
set :rbenv_map_bins, %w{rake gem bundle ruby rails}
|
||||||
|
|
||||||
|
# how many old releases do we want to keep, not much
|
||||||
set :keep_releases, 5
|
set :keep_releases, 5
|
||||||
|
|
||||||
set :linked_files, %w{config/database.yml config/secrets.yml config/puma.rb config/sidekiq.yml config/shops.json config/cable.yml}
|
# files we want symlinking to specific entries in shared
|
||||||
|
set :linked_files, %w{config/database.yml config/secrets.yml}
|
||||||
|
|
||||||
set :linked_dirs, %w{bin log tmp/puma tmp/pids tmp/cache tmp/sockets vendor/bundle public/system pids sockets}
|
# dirs we want symlinking to shared
|
||||||
|
set :linked_dirs, %w{log tmp/pids tmp/puma tmp/cache tmp/sockets vendor/bundle public/system}
|
||||||
|
|
||||||
|
# what specs should be run before deployment is allowed to
|
||||||
|
# continue, see lib/capistrano/tasks/run_tests.cap
|
||||||
set :tests, []
|
set :tests, []
|
||||||
set :pty, true
|
set :pty, true
|
||||||
|
|
||||||
|
set :puma_jungle_conf, '/etc/puma.conf'
|
||||||
|
set :puma_run_path, '/usr/local/bin/run-puma'
|
||||||
|
set :puma_bind, %w(tcp://0.0.0.0:9393)
|
||||||
|
|
||||||
|
#set :enable_ssl, true
|
||||||
|
|
||||||
|
# which config files should be copied by deploy:setup_config
|
||||||
|
# see documentation in lib/capistrano/tasks/setup_config.cap
|
||||||
|
# for details of operations
|
||||||
|
set(:config_files, %w(
|
||||||
|
database.yml
|
||||||
|
log_rotation
|
||||||
|
monit.conf
|
||||||
|
sidekiq_init.sh
|
||||||
|
sidekiq.yml
|
||||||
|
))
|
||||||
|
|
||||||
|
# which config files should be made executable after copying
|
||||||
|
# by deploy:setup_config
|
||||||
|
set(:executable_config_files, %w(
|
||||||
|
sidekiq_init.sh
|
||||||
|
))
|
||||||
|
|
||||||
|
# files which need to be symlinked to other parts of the
|
||||||
|
# filesystem. For example nginx virtualhosts, log rotation
|
||||||
|
# init scripts etc. The full_app_name variable isn't
|
||||||
|
# available at this point so we use a custom template {{}}
|
||||||
|
# tag and then add it at run time.
|
||||||
|
set(:symlinks, [
|
||||||
|
{
|
||||||
|
source: "sidekiq_init.sh",
|
||||||
|
link: "/etc/init.d/sidekiq_{{full_app_name}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: "log_rotation",
|
||||||
|
link: "/etc/logrotate.d/{{full_app_name}}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: "monit",
|
||||||
|
link: "/etc/monit/conf.d/{{full_app_name}}.conf"
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
|
# this:
|
||||||
|
# http://www.capistranorb.com/documentation/getting-started/flow/
|
||||||
|
# is worth reading for a quick overview of what tasks are called
|
||||||
|
# and when for `cap stage deploy`
|
||||||
|
|
||||||
|
namespace :deploy do
|
||||||
|
# make sure we're deploying what we think we're deploying
|
||||||
|
before :deploy, "deploy:check_revision"
|
||||||
|
# only allow a deploy with passing tests to deployed
|
||||||
|
before :deploy, "deploy:run_tests"
|
||||||
|
# compile assets locally then rsync
|
||||||
|
after 'deploy:symlink:shared', 'deploy:compile_assets_locally'
|
||||||
|
Rake::Task["deploy:assets:precompile"].clear_actions
|
||||||
|
|
||||||
|
after :finishing, 'deploy:cleanup'
|
||||||
|
|
||||||
|
#nginx will be install in the Load Balancer - No need to deploy there
|
||||||
|
# remove the default nginx configuration as it will tend
|
||||||
|
# to conflict with our configs.
|
||||||
|
#before 'deploy:setup_config', 'nginx:remove_default_vhost'
|
||||||
|
|
||||||
|
# reload nginx to it will pick up any modified vhosts from
|
||||||
|
# setup_config
|
||||||
|
#after 'deploy:setup_config', 'nginx:reload'
|
||||||
|
|
||||||
|
# Restart monit so it will pick up any monit configurations
|
||||||
|
# we've added
|
||||||
|
#after 'deploy:setup_config', 'monit:restart'
|
||||||
|
|
||||||
|
# As of Capistrano 3.1, the `deploy:restart` task is not called
|
||||||
|
# automatically.
|
||||||
|
after 'finishing', 'puma:jungle:restart'
|
||||||
|
end
|
||||||
|
|||||||
@@ -9,13 +9,12 @@
|
|||||||
# set :rails_env, :production
|
# set :rails_env, :production
|
||||||
|
|
||||||
set :stage, :production
|
set :stage, :production
|
||||||
set :server_name, "svr.sxrestaurant.host"
|
set :server_name, "a.c2l.shop"
|
||||||
|
set :branch, "r-1902001-01"
|
||||||
|
|
||||||
set :full_app_name, "#{fetch(:application)}_#{fetch(:stage)}"
|
set :full_app_name, "#{fetch(:application)}_#{fetch(:stage)}"
|
||||||
|
server '167.71.194.57', user: 'deploy', roles: %w{web app db}, primary: true
|
||||||
server '52.77.219.228', user: 'deploy', roles: %w{web app db}, primary: true
|
|
||||||
|
|
||||||
set :deploy_to, "/home/#{fetch(:deploy_user)}/apps/#{fetch(:full_app_name)}"
|
set :deploy_to, "/home/#{fetch(:deploy_user)}/apps/#{fetch(:full_app_name)}"
|
||||||
set :rbenv_ruby, '2.4.1'
|
set :rbenv_ruby, '2.6.5'
|
||||||
set :rails_env, :production
|
set :rails_env, :production
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
if File.exist?("config/license.yml")
|
if File.exist?("config/license.yml")
|
||||||
config = YAML.load_file(Rails.root.join("config/license.yml"))
|
config = YAML.load_file(Rails.root.join("config/license.yml"))
|
||||||
config.fetch(Rails.env, {}).each do |key, value|
|
config.fetch(Rails.env, {}).each do |key, value|
|
||||||
ENV[key.upcase] = value.to_s
|
ENV[key.upcase] = value.to_s
|
||||||
end
|
end
|
||||||
end
|
else
|
||||||
|
ENV["SERVER_MODE"] = "cloud"
|
||||||
|
end
|
||||||
|
|||||||
@@ -1,31 +1,33 @@
|
|||||||
version: '3'
|
version: '3'
|
||||||
services:
|
services:
|
||||||
code2lab:
|
code2lab:
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: ./Dockerfile
|
dockerfile: ./Dockerfile
|
||||||
links:
|
links:
|
||||||
- redis
|
- redis
|
||||||
volumes:
|
volumes:
|
||||||
- .:/sxrestaurant
|
- .:/sxrestaurant
|
||||||
env_file:
|
- "/etc/timezone:/etc/timezone:ro"
|
||||||
- .code2lab.env
|
- "/etc/localtime:/etc/localtime:ro"
|
||||||
ports:
|
env_file:
|
||||||
- '8082:62158'
|
- .code2lab.env
|
||||||
environment:
|
ports:
|
||||||
- REDIS_URL=redis://redis:6379/0
|
- '62160:62158'
|
||||||
sidekiq:
|
environment:
|
||||||
build: .
|
- REDIS_URL=redis://172.17.0.1:6380/0
|
||||||
command: bundle exec sidekiq -C config/sidekiq.yml
|
sidekiq:
|
||||||
links:
|
build: .
|
||||||
- redis
|
command: bundle exec sidekiq -C config/sidekiq.yml
|
||||||
volumes:
|
links:
|
||||||
- .:/sxrestaurant
|
- redis
|
||||||
environment:
|
volumes:
|
||||||
- REDIS_URL=redis://redis:6379/0
|
- .:/sxrestaurant
|
||||||
redis:
|
environment:
|
||||||
image: redis
|
- REDIS_URL=redis://172.17.0.1:6380/0
|
||||||
ports:
|
redis:
|
||||||
- '6380:6379'
|
image: redis
|
||||||
volumes:
|
ports:
|
||||||
- ../data/redis:/data
|
- '6380:6379'
|
||||||
|
volumes:
|
||||||
|
- ../data/redis:/data
|
||||||
|
|||||||
12
lib/capistrano/substitute_strings.rb
Normal file
12
lib/capistrano/substitute_strings.rb
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# we often want to refer to variables which
|
||||||
|
# are defined in subsequent stage files. This
|
||||||
|
# let's us use the {{var}} to represent fetch(:var)
|
||||||
|
# in strings which are only evaluated at runtime.
|
||||||
|
|
||||||
|
def sub_strings(input_string)
|
||||||
|
output_string = input_string
|
||||||
|
input_string.scan(/{{(\w*)}}/).each do |var|
|
||||||
|
output_string.gsub!("{{#{var[0]}}}", fetch(var[0].to_sym))
|
||||||
|
end
|
||||||
|
output_string
|
||||||
|
end
|
||||||
14
lib/capistrano/tasks/check_revision.cap
Normal file
14
lib/capistrano/tasks/check_revision.cap
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
namespace :deploy do
|
||||||
|
desc "checks whether the currently checkout out revision matches the
|
||||||
|
remote one we're trying to deploy from"
|
||||||
|
task :check_revision do
|
||||||
|
branch = fetch(:branch)
|
||||||
|
unless `git rev-parse HEAD` == `git rev-parse #{branch}`
|
||||||
|
puts "WARNING: HEAD is not the same as #{branch}"
|
||||||
|
puts "Run `git push` to sync changes or make sure you've"
|
||||||
|
puts "checked out the branch: #{branch} as you can only deploy"
|
||||||
|
puts "if you've got the target branch checked out"
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
17
lib/capistrano/tasks/compile_assets_locally.cap
Normal file
17
lib/capistrano/tasks/compile_assets_locally.cap
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
namespace :deploy do
|
||||||
|
desc "compiles assets locally then rsyncs"
|
||||||
|
task :compile_assets_locally do
|
||||||
|
run_locally do
|
||||||
|
execute "RAILS_ENV=#{fetch(:rails_env)} bundle exec rake assets:precompile"
|
||||||
|
end
|
||||||
|
on roles(:app) do |role|
|
||||||
|
run_locally do
|
||||||
|
execute"rsync -av ./public/assets/ #{role.user}@#{role.hostname}:#{release_path}/public/assets/;"
|
||||||
|
end
|
||||||
|
sudo "chmod -R 755 #{release_path}/public/assets/"
|
||||||
|
end
|
||||||
|
run_locally do
|
||||||
|
execute "rm -rf ./public/assets"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
14
lib/capistrano/tasks/logs.cap
Normal file
14
lib/capistrano/tasks/logs.cap
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
namespace :logs do
|
||||||
|
task :tail, :file do |t, args|
|
||||||
|
if args[:file]
|
||||||
|
on roles(:app) do
|
||||||
|
execute "tail -f #{shared_path}/log/#{args[:file]}.log"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
puts "please specify a logfile e.g: 'rake logs:tail[logfile]"
|
||||||
|
puts "will tail 'shared_path/log/logfile.log'"
|
||||||
|
puts "remember if you use zsh you'll need to format it as:"
|
||||||
|
puts "rake 'logs:tail[logfile]' (single quotes)"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
10
lib/capistrano/tasks/monit.cap
Normal file
10
lib/capistrano/tasks/monit.cap
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace :monit do
|
||||||
|
%w(start stop restart).each do |task_name|
|
||||||
|
desc "#{task_name} Monit"
|
||||||
|
task task_name do
|
||||||
|
on roles(:app), in: :sequence, wait: 5 do
|
||||||
|
sudo "service monit #{task_name}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
22
lib/capistrano/tasks/nginx.cap
Normal file
22
lib/capistrano/tasks/nginx.cap
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
namespace :nginx do
|
||||||
|
%w(start stop restart reload).each do |task_name|
|
||||||
|
desc "#{task } Nginx"
|
||||||
|
task task_name do
|
||||||
|
on roles(:app), in: :sequence, wait: 5 do
|
||||||
|
sudo "/etc/init.d/nginx #{task_name}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Remove default Nginx Virtual Host"
|
||||||
|
task "remove_default_vhost" do
|
||||||
|
on roles(:app) do
|
||||||
|
if test("[ -f /etc/nginx/sites-enabled/default ]")
|
||||||
|
sudo "rm /etc/nginx/sites-enabled/default"
|
||||||
|
puts "removed default Nginx Virtualhost"
|
||||||
|
else
|
||||||
|
puts "No default Nginx Virtualhost to remove"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
10
lib/capistrano/tasks/restart.cap
Normal file
10
lib/capistrano/tasks/restart.cap
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace :deploy do
|
||||||
|
desc 'Commands for unicorn application'
|
||||||
|
%w(start stop force-stop restart upgrade reopen-logs).each do |command|
|
||||||
|
task command.to_sym do
|
||||||
|
on roles(:app), in: :sequence, wait: 5 do
|
||||||
|
sudo "/etc/init.d/unicorn_#{fetch(:full_app_name)} #{command}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
18
lib/capistrano/tasks/run_tests.cap
Normal file
18
lib/capistrano/tasks/run_tests.cap
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
namespace :deploy do
|
||||||
|
desc "Runs test before deploying, can't deploy unless they pass"
|
||||||
|
task :run_tests do
|
||||||
|
test_log = "log/capistrano.test.log"
|
||||||
|
tests = fetch(:tests)
|
||||||
|
tests.each do |test|
|
||||||
|
puts "--> Running tests: '#{test}', please wait ..."
|
||||||
|
unless system "bundle exec rspec #{test} > #{test_log} 2>&1"
|
||||||
|
puts "--> Tests: '#{test}' failed. Results in: #{test_log} and below:"
|
||||||
|
system "cat #{test_log}"
|
||||||
|
exit;
|
||||||
|
end
|
||||||
|
puts "--> '#{test}' passed"
|
||||||
|
end
|
||||||
|
puts "--> All tests passed"
|
||||||
|
system "rm #{test_log}"
|
||||||
|
end
|
||||||
|
end
|
||||||
33
lib/capistrano/tasks/setup_config.cap
Normal file
33
lib/capistrano/tasks/setup_config.cap
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
namespace :deploy do
|
||||||
|
task :setup_config do
|
||||||
|
on roles(:app) do
|
||||||
|
# make the config dir
|
||||||
|
execute :mkdir, "-p #{shared_path}/config"
|
||||||
|
full_app_name = fetch(:full_app_name)
|
||||||
|
|
||||||
|
# config files to be uploaded to shared/config, see the
|
||||||
|
# definition of smart_template for details of operation.
|
||||||
|
# Essentially looks for #{filename}.erb in deploy/#{full_app_name}/
|
||||||
|
# and if it isn't there, falls back to deploy/#{shared}. Generally
|
||||||
|
# everything should be in deploy/shared with params which differ
|
||||||
|
# set in the stage files
|
||||||
|
config_files = fetch(:config_files)
|
||||||
|
config_files.each do |file|
|
||||||
|
smart_template file
|
||||||
|
end
|
||||||
|
|
||||||
|
# which of the above files should be marked as executable
|
||||||
|
executable_files = fetch(:executable_config_files)
|
||||||
|
executable_files.each do |file|
|
||||||
|
execute :chmod, "+x #{shared_path}/config/#{file}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# symlink stuff which should be... symlinked
|
||||||
|
symlinks = fetch(:symlinks)
|
||||||
|
|
||||||
|
symlinks.each do |symlink|
|
||||||
|
sudo "ln -nfs #{shared_path}/config/#{symlink[:source]} #{sub_strings(symlink[:link])}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
32
lib/capistrano/template.rb
Normal file
32
lib/capistrano/template.rb
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# will first try and copy the file:
|
||||||
|
# config/deploy/#{full_app_name}/#{from}.erb
|
||||||
|
# to:
|
||||||
|
# shared/config/to
|
||||||
|
# if the original source path doesn exist then it will
|
||||||
|
# search in:
|
||||||
|
# config/deploy/shared/#{from}.erb
|
||||||
|
# this allows files which are common to all enviros to
|
||||||
|
# come from a single source while allowing specific
|
||||||
|
# ones to be over-ridden
|
||||||
|
# if the target file name is the same as the source then
|
||||||
|
# the second parameter can be left out
|
||||||
|
def smart_template(from, to=nil)
|
||||||
|
to ||= from
|
||||||
|
full_to_path = "#{shared_path}/config/#{to}"
|
||||||
|
if from_erb_path = template_file(from)
|
||||||
|
from_erb = StringIO.new(ERB.new(File.read(from_erb_path)).result(binding))
|
||||||
|
upload! from_erb, full_to_path
|
||||||
|
info "copying: #{from_erb} to: #{full_to_path}"
|
||||||
|
else
|
||||||
|
error "error #{from} not found"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def template_file(name)
|
||||||
|
if File.exist?((file = "config/deploy/#{fetch(:full_app_name)}/#{name}.erb"))
|
||||||
|
return file
|
||||||
|
elsif File.exist?((file = "config/deploy/shared/#{name}.erb"))
|
||||||
|
return file
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user