Commit 0c5cc316 by Quang Vinh Nguyen

test capistrano 01

parent 8afb0695
# Load DSL and set up stages
require "capistrano/setup"
# Include default deployment tasks
require "capistrano/deploy"
require "capistrano/rails"
require "capistrano/passenger"
require "capistrano/rbenv"
require "capistrano/yarn"
require "capistrano/bundler"
# rbenv
set :rbenv_type, :user
set :rbenv_ruby, "2.5.1"
# 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"
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
...@@ -4,7 +4,6 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } ...@@ -4,7 +4,6 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.1' ruby '2.5.1'
gem 'devise', '4.4.3' gem 'devise', '4.4.3'
gem 'redis'
gem 'json' gem 'json'
gem 'bootstrap' gem 'bootstrap'
gem 'jquery-rails' gem 'jquery-rails'
...@@ -12,44 +11,24 @@ gem 'kaminari' ...@@ -12,44 +11,24 @@ gem 'kaminari'
gem 'rsolr' gem 'rsolr'
gem 'rsolr-ext' gem 'rsolr-ext'
gem 'config' gem 'config'
gem 'twitter-bootstrap-rails', :group => :assets gem 'twitter-bootstrap-rails', :group => :assets
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.0' gem 'rails', '~> 5.2.0'
# Use mysql as the database for Active Record
gem 'mysql2', '>= 0.4.4', '< 0.6.0' gem 'mysql2', '>= 0.4.4', '< 0.6.0'
# Use Puma as the app server
gem 'puma', '~> 3.11' gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0' gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0' gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2' gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5' gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5' gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false gem 'bootsnap', '>= 1.1.0', require: false
group :development, :test do group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'rspec-rails' gem 'rspec-rails'
...@@ -60,27 +39,26 @@ group :development, :test do ...@@ -60,27 +39,26 @@ group :development, :test do
end end
group :development do group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0' gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2' gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring' gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0' gem 'spring-watcher-listen', '~> 2.0.0'
gem 'pry' gem 'pry'
gem "better_errors" gem 'better_errors'
gem "binding_of_caller" gem 'binding_of_caller'
gem 'capistrano'
gem 'capistrano-rails'
gem 'capistrano-passenger'
gem 'capistrano-yarn'
gem 'capistrano-rbenv'
end end
group :test do group :test do
# Adds support for Capybara system testing and selenium driver
# gem 'capybara', '>= 2.15', '< 4.0'
gem 'selenium-webdriver' gem 'selenium-webdriver'
# Easy installation and use of chromedriver to run system tests with Chrome
gem 'chromedriver-helper' gem 'chromedriver-helper'
gem 'shoulda-matchers', '~> 3.1' gem 'shoulda-matchers', '~> 3.1'
gem 'database_cleaner' gem 'database_cleaner'
end end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
...@@ -44,6 +44,8 @@ GEM ...@@ -44,6 +44,8 @@ GEM
tzinfo (~> 1.1) tzinfo (~> 1.1)
addressable (2.5.2) addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0) public_suffix (>= 2.0.2, < 4.0)
airbrussh (1.3.0)
sshkit (>= 1.6.1, != 1.7.0)
archive-zip (0.11.0) archive-zip (0.11.0)
io-like (~> 0.3.0) io-like (~> 0.3.0)
arel (9.0.0) arel (9.0.0)
...@@ -71,6 +73,24 @@ GEM ...@@ -71,6 +73,24 @@ GEM
sass (>= 3.5.2) sass (>= 3.5.2)
builder (3.2.3) builder (3.2.3)
byebug (10.0.2) byebug (10.0.2)
capistrano (3.11.0)
airbrussh (>= 1.0.0)
i18n
rake (>= 10.0.0)
sshkit (>= 1.9.0)
capistrano-bundler (1.3.0)
capistrano (~> 3.1)
sshkit (~> 1.2)
capistrano-passenger (0.2.0)
capistrano (~> 3.0)
capistrano-rails (1.4.0)
capistrano (~> 3.1)
capistrano-bundler (~> 1.1)
capistrano-rbenv (2.1.3)
capistrano (~> 3.1)
sshkit (~> 1.3)
capistrano-yarn (2.0.2)
capistrano (~> 3.0)
capybara (3.2.1) capybara (3.2.1)
addressable addressable
mini_mime (>= 0.1.3) mini_mime (>= 0.1.3)
...@@ -212,6 +232,9 @@ GEM ...@@ -212,6 +232,9 @@ GEM
mysql2 (0.5.1-x64-mingw32) mysql2 (0.5.1-x64-mingw32)
mysql2 (0.5.1-x86-mingw32) mysql2 (0.5.1-x86-mingw32)
mysql2 (0.5.1-x86-mswin32-60) mysql2 (0.5.1-x86-mswin32-60)
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-ssh (5.0.2)
nio4r (2.3.1) nio4r (2.3.1)
nio4r (2.3.1-java) nio4r (2.3.1-java)
nokogiri (1.8.2) nokogiri (1.8.2)
...@@ -336,6 +359,9 @@ GEM ...@@ -336,6 +359,9 @@ GEM
actionpack (>= 4.0) actionpack (>= 4.0)
activesupport (>= 4.0) activesupport (>= 4.0)
sprockets (>= 3.0.0) sprockets (>= 3.0.0)
sshkit (1.16.1)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
thor (0.20.0) thor (0.20.0)
thread_safe (0.3.6) thread_safe (0.3.6)
thread_safe (0.3.6-java) thread_safe (0.3.6-java)
...@@ -383,6 +409,11 @@ DEPENDENCIES ...@@ -383,6 +409,11 @@ DEPENDENCIES
bootsnap (>= 1.1.0) bootsnap (>= 1.1.0)
bootstrap bootstrap
byebug byebug
capistrano
capistrano-passenger
capistrano-rails
capistrano-rbenv
capistrano-yarn
capybara (>= 2.15, < 4.0) capybara (>= 2.15, < 4.0)
chromedriver-helper chromedriver-helper
coffee-rails (~> 4.2) coffee-rails (~> 4.2)
......
# config valid for current version and patch releases of Capistrano
lock "~> 3.11.0"
set :application, "venjobs_app"
set :repo_url, "git@gitlab.zigexn.vn:vinhnq/venjobs_app.git"
# restart app by running: touch tmp/restart.txt
# at server machine
set :passenger_restart_with_touch, true
set :puma_threads, [4,16]
# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, "/var/www/venjobs_app"
# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
# Default deploy_to directory is /var/www/my_app_name
# set :deploy_to, "/var/www/my_app_name"
# 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/database.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
# 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:
# server "example.com", user: "deploy", roles: %w{app db web}, my_property: :my_value
# server "example.com", user: "deploy", roles: %w{app web}, other_property: :other_value
# server "db.example.com", user: "deploy", roles: %w{db}
# 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"
# }
set :stage, :production
set :rails_env, :production
set :branch, "master"
# server "<MACHINE_IP>", user: "<LOGIN_USER>", roles: %w{app db web}
server "192.168.1.74", user: "admin", roles: %w{app db web}
\ No newline at end of file
# 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:
# server "example.com", user: "deploy", roles: %w{app db web}, my_property: :my_value
# server "example.com", user: "deploy", roles: %w{app web}, other_property: :other_value
# server "db.example.com", user: "deploy", roles: %w{db}
# 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"
# }
solr: solr:
url: "http://localhost:8983/solr/gettingstarted/" url: "http://192.168.1.58:8983/solr/gettingstarted/"
row: 25 row: 25
df: "search_text" df: "search_text"
solr:
url: "http://192.168.1.58:8983/solr/gettingstarted/"
row: 25
df: "search_text"
1,Ngành Kế Toán, buôn bán - kinh doanh
2,Ngành kiểm toán, buôn bán - kinh doanh
3,Ngành Thương mại Điện Tử, buôn bán - kinh doanh
4,Ngành Tài Chính – Ngân hàng, buôn bán - kinh doanh
5,Quản Trị Kinh Doanh., buôn bán - kinh doanh
6,Kinh tế - Tài chính, buôn bán - kinh doanh
7,Ngành marketing, buôn bán - kinh doanh
8,Ngành Bảo hiểm., buôn bán - kinh doanh
9,Ngành quảng cáo, buôn bán - kinh doanh
10,Ngành Quảng trị nhân sự, buôn bán - kinh doanh
11,Quản trị khách sạn, buôn bán - kinh doanh
12,Chứng khoán, buôn bán - kinh doanh
13,Thanh toán quốc tế, buôn bán - kinh doanh
\ No newline at end of file
# frozen_string_literal: true # # frozen_string_literal: true
namespace :importdb do # namespace :importdb do
require 'pry' # # require 'pry'
require 'json' # require 'json'
require 'redis' # require 'redis'
require 'csv' # require 'csv'
require 'yaml' # require 'yaml'
desc 'import data to cities table' # desc 'import data to cities table'
task cities: :environment do # task cities: :environment do
city_redis = Redis.new # city_redis = Redis.new
city_yaml_arr = city_redis.smembers('cities') # city_yaml_arr = city_redis.smembers('cities')
city_yaml_arr.each do |row| # city_yaml_arr.each do |row|
city = YAML.safe_load(row) # city = YAML.safe_load(row)
next if City.find_by(name: city[1]) # next if City.find_by(name: city[1])
City.create!( code: city[0], # City.create!( code: city[0],
name: city[1], # name: city[1],
slug: city[2]) # slug: city[2])
end # end
end # end
desc 'import data to companies table' # desc 'import data to companies table'
task companies: :environment do # task companies: :environment do
# Company.create!( # # Company.create!(
# name: Faker::Company.name, # # name: Faker::Company.name,
# description: Faker::Lorem.paragraph, # # description: Faker::Lorem.paragraph,
# address: Faker::Address.street_address, # # address: Faker::Address.street_address,
# email: Faker::Internet.email, # # email: Faker::Internet.email,
# phone: '123-456-7890', # # phone: '123-456-7890',
# fax: '123-456-7890', # # fax: '123-456-7890',
# number_of_employees: '1000 - 2000' # # number_of_employees: '1000 - 2000'
# ) # # )
end # end
desc 'seed industries data' # desc 'seed industries data'
task industries: :environment do # task industries: :environment do
inds_redis = Redis.new # inds_redis = Redis.new
inds_yaml_arr = inds_redis.smembers('industry') # inds_yaml_arr = inds_redis.smembers('industry')
inds_yaml_arr.each do |row| # inds_yaml_arr.each do |row|
ind = YAML.safe_load(row) # ind = YAML.safe_load(row)
next if Industry.find_by(name: ind[1]) # next if Industry.find_by(name: ind[1])
Industry.create!( code: ind[0], # Industry.create!( code: ind[0],
name: ind[1], # name: ind[1],
slug: ind[2] ) # slug: ind[2] )
end # end
end # end
desc 'seed jobs data' # desc 'seed jobs data'
task jobs: :environment do # task jobs: :environment do
jobs_redis = Redis.new # jobs_redis = Redis.new
jobs_yaml_arr = jobs_redis.smembers 'crawled' # jobs_yaml_arr = jobs_redis.smembers 'crawled'
jobs_yaml_arr.each_with_index do |row,id| # jobs_yaml_arr.each_with_index do |row,id|
# break if id == 100 # # break if id == 100
job = YAML.safe_load(row) # job = YAML.safe_load(row)
next if job[1].blank? || !!Job.find_by(title: job[1]) || !!Job.find_by(link: job[14]) # next if job[1].blank? || !!Job.find_by(title: job[1]) || !!Job.find_by(link: job[14])
# create job company # # create job company
next if job[2].blank? # next if job[2].blank?
company = Company.find_by(name: job[2]) # company = Company.find_by(name: job[2])
unless company # unless company
company = Company.create( name: job[2], # company = Company.create( name: job[2],
description: Faker::Lorem.paragraph, # description: Faker::Lorem.paragraph,
address: Faker::Address.street_address, # address: Faker::Address.street_address,
email: Faker::Internet.email, # email: Faker::Internet.email,
phone: '123-456-7890', # phone: '123-456-7890',
fax: '123-456-7890', # fax: '123-456-7890',
number_of_employees: '1000 - 2000' # number_of_employees: '1000 - 2000'
) # )
end # end
next unless company # next unless company
# create job # # create job
job_new = Job.create!( # job_new = Job.create!(
title: job[1], # title: job[1],
company_id: company.id, # company_id: company.id,
position: 'NA', # position: 'NA',
salary: job[7], # salary: job[7],
expiry_date: Time.now, # expiry_date: Time.now,
description: job[10], # description: job[10],
update_date: Time.now, # update_date: Time.now,
published: true, # published: true,
welfare: 'NA', # welfare: 'NA',
condition: 'NA', # condition: 'NA',
link: job[14] # link: job[14]
) # )
# import job industry # # import job industry
industry_arr = job[5].split('+').map { |ind| ind.strip } # industry_arr = job[5].split('+').map { |ind| ind.strip }
if industry_arr.any? # if industry_arr.any?
industry_arr.each do |ind| # industry_arr.each do |ind|
ind_id = Industry.find_by(name: ind).id || Industry.first.id # ind_id = Industry.find_by(name: ind).id || Industry.first.id
job_new.industries_jobs.create!(industry_id: ind_id) # job_new.industries_jobs.create!(industry_id: ind_id)
end # end
else # else
job_new.industries_jobs.create!(industry_id: City.first.id) # job_new.industries_jobs.create!(industry_id: City.first.id)
end # end
# import job city # # import job city
city_arr = job[3].split(',').map { |city| city.strip } # city_arr = job[3].split(',').map { |city| city.strip }
if city_arr.any? # if city_arr.any?
city_arr.each do |city| # city_arr.each do |city|
city_id = City.find_by(name: city).id || City.first.id # city_id = City.find_by(name: city).id || City.first.id
job_new.cities_jobs.create!(city_id: city_id) # job_new.cities_jobs.create!(city_id: city_id)
end # end
else # else
job_new.cities_jobs.create!(city_id: City.first.id) # job_new.cities_jobs.create!(city_id: City.first.id)
end # end
end # end
end # end
end # end
# frozen_string_literal: true # # frozen_string_literal: true
namespace :update do # namespace :update do
desc 'update solr index from database' # desc 'update solr index from database'
task solr: :environment do # task solr: :environment do
solr = RSolr.connect url: 'http://localhost:8983/solr/gettingstarted/' # solr = RSolr.connect url: 'http://localhost:8983/solr/gettingstarted/'
jobs = Job.all # jobs = Job.all
if jobs.any? # if jobs.any?
jobs.each_with_index do |job, id| # jobs.each_with_index do |job, id|
# break if id == 10 # # break if id == 10
# check is job_id is exist and not update job to solr # # check is job_id is exist and not update job to solr
response_solr = solr.get 'select', params: { q: "job_id: #{job['id']}" } # response_solr = solr.get 'select', params: { q: "job_id: #{job['id']}" }
next if response_solr['response']['docs'].any? # next if response_solr['response']['docs'].any?
# hash of job attribute array: city_name, ... # # hash of job attribute array: city_name, ...
h = {} # h = {}
# h['city_id'] = job.cities.collect { |city| city['id'].to_s } # # h['city_id'] = job.cities.collect { |city| city['id'].to_s }
h['city_name'] = job.cities.collect { |city| city['name'].downcase } # h['city_name'] = job.cities.collect { |city| city['name'].downcase }
h['city_slug'] = job.cities.collect { |city| city['slug'] } # h['city_slug'] = job.cities.collect { |city| city['slug'] }
# h['industry_id'] = job.industries.collect { |ind| ind['id'].to_s } # # h['industry_id'] = job.industries.collect { |ind| ind['id'].to_s }
h['industry_name'] = job.industries.collect { |ind| ind['name'].downcase } # h['industry_name'] = job.industries.collect { |ind| ind['name'].downcase }
h['industry_slug'] = job.industries.collect { |ind| ind['slug'] } # h['industry_slug'] = job.industries.collect { |ind| ind['slug'] }
h['company_name'] = job.company.name.downcase # h['company_name'] = job.company.name.downcase
doc = { # doc = {
job_id: job.id, # job_id: job.id,
job_title: job.title.downcase, # job_title: job.title.downcase,
# job_city_id: h['city_id'], # # job_city_id: h['city_id'],
job_city_name: h['city_name'], # job_city_name: h['city_name'],
job_city_slug: h['city_slug'], # job_city_slug: h['city_slug'],
# job_industry_id: h['industry_id'], # # job_industry_id: h['industry_id'],
job_industry_name: h['industry_name'], # job_industry_name: h['industry_name'],
job_industry_slug: h['industry_slug'], # job_industry_slug: h['industry_slug'],
job_company_name: h['company_name'] # job_company_name: h['company_name']
} # }
solr.add [doc] # solr.add [doc]
end # end
solr.commit # solr.commit
end # end
# solr.delete_by_query '*:*' # # solr.delete_by_query '*:*'
# solr.commit # # solr.commit
end # end
end # end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment