railman-deployment 1.1.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3e2c7491fb51d84d9de0b91a04abc195bf3eb2a3
4
- data.tar.gz: '0392f78007317b1b7d5a2c0bc15388b83ed8a697'
2
+ SHA256:
3
+ metadata.gz: 8f75058ce67a79a21f24384da8681a2a0aedea32eaef8fb0d7a7a5ada401e75d
4
+ data.tar.gz: 3af5c61e95ba8340191da95346a476f6437b33692df81ea6ce5135bc914e3a53
5
5
  SHA512:
6
- metadata.gz: c24d68a0905af04589ca2769f69735e5763afd1f0009d9aa868b42b3cd25c96f67a334ff492a7acb558c908f0bf70deacf2add988239f7e45c1fc9bfe961c6a5
7
- data.tar.gz: c904cfb7cbcdd429dcc1cc8216de71eac5bbc3feecd058f35eed0766edd164d3a3d96974d5369c111a6ad184e3d20d4ff11e2f52b6b8016db57e61ec0b148f37
6
+ metadata.gz: 052d41d13308677118eeef4ebadc1542613a9b541c286aa9fe7bb866bbab7ec234dc52520fa981a42bc8ae50867747825e47e3755f81ca4abacc04125aa35725
7
+ data.tar.gz: 18f77e9335847bca0a8fd6fff4af88a2fd5651060351b556bdb2a2ce2a499b6cbea9763a97d7d00731dd7af36af3666aeefe2a4ceb682b161bc315bd384a2d66
@@ -1 +1 @@
1
- 2.3.3
1
+ 2.5.0
@@ -1,3 +1,3 @@
1
1
  module RailmanDeployment
2
- VERSION = '1.1.4'
2
+ VERSION = '2.0.0'
3
3
  end
@@ -2,7 +2,6 @@ desc 'Setup rails application for the first time on a server'
2
2
  task :setup do
3
3
  on roles(:all) do
4
4
  with fetch(:environment) do
5
- # setup backend application
6
5
  if test "[ -d #{fetch(:deploy_to)} ]"
7
6
  invoke :fetch_and_reset_git_repository
8
7
  else
@@ -10,79 +9,63 @@ task :setup do
10
9
  invoke :sync_local_dirs_to_server
11
10
  end
12
11
  server_conf_dir = "#{fetch(:deploy_to)}/config/server"
13
- execute :cp, "#{server_conf_dir}/nginx.conf /etc/nginx/sites-available/#{fetch(:domain)}"
14
- execute :ln, "-s -f /etc/nginx/sites-available/#{fetch(:domain)} /etc/nginx/sites-enabled/"
15
- execute :ln, "-s -f #{server_conf_dir}/logrotate.conf /etc/logrotate.d/#{fetch(:application)}"
12
+ execute :su_ln, "-s -f #{server_conf_dir}/puma.service /lib/systemd/system/#{fetch(:application)}.service"
13
+ execute :su_ln, "-s -f #{server_conf_dir}/sidekiq.service /lib/systemd/system/#{fetch(:application)}_sidekiq.service"
14
+ execute :su_ln, "-s -f #{server_conf_dir}/logrotate.conf /etc/logrotate.d/#{fetch(:application)}"
16
15
  within fetch(:deploy_to) do
16
+ upload! './config/master.key', "#{fetch(:deploy_to)}/config/master.key"
17
17
  execute :bundle, :install, '--without development test'
