forked from pluosi/app-host
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.rb
108 lines (90 loc) · 3.48 KB
/
deploy.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
require 'mina/rails'
require 'mina/git'
# require 'mina/rbenv' # for rbenv support. (https://rbenv.org)
require 'mina/rvm' # for rvm support. (https://rvm.io)
# Basic settings:
# domain - The hostname to SSH to.
# deploy_to - Path to deploy into.
# repository - Git repo to clone from. (needed by mina/git)
# branch - Branch name to deploy. (needed by mina/git)
set :domain, '192.168.66.248'
set :deploy_to, '/app'
set :repository, '[email protected]:beijing/app-host.git'
set :branch, 'master'
# Optional settings:
set :user, 'vagrant' # Username in the server to SSH to.
# set :port, '30000' # SSH port number.
# set :forward_agent, true # SSH forward_agent.
# shared dirs and files will be symlinked into the app-folder by the 'deploy:link_shared_paths' step.
set :shared_dirs, fetch(:shared_dirs, []).push('log', 'public/sitemaps', 'public/uploads', 'tmp')
set :shared_files, fetch(:shared_files, []).push('config/database.yml', 'config/secrets.yml', 'config/settings.local.yml' )
# This task is the environment that is loaded for all remote run commands, such as
# `mina deploy` or `mina rake`.
task :environment do
# If you're using rbenv, use this to load the rbenv environment.
# Be sure to commit your .ruby-version or .rbenv-version to your repository.
# invoke :'rbenv:load'
ruby_version = File.read('.ruby-version').strip
raise "Couldn't determine Ruby version: Do you have a file .ruby-version in your project root?" if ruby_version.empty?
command %{
source "$HOME/.rvm/scripts/rvm"
rvm use #{ruby_version} || exit 1
}
end
# Put any custom commands you need to run at setup
# All paths in `shared_dirs` and `shared_paths` will be created on their own.
task :setup => :environment do
command %{gem install bundler}
# command %{sudo gem install god}
# command %{sudo mkdir -p /etc/god/conf.d/}
%w{log tmp/pids tmp/sockets config public/uploads public/sitemaps}.each do |dir|
command %{mkdir -p "#{fetch(:shared_path)}/#{dir}"}
command %{chmod g+rx,u+rwx "#{fetch(:shared_path)}/#{dir}"}
end
end
desc "Deploys the current version to the server."
task :deploy => :environment do
# uncomment this line to make sure you pushed your local branch to the remote origin
# invoke :'git:ensure_pushed'
deploy do
# Put things that will set up an empty directory into a fully set-up
# instance of your project.
invoke :'git:clone'
invoke :'deploy:link_shared_paths'
invoke :'bundle:install'
invoke :'rails:db_migrate'
invoke :'rails:assets_precompile'
invoke :'deploy:cleanup'
on :launch do
in_path(fetch(:current_path)) do
command %{mkdir -p tmp/}
command %{touch tmp/restart.txt}
end
invoke :'puma:restart'
end
end
# you can use `run :local` to run tasks on local machine before of after the deploy scripts
# run :local { say 'done' }
end
namespace :puma do
desc 'start puma'
task :start => :environment do
in_path(fetch(:current_path)) do
command %{bundle exec puma --config ./config/puma.rb -e production -d}
end
end
desc 'stop puma'
task :stop => :environment do
in_path(fetch(:current_path)) do
command %{bundle exec pumactl stop}
end
end
desc 'restart puma'
task :restart => :environment do
command %{bundle exec pumactl stop || true}
invoke :'puma:start'
end
end
# For help in making your deploy script, see the Mina documentation:
#
# - https://github.com/mina-deploy/mina/tree/master/docs