cap deployment setup

This commit is contained in:
Min Zeya Phyo
2019-10-25 12:29:56 +06:30
8 changed files with 155 additions and 41 deletions

View File

@@ -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 }

View File

@@ -113,6 +113,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
@@ -132,4 +133,4 @@ gem 'momentjs-rails' # for date-range selector
# gem 'bootstrap-datepicker-rails' # date picker # gem 'bootstrap-datepicker-rails' # date picker
# gem 'jquery-datetimepicker-rails' # gem 'jquery-datetimepicker-rails'
# gem 'select2-rails' # for multi-select and auto-complete select box # gem 'select2-rails' # for multi-select and auto-complete select box
gem "chartkick" #chart lib gem "chartkick" #chart lib

View File

@@ -73,6 +73,10 @@ GEM
capistrano-rails (1.3.1) capistrano-rails (1.3.1)
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.2.1) carrierwave (1.2.1)
activemodel (>= 4.0.0) activemodel (>= 4.0.0)
activesupport (>= 4.0.0) activesupport (>= 4.0.0)
@@ -317,6 +321,7 @@ 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)
@@ -368,4 +373,4 @@ RUBY VERSION
ruby 2.4.1p111 ruby 2.4.1p111
BUNDLED WITH BUNDLED WITH
2.0.1 2.0.2

View File

@@ -18,36 +18,39 @@ class Customer < ApplicationRecord
paginates_per 50 paginates_per 50
def self.get_member_account(customer) def self.get_member_account(customer)
membership = MembershipSetting.find_by_membership_type("paypar_url") membership = MembershipSetting.active.find_by_membership_type("paypar_url")
memberaction = MembershipAction.find_by_membership_type("get_all_member_account") memberaction = MembershipAction.active.find_by_membership_type("get_all_member_account")
merchant_uid = memberaction.merchant_account_id.to_s merchant_uid = memberaction.merchant_account_id.to_s
auth_token = memberaction.auth_token.to_s auth_token = memberaction.auth_token.to_s
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
# urltest =self.url_exist?(url) # urltest =self.url_exist?(url)
if !membership.nil? && !memberaction.nil?
begin
response = HTTParty.get(url, :body => {
membership_id: customer.membership_id,
merchant_uid:merchant_uid,
type: "summary",
auth_token:auth_token
}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json; version=3'
},
:timeout => 10)
rescue HTTParty::Error
response = {status: false, message: "Server Error"}
rescue Net::OpenTimeout
response = { status: false , message: "Server Time out"}
begin rescue OpenURI::HTTPError
response = HTTParty.get(url, :body => { response = { status: false, message: "Can't connect server"}
membership_id: customer.membership_id,
merchant_uid:merchant_uid,
type: "summary",
auth_token:auth_token
}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json; version=3'
},
:timeout => 10)
rescue HTTParty::Error
response = {status: false, message: "Server Error"}
rescue Net::OpenTimeout
response = { status: false , message: "Server Time out"}
rescue OpenURI::HTTPError rescue SocketError
response = { status: false, message: "Can't connect server"} response = { status: false, message: "Can't connect server"}
end
rescue SocketError else
response = { status: false, message: "Can't connect server"} response = {status: false, message: "There is no membership setting."}
end end
Rails.logger.debug "--------Get Member Account response -------" Rails.logger.debug "--------Get Member Account response -------"
Rails.logger.debug response.to_json Rails.logger.debug response.to_json

View File

@@ -721,7 +721,6 @@ $(document).ready(function(){
var sale_id = $('#sale_id').text(); var sale_id = $('#sale_id').text();
window.location.replace('/origami/sale/'+sale_id+'/cashier/payment'); window.location.replace('/origami/sale/'+sale_id+'/cashier/payment');
} }
/* replace url type*/ /* replace url type*/
/* start check first bill or not*/ /* start check first bill or not*/
var member_id = $('#membership_id').text(); var member_id = $('#membership_id').text();
@@ -1125,6 +1124,8 @@ $(document).ready(function(){
<% else %> <% else %>
$('#balance').text(parseFloat(result)); $('#balance').text(parseFloat(result));
<% end %> <% end %>
show_hide_btn($('#balance').text());
} }
function customer_display_view(data,status) { function customer_display_view(data,status) {
@@ -1831,4 +1832,15 @@ $(document).ready(function(){
} }
},100); },100);
}); });
function show_hide_btn(balance) {
// show discount when balance is greater than 0
// if(parseFloat(balance) > 0){
// $("#discount").show();
// $("#edit").show();
// }else{
// $("#discount").hide();
// $("#edit").hide();
// }
}
</script> </script>

View File

@@ -1,20 +1,105 @@
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'
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

View File

@@ -1,9 +1,10 @@
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 '192.168.1.27', user: 'deploy', roles: %w{web app db}, primary: true server '167.71.194.57', 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

View File

@@ -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