18
- execute :mkdir, "-p #{fetch(:deploy_to)}/tmp/pids"
19
- if test "[ -f #{fetch(:deploy_to)}/.env ]"
20
- invoke :create_database_from_sql_file
21
- execute :eye, :load, 'Eyefile'
22
- execute :eye, :start, fetch(:application)
23
- execute :service, 'nginx restart'
24
- warn "TODO: Run certbot--nginx -d #{fetch(:domain)} on the server as root to create a certificate"
25
- else
26
- execute "cp #{fetch(:deploy_to)}/.env.example.production #{fetch(:deploy_to)}/.env"
27
- execute "sed -i -e 's/TODO: generate with: rake secret/#{SecureRandom.hex(64)}/g' #{fetch(:deploy_to)}/.env"
28
- warn 'TODO: Edit .env and modify your database and smtp settings.'
29
- warn 'TODO: Run \'cap ENV setup\' again!'
30
- end
31
- end
32
- end
33
- end
34
- end
35
-
36
- desc 'Setup spa application for the first time on a server'
37
- task :setup_spa do
38
- on roles(:all) do
39
- server_conf_dir = "#{fetch(:deploy_to)}/config/server"
40
- if fetch(:spa_application)
41
- if test "[ -d #{fetch(:deploy_spa_to)} ]"
42
- invoke :fetch_and_reset_spa_git_repository
43
- else
44
- execute :git, :clone, fetch(:spa_repo_url), fetch(:deploy_spa_to)
45
- end
46
-
47
- within fetch(:deploy_spa_to) do
48
- execute :mkdir, "-p #{fetch(:deploy_spa_to)}/public"
49
- execute :yarn
50
- execute :yarn, 'run build'
51
- execute "rsync -avz --delete #{fetch(:deploy_spa_to)}/dist/ #{fetch(:deploy_spa_to)}/public/"
52
- execute :cp, "#{server_conf_dir}/nginx_spa.conf /etc/nginx/sites-available/#{fetch(:spa_domain)}"
53
- execute :ln, "-s -f /etc/nginx/sites-available/#{fetch(:spa_domain)} /etc/nginx/sites-enabled/"
54
- execute :service, 'nginx restart'
55
- warn "TODO: Run certbot--nginx -d #{fetch(:spa_domain)} on the server as root to create a certificate"
18
+ invoke :create_database_from_sql_file
19
+ execute :rake, 'assets:precompile'
20
+ execute :systemctl, :start, fetch(:application)
21
+ execute :systemctl, :start, "#{fetch(:application)}_sidekiq"
22
+ execute :systemctl, :enable, fetch(:application)
23
+ execute :systemctl, :enable, "#{fetch(:application)}_sidekiq"
24
+ # copy temporary simple nginx.conf only for getting letsencrypt certificate
25
+ nginx_conf = File.read(File.join(File.dirname(__FILE__), 'nginx.conf'))
26
+ nginx_conf.gsub!('DOMAINS', fetch(:domains).join(' '))
27
+ nginx_conf.gsub!('APPLICATION', fetch(:application))
28
+ upload! StringIO.new(nginx_conf), "/etc/nginx/conf.d/#{fetch(:application)}.conf"
29
+ execute :systemctl, :restart, :nginx
30
+ execute :certbot, "certonly --webroot -w /home/deploy/apps/#{fetch(:application)}/public #{fetch(:domains).collect { |d| '-d ' + d }.join(' ')} -n --agree-tos -m #{fetch(:certbot_email)} --deploy-hook 'systemctl reload nginx'"
31
+ # remove temporary nginx.conf and link config/server/nginx.conf to /etc/nginx/conf.d
32
+ execute :su_rm, "/etc/nginx/conf.d/#{fetch(:application)}.conf"
33
+ execute :su_ln, "-s -f #{server_conf_dir}/nginx.conf /etc/nginx/conf.d/#{fetch(:application)}.conf"
34
+ execute :systemctl, :restart, :nginx
56
35
  end
57
36
  end
58
37
  end
59
38
  end
60
39
 
40
+ # todo
61
41
  desc 'Remove the application completely from the server'
62
42
  task :remove do
63
43
  on roles(:all) do
64
44
  with fetch(:environment) do
45
+ # dropt the database and remove the application directory from /home/deploy/apps
65
46
  within fetch(:deploy_to) do
66
- execute :eye, :load, 'Eyefile'
67
- execute :eye, :stop, fetch(:application)
68
47
  execute :rake, 'db:drop'
69
48
  execute :su_rm, "-rf #{fetch(:deploy_to)}"
70
49
  end if test "[ -d #{fetch(:deploy_to)} ]"
71
- execute :su_rm, "-f /etc/nginx/sites-enabled/#{fetch(:domain)}"
72
- execute :su_rm, "-f /etc/nginx/sites-available/#{fetch(:domain)}"
50
+ # stop, disable and remove systemd service files
51
+ execute :systemctl, :stop, fetch(:application)
52
+ execute :systemctl, :stop, "#{fetch(:application)}_sidekiq"
53
+ execute :systemctl, :disable, fetch(:application)
54
+ execute :systemctl, :disable, "#{fetch(:application)}_sidekiq"
55
+ execute :su_rm, "-f /lib/systemd/system/#{fetch(:application)}.service"
56
+ execute :su_rm, "-f /lib/systemd/system/#{fetch(:application)}_sidekiq.service"
57
+ # remove application nginx configuration
58
+ execute :su_rm, "-f /etc/nginx/conf.d/#{fetch(:application)}"
59
+ execute :systemctl, :restart, :nginx
60
+ # remove logrotate configuration
73
61
  execute :su_rm, "-f /etc/logrotate.d/#{fetch(:application)}"
74
- if test "[ -d #{fetch(:deploy_spa_to)} ]"
75
- execute :su_rm, "-rf #{fetch(:deploy_spa_to)}"
76
- execute :su_rm, "-f /etc/nginx/sites-enabled/#{fetch(:spa_domain)}"
77
- execute :su_rm, "-f /etc/nginx/sites-available/#{fetch(:spa_domain)}"
78
- end
79
- execute :service, 'nginx restart'
80
- warn 'TODO: Run certbot--nginx remove on the server as root to remove the certificate'
62
+ # todo remove letsencrypt certificates and renew cron job
81
63
  end
82
64
  end
83
65
  end
84
66
 
85
- desc 'Deploy rails application (and spa if configured)'
67
+ # OK!
68
+ desc 'Deploy rails application'
86
69
  task :deploy do
87
70
  on roles(:all) do
88
71
  with fetch(:environment) do
@@ -90,35 +73,16 @@ task :deploy do
90
73
  invoke :fetch_and_reset_git_repository
91
74
  execute :bundle, :install
92
75
  execute :rake, 'db:migrate'
93
- execute :eye, :load, 'Eyefile'
94
- execute :eye, :restart, fetch(:application)
95
- execute :service, 'nginx restart'
76
+ execute :rake, 'assets:precompile'
77
+ execute :systemctl, :restart, fetch(:application)
78
+ execute :systemctl, :restart, "#{fetch(:application)}_sidekiq"
79
+ execute :systemctl, :restart, :nginx
96
80
  end
97
81
  end
98
82
  end
99
83
  end
100
84
 
101
- desc 'Deploy SPA application'
102
- task :deploy_spa do
103
- on roles(:all) do
104
- with fetch(:environment) do
105
- within fetch(:deploy_spa_to) do
106
- invoke :fetch_and_reset_spa_git_repository
107
- execute :yarn
108
- execute :yarn, 'run build'
109
- execute "rsync -avz --delete #{fetch(:deploy_spa_to)}/dist/ #{fetch(:deploy_spa_to)}/public/"
110
- execute :service, 'nginx restart'
111
- end
112
- end
113
- end
114
- end
115
-
116
- desc 'Deploy both the rails application and the spa application'
117
- task :deploy_all do
118
- invoke :deploy
119
- invoke :deploy_spa
120
- end
121
-
85
+ # OK!
122
86
  desc 'Copy database from the server to the local machine'
123
87
  task :update do
124
88
  on roles(:all) do
@@ -133,25 +97,27 @@ task :update do
133
97
  end
134
98
  end
135
99
 
100
+ # OK!
136
101
  desc "Recreate server database from db/#{fetch(:application)}.sql and sync local dirs if any"
137
102
  task :reset_server do
138
103
  on roles(:all) do
139
104
  with fetch(:environment) do
140
105
  within fetch(:deploy_to) do
141
- execute :eye, :load, 'Eyefile'
142
- execute :eye, :stop, fetch(:application)
143
- sleep 6 # seconds
106
+ execute :systemctl, :stop, fetch(:application)
107
+ execute :systemctl, :stop, "#{fetch(:application)}_sidekiq"
144
108
  invoke :fetch_and_reset_git_repository
145
109
  execute :rake, 'db:drop'
146
110
  invoke :create_database_from_sql_file
147
111
  invoke :sync_local_dirs_to_server
148
- execute :eye, :start, fetch(:application)
149
- execute :service, 'nginx restart'
112
+ execute :systemctl, :restart, fetch(:application)
113
+ execute :systemctl, :restart, "#{fetch(:application)}_sidekiq"
114
+ execute :systemctl, :restart, :nginx
150
115
  end
151
116
  end
152
117
  end
153
118
  end
154
119
 
120
+ # OK!
155
121
  task :sync_local_dirs_to_server do
156
122
  on roles(:all) do
157
123
  fetch(:sync_dirs, []).each do |sync_dir|
@@ -162,6 +128,7 @@ task :sync_local_dirs_to_server do
162
128
  end
163
129
  end
164
130
 
131
+ # OK!
165
132
  task :sync_local_dirs_from_server do
166
133
  on roles(:all) do
167
134
  fetch(:sync_dirs, []).each do |sync_dir|
@@ -172,6 +139,7 @@ task :sync_local_dirs_from_server do
172
139
  end
173
140
  end
174
141
 
142
+ # OK!
175
143
  task :fetch_and_reset_git_repository do
176
144
  on roles(:all) do
177
145
  with fetch(:environment) do
@@ -183,26 +151,18 @@ task :fetch_and_reset_git_repository do
183
151
  end
184
152
  end
185
153
 
186
- task :fetch_and_reset_spa_git_repository do
187
- on roles(:all) do
188
- with fetch(:environment) do
189
- within fetch(:deploy_spa_to) do
190
- execute :git, :fetch, 'origin'
191
- execute :git, :reset, "--hard origin/#{fetch(:spa_deploy_branch, 'master')}"
192
- end
193
- end
194
- end
195
- end
196
-
154
+ # OK!
197
155
  task :create_database_from_sql_file do
198
156
  on roles(:all) do
199
157
  with fetch(:environment) do
200
158
  within fetch(:deploy_to) do
201
159
  execute :rake, 'db:create'
160
+ execute :rake, 'db:migrate'
161
+ execute :rake, 'db:seed'
202
162
  if test "[ -f #{fetch(:deploy_to)}/db/#{fetch(:application)}.sql ]"
203
163
  execute :psql, "-d #{fetch(:application)}_production", "-f db/#{fetch(:application)}.sql"
164
+ execute :rake, 'db:migrate'
204
165
  end
205
- execute :rake, 'db:migrate'
206
166
  end
207
167
  end
208
168
  end
@@ -0,0 +1,12 @@
1
+ server {
2
+ listen 80;
3
+ listen [::]:80;
4
+ server_name DOMAINS;
5
+
6
+ root /home/deploy/apps/APPLICATION/public;
7
+ index index.html;
8
+
9
+ location / {
10
+ try_files $uri $uri/ =404;
11
+ }
12
+ }
@@ -1,24 +1,20 @@
1
1
  task :set_railman_env do
2
2
  set :deploy_to, "/home/deploy/apps/#{fetch(:application)}"
3
- if fetch(:spa_application)
4
- set :deploy_spa_to, "/home/deploy/sites/#{fetch(:spa_application)}"
5
- end
6
- set :rbenv_home, '/home/deploy/.rbenv'
7
- set :environment, {path: "#{fetch(:rbenv_home)}/shims:#{fetch(:rbenv_home)}/bin:$PATH", rails_env: 'production'}
3
+ set :environment, { rails_env: 'production'}
4
+ set :chruby_prefix, "/usr/local/bin/chruby-exec #{fetch(:chruby_ruby)} -- RAILS_ENV=production "
8
5
 
9
- SSHKit.config.command_map[:rake] = "#{fetch(:deploy_to)}/bin/rake"
10
- %w(ln cp service start restart stop status certbot).each do |cmd|
6
+ SSHKit.config.command_map[:rake] = "#{fetch(:chruby_prefix)} #{fetch(:deploy_to)}/bin/rake"
7
+ SSHKit.config.command_map[:bundle] = "#{fetch(:chruby_prefix)} #{fetch(:deploy_to)}/bin/bundle"
8
+ %w(systemctl certbot).each do |cmd|
11
9
  SSHKit.config.command_map[cmd.to_sym] = "sudo #{cmd}"
12
10
  end
13
- SSHKit.config.command_map[:eye] = "#{fetch(:rbenv_home)}/shims/eye"
14
11
  SSHKit.config.command_map[:su_rm] = 'sudo rm'
12
+ SSHKit.config.command_map[:su_ln] = 'sudo ln'
13
+ SSHKit.config.command_map[:su_cp] = 'sudo cp'
15
14
  end
16
15
 
17
16
  before :setup, :set_railman_env
18
- before :setup_spa, :set_railman_env
19
17
  before :deploy, :set_railman_env
20
- before :deploy_spa, :set_railman_env
21
- before :deploy_all, :set_railman_env
22
18
  before :update, :set_railman_env
23
19
  before :reset_server, :set_railman_env
24
20
  before :remove, :set_railman_env
@@ -0,0 +1,4 @@
1
+ s = File.read(File.join(File.dirname(__FILE__), 'nginx.conf'))
2
+ s.gsub!('DOMAINS', 'faluninfo.ba www.faluninfo.ba')
3
+ s.gsub!('APPLICATION', 'faluninfo')
4
+ puts s
@@ -15,14 +15,13 @@ Gem::Specification.new do |spec|
15
15
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^test/}) }
16
16
  spec.require_paths = ["lib"]
17
17
 
18
- spec.add_development_dependency "bundler", "~> 1.11"
19
- spec.add_development_dependency "rake", "~> 10.0"
20
- spec.add_development_dependency "minitest", "~> 5.8"
21
- spec.add_development_dependency "minitest-reporters", "~> 1.1"
18
+ spec.add_development_dependency "bundler", "~> 1.16.1"
19
+ spec.add_development_dependency "rake", "~> 12.3.0"
20
+ spec.add_development_dependency "minitest", "~> 5.11.3"
21
+ spec.add_development_dependency "minitest-reporters", "~> 1.1.19"
22
22
  spec.add_development_dependency "gem-release", "~> 0.7"
23
- spec.add_development_dependency "geminabox", "~> 0.13"
23
+ spec.add_development_dependency "geminabox", "~> 0.13.15"
24
24
  spec.add_development_dependency "coveralls"
25
25
 
26
26
  spec.add_dependency "capistrano", "~> 3.6.1"
27
- spec.add_dependency "eye", "~> 0.9.2"
28
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railman-deployment
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Jancev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-17 00:00:00.000000000 Z
11
+ date: 2018-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.11'
19
+ version: 1.16.1
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.11'
26
+ version: 1.16.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: 12.3.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: 12.3.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '5.8'
47
+ version: 5.11.3
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '5.8'
54
+ version: 5.11.3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: minitest-reporters
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.1'
61
+ version: 1.1.19
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.1'
68
+ version: 1.1.19
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: gem-release
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.13'
89
+ version: 0.13.15
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0.13'
96
+ version: 0.13.15
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: coveralls
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -122,20 +122,6 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: 3.6.1
125
- - !ruby/object:Gem::Dependency
126
- name: eye
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: 0.9.2
132
- type: :runtime
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: 0.9.2
139
125
  description: railman-deployment gem adds capistrano tasks for automated deployment
140
126
  of rails applications generated by railman
141
127
  email:
@@ -162,7 +148,9 @@ files:
162
148
  - lib/railman/deployment/set_railman_env.rb
163
149
  - lib/railman/deployment/tasks.rb
164
150
  - lib/railman/tasks/deployment.rake
151
+ - lib/railman/tasks/nginx.conf
165
152
  - lib/railman/tasks/set_railman_env.rake
153
+ - lib/railman/tasks/test.rb
166
154
  - railman-deployment.gemspec
167
155
  homepage: https://github.com/igorj/railman-deployment
168
156
  licenses:
@@ -184,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
172
  version: '0'
185
173
  requirements: []
186
174
  rubyforge_project:
187
- rubygems_version: 2.5.2
175
+ rubygems_version: 2.7.3
188
176
  signing_key:
189
177
  specification_version: 4
190
178
  summary: Capistrano tasks for railman-generated rails applications