From b025cc2cfd2b10df84cc1cee458efa4eef108752 Mon Sep 17 00:00:00 2001 From: Aung Ye Kyaw Date: Thu, 24 Oct 2019 05:40:56 +0000 Subject: [PATCH 1/9] Update Gemfile Ruby version change 2.3.1 to 2.4.1 (may be someone changed) --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 1a15a61a..66c149ef 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' -ruby '2.3.1' +ruby '2.4.1' git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") "https://github.com/#{repo_name}.git" From 0be67f4f121a9a1e850a01cd1432676e4c3d3ff3 Mon Sep 17 00:00:00 2001 From: Min Zeya Phyo Date: Fri, 25 Oct 2019 12:33:21 +0630 Subject: [PATCH 2/9] SX cap production setup files --- lib/capistrano/substitute_strings.rb | 12 +++++++ lib/capistrano/tasks/check_revision.cap | 14 ++++++++ .../tasks/compile_assets_locally.cap | 17 ++++++++++ lib/capistrano/tasks/logs.cap | 14 ++++++++ lib/capistrano/tasks/monit.cap | 10 ++++++ lib/capistrano/tasks/nginx.cap | 22 +++++++++++++ lib/capistrano/tasks/restart.cap | 10 ++++++ lib/capistrano/tasks/run_tests.cap | 18 ++++++++++ lib/capistrano/tasks/setup_config.cap | 33 +++++++++++++++++++ lib/capistrano/template.rb | 32 ++++++++++++++++++ 10 files changed, 182 insertions(+) create mode 100644 lib/capistrano/substitute_strings.rb create mode 100644 lib/capistrano/tasks/check_revision.cap create mode 100644 lib/capistrano/tasks/compile_assets_locally.cap create mode 100644 lib/capistrano/tasks/logs.cap create mode 100644 lib/capistrano/tasks/monit.cap create mode 100644 lib/capistrano/tasks/nginx.cap create mode 100644 lib/capistrano/tasks/restart.cap create mode 100644 lib/capistrano/tasks/run_tests.cap create mode 100644 lib/capistrano/tasks/setup_config.cap create mode 100644 lib/capistrano/template.rb diff --git a/lib/capistrano/substitute_strings.rb b/lib/capistrano/substitute_strings.rb new file mode 100644 index 00000000..d4b24432 --- /dev/null +++ b/lib/capistrano/substitute_strings.rb @@ -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 diff --git a/lib/capistrano/tasks/check_revision.cap b/lib/capistrano/tasks/check_revision.cap new file mode 100644 index 00000000..72b4aa12 --- /dev/null +++ b/lib/capistrano/tasks/check_revision.cap @@ -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 diff --git a/lib/capistrano/tasks/compile_assets_locally.cap b/lib/capistrano/tasks/compile_assets_locally.cap new file mode 100644 index 00000000..e6264e81 --- /dev/null +++ b/lib/capistrano/tasks/compile_assets_locally.cap @@ -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 diff --git a/lib/capistrano/tasks/logs.cap b/lib/capistrano/tasks/logs.cap new file mode 100644 index 00000000..7bbfac2e --- /dev/null +++ b/lib/capistrano/tasks/logs.cap @@ -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 diff --git a/lib/capistrano/tasks/monit.cap b/lib/capistrano/tasks/monit.cap new file mode 100644 index 00000000..5dbac6a2 --- /dev/null +++ b/lib/capistrano/tasks/monit.cap @@ -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 diff --git a/lib/capistrano/tasks/nginx.cap b/lib/capistrano/tasks/nginx.cap new file mode 100644 index 00000000..dfadd5c6 --- /dev/null +++ b/lib/capistrano/tasks/nginx.cap @@ -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 diff --git a/lib/capistrano/tasks/restart.cap b/lib/capistrano/tasks/restart.cap new file mode 100644 index 00000000..ff8c028f --- /dev/null +++ b/lib/capistrano/tasks/restart.cap @@ -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 diff --git a/lib/capistrano/tasks/run_tests.cap b/lib/capistrano/tasks/run_tests.cap new file mode 100644 index 00000000..32f26f9c --- /dev/null +++ b/lib/capistrano/tasks/run_tests.cap @@ -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 diff --git a/lib/capistrano/tasks/setup_config.cap b/lib/capistrano/tasks/setup_config.cap new file mode 100644 index 00000000..81ce88d9 --- /dev/null +++ b/lib/capistrano/tasks/setup_config.cap @@ -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 diff --git a/lib/capistrano/template.rb b/lib/capistrano/template.rb new file mode 100644 index 00000000..07bd0be3 --- /dev/null +++ b/lib/capistrano/template.rb @@ -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 From bfc697376286b61049872eee350da51778b4cf27 Mon Sep 17 00:00:00 2001 From: Min Zeya Phyo Date: Fri, 25 Oct 2019 13:00:40 +0630 Subject: [PATCH 3/9] Gem lock update --- Gemfile.lock | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 0db34edf..7928786c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -62,7 +62,7 @@ GEM builder (3.2.3) byebug (11.0.1) cancancan (1.17.0) - capistrano (3.10.1) + capistrano (3.11.2) airbrussh (>= 1.0.0) i18n rake (>= 10.0.0) @@ -72,15 +72,11 @@ GEM capistrano-rails (1.4.0) capistrano (~> 3.1) capistrano-bundler (~> 1.1) -<<<<<<< HEAD capistrano3-puma (3.1.1) capistrano (~> 3.7) capistrano-bundler puma (~> 3.4) - carrierwave (1.2.1) -======= carrierwave (1.3.1) ->>>>>>> b025cc2cfd2b10df84cc1cee458efa4eef108752 activemodel (>= 4.0.0) activesupport (>= 4.0.0) mime-types (>= 1.16) @@ -107,8 +103,8 @@ GEM factory_girl_rails (4.9.0) factory_girl (~> 4.9.0) railties (>= 3.0.0) - faker (2.5.0) - i18n (~> 1.6.0) + faker (2.6.0) + i18n (>= 1.6, < 1.8) ffi (1.11.1) filterrific (5.2.1) font-awesome-rails (4.7.0.5) @@ -148,7 +144,7 @@ GEM listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - loofah (2.3.0) + loofah (2.3.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) @@ -231,23 +227,23 @@ GEM chunky_png (~> 1.0) rqrcode_core (~> 0.1.0) rqrcode_core (0.1.0) - rspec-core (3.8.2) - rspec-support (~> 3.8.0) - rspec-expectations (3.8.5) + rspec-core (3.9.0) + rspec-support (~> 3.9.0) + rspec-expectations (3.9.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.8.0) - rspec-mocks (3.8.2) + rspec-support (~> 3.9.0) + rspec-mocks (3.9.0) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) rspec-rails (3.9.0) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) - rspec-support (~> 3.8.0) - rspec-support (3.8.3) + rspec-core (~> 3.9.0) + rspec-expectations (~> 3.9.0) + rspec-mocks (~> 3.9.0) + rspec-support (~> 3.9.0) + rspec-support (3.9.0) ruby-ole (1.2.12.2) rubyzip (1.0.0) sass (3.7.4) @@ -273,10 +269,9 @@ GEM simple_form (5.0.1) actionpack (>= 5.0) activemodel (>= 5.0) - spreadsheet (1.2.4) + spreadsheet (1.2.5) ruby-ole (>= 1.0) - spring (2.0.2) - activesupport (>= 4.2) + spring (2.1.0) spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) spring (>= 1.2, < 3.0) @@ -380,7 +375,7 @@ DEPENDENCIES whenever RUBY VERSION - ruby 2.3.1p112 + ruby 2.4.1p111 BUNDLED WITH 2.0.2 From 77ed76c36864cadee1d17e1adad99eb73a08da08 Mon Sep 17 00:00:00 2001 From: Min Zeya Phyo Date: Fri, 25 Oct 2019 13:04:12 +0630 Subject: [PATCH 4/9] Update Gemfile to use ruby 2.6.5 --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 73701b6c..9f51df74 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' -ruby '2.4.1' +ruby '2.6.5' git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") "https://github.com/#{repo_name}.git" From af3efbe607e68a4fe378ff40c363a2e5d151f88e Mon Sep 17 00:00:00 2001 From: Min Zeya Phyo Date: Fri, 25 Oct 2019 13:06:45 +0630 Subject: [PATCH 5/9] Update Gemfile to use ruby 2.6.5 --- Gemfile | 2 +- Gemfile.lock | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 9f51df74..c489fc3e 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' -ruby '2.6.5' + git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") "https://github.com/#{repo_name}.git" diff --git a/Gemfile.lock b/Gemfile.lock index 7928786c..e28d4fd6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -374,8 +374,5 @@ DEPENDENCIES web-console (>= 3.3.0) whenever -RUBY VERSION - ruby 2.4.1p111 - BUNDLED WITH 2.0.2 From dc1f83ddc9b683c6f09063e442915c94a883ab0b Mon Sep 17 00:00:00 2001 From: Min Zeya Phyo Date: Fri, 25 Oct 2019 13:14:49 +0630 Subject: [PATCH 6/9] remove cups installation for cloud in Gemfile --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index c489fc3e..143907b6 100644 --- a/Gemfile +++ b/Gemfile @@ -44,7 +44,7 @@ gem 'mini_magick' gem 'jquery-fileupload-rails', '~> 0.4.7' #Report and Printing gems -gem 'cups' +#gem 'cups' #remove for cloud installation gem 'prawn' gem 'prawn-table' gem 'prawn-qrcode' From 2e2117a8203764bd8c85dc96905eccc85fc37b8b Mon Sep 17 00:00:00 2001 From: Min Zeya Phyo Date: Fri, 25 Oct 2019 13:20:26 +0630 Subject: [PATCH 7/9] Remove cups for cloud --- Gemfile.lock | 2 -- 1 file changed, 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index e28d4fd6..db4f94aa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -93,7 +93,6 @@ GEM concurrent-ruby (1.1.5) connection_pool (2.2.2) crass (1.0.5) - cups (0.1.10) database_cleaner (1.7.0) diff-lcs (1.3) erubi (1.9.0) @@ -329,7 +328,6 @@ DEPENDENCIES carrierwave (~> 1.0) chartkick coffee-rails (~> 4.2) - cups database_cleaner factory_girl_rails (~> 4.0) faker From d4a90d6563241c995846c8325532a1ce1c9bbf04 Mon Sep 17 00:00:00 2001 From: Min Zeya Phyo Date: Tue, 29 Oct 2019 10:38:50 +0630 Subject: [PATCH 8/9] docker changes --- config/deploy.rb | 1 + docker-compose.yml | 60 ++++++++++++++++++++++++---------------------- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/config/deploy.rb b/config/deploy.rb index 6dba4c2d..05bba77d 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -83,6 +83,7 @@ namespace :deploy do 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' diff --git a/docker-compose.yml b/docker-compose.yml index d1a961f7..ab61383d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,31 +1,33 @@ version: '3' services: - code2lab: - build: - context: . - dockerfile: ./Dockerfile - links: - - redis - volumes: - - .:/sxrestaurant - env_file: - - .code2lab.env - ports: - - '8082:62158' - environment: - - REDIS_URL=redis://redis:6379/0 - sidekiq: - build: . - command: bundle exec sidekiq -C config/sidekiq.yml - links: - - redis - volumes: - - .:/sxrestaurant - environment: - - REDIS_URL=redis://redis:6379/0 - redis: - image: redis - ports: - - '6380:6379' - volumes: - - ../data/redis:/data \ No newline at end of file + code2lab: + build: + context: . + dockerfile: ./Dockerfile + links: + - redis + volumes: + - .:/sxrestaurant + - "/etc/timezone:/etc/timezone:ro" + - "/etc/localtime:/etc/localtime:ro" + env_file: + - .code2lab.env + ports: + - '62160:62158' + environment: + - REDIS_URL=redis://172.17.0.1:6380/0 + sidekiq: + build: . + command: bundle exec sidekiq -C config/sidekiq.yml + links: + - redis + volumes: + - .:/sxrestaurant + environment: + - REDIS_URL=redis://172.17.0.1:6380/0 + redis: + image: redis + ports: + - '6380:6379' + volumes: + - ../data/redis:/data From 83e7f22b13954d9a92d074c397c2faadb38b32dc Mon Sep 17 00:00:00 2001 From: Min Zeya Phyo Date: Tue, 29 Oct 2019 14:15:43 +0630 Subject: [PATCH 9/9] menu form is_ordering and is_active to data type boolean --- app/views/settings/menus/_form.html.erb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/views/settings/menus/_form.html.erb b/app/views/settings/menus/_form.html.erb index 15842333..770a18b3 100755 --- a/app/views/settings/menus/_form.html.erb +++ b/app/views/settings/menus/_form.html.erb @@ -7,8 +7,8 @@
<%= f.input :name,:input_html=>{:class=>"col-md-9"} %> - <%= f.input :is_active,:input_html=>{:class=>"col-md-9"} %> - <%= f.input :is_ordering,: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"}, as: :boolean %>
@@ -50,7 +50,7 @@ <% end %>
- +
@@ -58,7 +58,7 @@
<% end %> - +
@@ -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") %>

-
+ -