railman-deployment 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/railman/deployment/set_railman_env.rb +1 -0
- data/lib/railman/deployment/tasks.rb +1 -0
- data/lib/railman/deployment.rb +1 -1
- data/lib/railman/tasks/deployment.rake +53 -44
- data/lib/railman/tasks/set_railman_env.rake +18 -0
- data/lib/railman-deployment/version.rb +1 -1
- metadata +3 -3
- data/lib/railman/deployment/hooks.rb +0 -1
- data/lib/railman/tasks/hooks.rake +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ada16d76a193ef6da390c448c0d6a32b852a4944
|
4
|
+
data.tar.gz: b312b09dd08488928d1b229eabbeaf0bcabc03a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbc4a6ab1d641c1c66c6913183919fd2935d8ce151e5c962bf81bf65c1c26800cc4f99c5b86e4aff043b0eae8cc4cf4d515e2546223fde24aac5c8263b413faf
|
7
|
+
data.tar.gz: 786ec7eaf03b05296f128766f2ef3a0e7b1134e834be9d3f54f08d89dd8bea7e882b86659ccc026b2f836f01fef0a91be9e1418a24a3233e304b552f1f122c71
|
data/README.md
CHANGED
@@ -36,7 +36,7 @@ Add `require 'railman/deployment'` to Capfile and you'll get following capistran
|
|
36
36
|
- `cap ENV deploy` => Deploy rails application
|
37
37
|
- `cap ENV remove` => Remove the application completely from the server
|
38
38
|
- `cap ENV reset_server` => Recreate server database from db/<application_name>.sql
|
39
|
-
- `cap ENV
|
39
|
+
- `cap ENV update` => Synchronize local database with the production database
|
40
40
|
|
41
41
|
|
42
42
|
## Development
|
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path('../../railman/tasks/set_railman_env.rake', __FILE__)
|
data/lib/railman/deployment.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
require_relative 'deployment/tasks'
|
2
|
-
require_relative 'deployment/
|
2
|
+
require_relative 'deployment/set_railman_env'
|
@@ -1,24 +1,11 @@
|
|
1
|
-
|
2
|
-
set :deploy_to, "/home/deploy/apps/#{fetch(:application)}"
|
3
|
-
set :rbenv_home, '/home/deploy/.rbenv'
|
4
|
-
set :environment, {path: "#{fetch(:rbenv_home)}/shims:#{fetch(:rbenv_home)}/bin:$PATH", rails_env: 'production'}
|
5
|
-
|
6
|
-
SSHKit.config.command_map[:rake] = "#{fetch(:deploy_to)}/bin/rake"
|
7
|
-
%w(ln service start restart stop status).each do |cmd|
|
8
|
-
SSHKit.config.command_map[cmd.to_sym] = "sudo #{cmd}"
|
9
|
-
end
|
10
|
-
SSHKit.config.command_map[:eye] = "#{fetch(:rbenv_home)}/shims/eye"
|
11
|
-
SSHKit.config.command_map[:su_rm] = "sudo rm"
|
12
|
-
end
|
13
|
-
|
14
|
-
desc "Setup rails application for the first time on a server"
|
1
|
+
desc 'Setup rails application for the first time on a server'
|
15
2
|
task :setup do
|
16
3
|
on roles(:all) do
|
17
4
|
with fetch(:environment) do
|
18
5
|
if test "[ -d #{fetch(:deploy_to)} ]"
|
19
6
|
within fetch(:deploy_to) do
|
20
|
-
|
21
|
-
|
7
|
+
invoke :fetch_and_reset_git_repository
|
8
|
+
invoke :sync_local_dirs_to_server
|
22
9
|
end
|
23
10
|
else
|
24
11
|
execute :git, :clone, fetch(:repo_url), fetch(:deploy_to)
|
@@ -28,30 +15,27 @@ task :setup do
|
|
28
15
|
execute :ln, "-s -f #{server_conf_dir}/letsencrypt.conf /etc/nginx/letsencrypt/#{fetch(:application)}.conf"
|
29
16
|
execute :ln, "-s -f #{server_conf_dir}/logrotate.conf /etc/logrotate.d/#{fetch(:application)}"
|
30
17
|
within fetch(:deploy_to) do
|
31
|
-
execute :bundle, :install,
|
18
|
+
execute :bundle, :install, '--without development test'
|
32
19
|
execute :mkdir, "-p #{fetch(:deploy_to)}/tmp/pids"
|
33
20
|
if test "[ -f #{fetch(:deploy_to)}/.env ]"
|
34
|
-
|
35
|
-
if test "[ -f #{fetch(:deploy_to)}/db/#{fetch(:application)}.sql ]"
|
36
|
-
execute :psql, "-d #{fetch(:application)}_production", "-f db/#{fetch(:application)}.sql"
|
37
|
-
end
|
38
|
-
execute :rake, 'db:migrate'
|
21
|
+
invoke :create_database_from_sql_file
|
39
22
|
execute :rake, 'assets:precompile'
|
40
23
|
execute :eye, :load, 'Eyefile'
|
41
24
|
execute :eye, :start, fetch(:application)
|
42
|
-
execute :service,
|
25
|
+
execute :service, 'nginx restart'
|
43
26
|
else
|
44
|
-
|
45
|
-
|
46
|
-
warn
|
47
|
-
warn
|
27
|
+
execute :cp, '.env.example.production', '.env'
|
28
|
+
execute "sed -i -e 's/TODO: generate with: rake secret/#{SecureRandom.hex(64)}/g' #{fetch(:deploy_to)}/.env"
|
29
|
+
warn 'TODO: Edit .env and modify your database and smtp settings.'
|
30
|
+
warn 'TODO: Create ssl certificates by running the following command as root: /etc/letsencrypt/generate_letsencrypt.sh'
|
31
|
+
warn 'TODO: Run \'cap ENV setup\' again!'
|
48
32
|
end
|
49
33
|
end
|
50
34
|
end
|
51
35
|
end
|
52
36
|
end
|
53
37
|
|
54
|
-
desc
|
38
|
+
desc 'Remove the application completely from the server'
|
55
39
|
task :remove do
|
56
40
|
on roles(:all) do
|
57
41
|
with fetch(:environment) do
|
@@ -64,31 +48,30 @@ task :remove do
|
|
64
48
|
execute :su_rm, "-f /etc/nginx/conf.d/#{fetch(:application)}.conf"
|
65
49
|
execute :su_rm, "-f /etc/nginx/letsencrypt/#{fetch(:application)}.conf"
|
66
50
|
execute :su_rm, "-f /etc/logrotate.d/#{fetch(:application)}"
|
67
|
-
execute :service,
|
51
|
+
execute :service, 'nginx restart'
|
68
52
|
end
|
69
53
|
end
|
70
54
|
end
|
71
55
|
|
72
|
-
desc
|
56
|
+
desc 'Deploy rails application'
|
73
57
|
task :deploy do
|
74
58
|
on roles(:all) do
|
75
59
|
with fetch(:environment) do
|
76
60
|
within fetch(:deploy_to) do
|
77
|
-
|
78
|
-
execute :git, :reset, '--hard origin/master'
|
61
|
+
invoke :fetch_and_reset_git_repository
|
79
62
|
execute :bundle, :install
|
80
63
|
execute :rake, 'db:migrate'
|
81
64
|
execute :rake, 'assets:precompile'
|
82
65
|
execute :eye, :load, 'Eyefile'
|
83
66
|
execute :eye, :restart, fetch(:application)
|
84
|
-
execute :service,
|
67
|
+
execute :service, 'nginx restart'
|
85
68
|
end
|
86
69
|
end
|
87
70
|
end
|
88
71
|
end
|
89
72
|
|
90
|
-
desc
|
91
|
-
task :
|
73
|
+
desc 'Copy database from the server to the local machine'
|
74
|
+
task :update do
|
92
75
|
on roles(:all) do
|
93
76
|
within fetch(:deploy_to) do
|
94
77
|
execute :pg_dump, "-U deploy --clean #{fetch(:application)}_production > db/#{fetch(:application)}.sql"
|
@@ -97,27 +80,53 @@ task :sync_local do
|
|
97
80
|
end
|
98
81
|
run_locally do
|
99
82
|
execute "psql -d #{fetch(:application)}_development -f db/#{fetch(:application)}.sql"
|
83
|
+
invoke :sync_local_dirs_from_server
|
100
84
|
end
|
101
85
|
end
|
102
86
|
|
103
|
-
desc "Recreate server database from db/#{fetch(:application)}.sql"
|
87
|
+
desc "Recreate server database from db/#{fetch(:application)}.sql and sync local dirs if any"
|
104
88
|
task :reset_server do
|
105
89
|
on roles(:all) do
|
106
90
|
with fetch(:environment) do
|
107
91
|
within fetch(:deploy_to) do
|
108
92
|
execute :eye, :load, 'Eyefile'
|
109
93
|
execute :eye, :stop, fetch(:application)
|
110
|
-
|
111
|
-
execute :git, :reset, '--hard origin/master'
|
94
|
+
invoke :fetch_and_reset_git_repository
|
112
95
|
execute :rake, 'db:drop'
|
113
|
-
|
114
|
-
|
115
|
-
execute :psql, "-d #{fetch(:application)}_production", "-f db/#{fetch(:application)}.sql"
|
116
|
-
end
|
117
|
-
execute :rake, 'db:migrate'
|
96
|
+
invoke :create_database_from_sql_file
|
97
|
+
invoke :sync_local_dirs_to_server
|
118
98
|
execute :eye, :start, fetch(:application)
|
119
|
-
execute :service,
|
99
|
+
execute :service, 'nginx restart'
|
120
100
|
end
|
121
101
|
end
|
122
102
|
end
|
123
103
|
end
|
104
|
+
|
105
|
+
task :sync_local_dirs_to_server do
|
106
|
+
fetch(:sync_dirs, []).each do |sync_dir|
|
107
|
+
run_locally do
|
108
|
+
execute "rsync -avz --delete -e ssh ./#{sync_dir}/ #{fetch(:user)}@#{fetch(:server)}:#{fetch(:deploy_to)}/#{sync_dir}/"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
task :sync_local_dirs_from_server do
|
114
|
+
fetch(:sync_dirs, []).each do |sync_dir|
|
115
|
+
run_locally do
|
116
|
+
execute "rsync -avzm --delete --force -e ssh #{fetch(:user)}@#{fetch(:server)}:#{fetch(:deploy_to)}/#{sync_dir}/ ./#{sync_dir}/"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
task :fetch_and_reset_git_repository do
|
122
|
+
execute :git, :fetch, 'origin'
|
123
|
+
execute :git, :reset, "--hard origin/#{fetch(:deploy_branch, 'master')}"
|
124
|
+
end
|
125
|
+
|
126
|
+
task :create_database_from_sql_file do
|
127
|
+
execute :rake, 'db:create'
|
128
|
+
if test "[ -f #{fetch(:deploy_to)}/db/#{fetch(:application)}.sql ]"
|
129
|
+
execute :psql, "-d #{fetch(:application)}_production", "-f db/#{fetch(:application)}.sql"
|
130
|
+
end
|
131
|
+
execute :rake, 'db:migrate'
|
132
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
task :set_railman_env do
|
2
|
+
set :deploy_to, "/home/deploy/apps/#{fetch(:application)}"
|
3
|
+
set :rbenv_home, '/home/deploy/.rbenv'
|
4
|
+
set :environment, {path: "#{fetch(:rbenv_home)}/shims:#{fetch(:rbenv_home)}/bin:$PATH", rails_env: 'production'}
|
5
|
+
|
6
|
+
SSHKit.config.command_map[:rake] = "#{fetch(:deploy_to)}/bin/rake"
|
7
|
+
%w(ln service start restart stop status).each do |cmd|
|
8
|
+
SSHKit.config.command_map[cmd.to_sym] = "sudo #{cmd}"
|
9
|
+
end
|
10
|
+
SSHKit.config.command_map[:eye] = "#{fetch(:rbenv_home)}/shims/eye"
|
11
|
+
SSHKit.config.command_map[:su_rm] = 'sudo rm'
|
12
|
+
end
|
13
|
+
|
14
|
+
before :setup, :set_railman_env
|
15
|
+
before :deploy, :set_railman_env
|
16
|
+
before :update, :set_railman_env
|
17
|
+
before :reset_server, :set_railman_env
|
18
|
+
before :remove, :set_railman_env
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: railman-deployment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Jancev
|
@@ -142,10 +142,10 @@ files:
|
|
142
142
|
- lib/railman-deployment.rb
|
143
143
|
- lib/railman-deployment/version.rb
|
144
144
|
- lib/railman/deployment.rb
|
145
|
-
- lib/railman/deployment/
|
145
|
+
- lib/railman/deployment/set_railman_env.rb
|
146
146
|
- lib/railman/deployment/tasks.rb
|
147
147
|
- lib/railman/tasks/deployment.rake
|
148
|
-
- lib/railman/tasks/
|
148
|
+
- lib/railman/tasks/set_railman_env.rake
|
149
149
|
- railman-deployment.gemspec
|
150
150
|
homepage: https://github.com/igorj/railman-deployment
|
151
151
|
licenses:
|
@@ -1 +0,0 @@
|
|
1
|
-
load File.expand_path('../../tasks/hooks.rake', __FILE__)
|