capistrano-django-systemd 3.5.6

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1f1b2c23ad7c1b2c15f5a37d1217b5b63cb6b50c
4
+ data.tar.gz: 136eed69412a6b1377762919124e7ebcc6000987
5
+ SHA512:
6
+ metadata.gz: 45fe75578b71f673c154522dd8497a2aba6f70cd0131ed16a7d9e72ab8b110e129948128caf7eee65fd84166a67916026fa29f6f2a44e1a6f1aaeb4f26762ea4
7
+ data.tar.gz: 9fe934f95aa7ded1f45ebf30b9c2151e521c94968c26ee338e26acdc6d736d470ec392dd1d87e670b0997dee3e082998cc69f4352c7692cf625a76a789344059
@@ -0,0 +1,312 @@
1
+ after 'deploy:updating', 'python:create_virtualenv'
2
+
3
+ namespace :deploy do
4
+
5
+ %w[start stop restart status].each do |command|
6
+ desc 'Restart application'
7
+ task command do
8
+ on roles(:web) do
9
+ if fetch(:nginx)
10
+ invoke 'deploy:nginx_restart'
11
+ else
12
+ on roles(:web) do |h|
13
+ if fetch(:systemd_unit)
14
+ execute "sudo systemctl #{command} #{fetch(:systemd_unit)}.socket"
15
+ execute "sudo systemctl #{command} #{fetch(:systemd_unit)}"
16
+ else
17
+ execute "sudo apache2ctl graceful"
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ task :nginx_restart do
26
+ on roles(:web) do |h|
27
+ within release_path do
28
+ pid_file = "#{releases_path}/gunicorn.pid"
29
+ if test "[ -e #{pid_file} ]"
30
+ execute "kill `cat #{pid_file}`"
31
+ end
32
+ execute "virtualenv/bin/gunicorn", "#{fetch(:wsgi_file)}:application", '-c=gunicorn_config.py', "--pid=#{pid_file}"
33
+ end
34
+ end
35
+ end
36
+
37
+
38
+ end
39
+
40
+
41
+ namespace :python do
42
+
43
+ def virtualenv_path
44
+ File.join(
45
+ fetch(:shared_virtualenv) ? shared_path : release_path, "virtualenv"
46
+ )
47
+ end
48
+
49
+ desc "Create a python virtualenv"
50
+ #Rake::Task["create_virtualenv"].clear_actions # this prevents the original task from being run
51
+ task :create_virtualenv do
52
+ on roles(:all) do |h|
53
+ execute "virtualenv -p python3 #{virtualenv_path}"
54
+ execute "sed -i '3i source #{fetch(:deploy_to)}/.env' #{release_path}/virtualenv/bin/activate"
55
+ execute "sed -i '4i export $(cut -d= -f1 #{fetch(:deploy_to)}/.env)' #{release_path}/virtualenv/bin/activate"
56
+ execute "#{virtualenv_path}/bin/pip install -r #{release_path}/#{fetch(:pip_requirements)}"
57
+ if fetch(:shared_virtualenv)
58
+ execute :ln, "-s", virtualenv_path, File.join(release_path, 'virtualenv')
59
+ end
60
+ end
61
+
62
+ if fetch(:npm_tasks)
63
+ invoke 'nodejs:npm'
64
+ end
65
+ if fetch(:flask)
66
+ invoke 'flask:setup'
67
+ else
68
+ invoke 'django:setup'
69
+ end
70
+ end
71
+
72
+ desc "Set things up after the virtualenv is ready"
73
+ task :post_virtualenv do
74
+ if fetch(:npm_tasks)
75
+ invoke 'nodejs:npm'
76
+ end
77
+ if fetch(:flask)
78
+ invoke 'flask:setup'
79
+ else
80
+ invoke 'django:setup'
81
+ end
82
+ end
83
+
84
+ end
85
+
86
+ after 'python:create_virtualenv', 'python:post_virtualenv'
87
+
88
+ namespace :flask do
89
+
90
+ task :setup do
91
+ on roles(:web) do |h|
92
+ execute "ln -s #{release_path}/settings/#{fetch(:settings_file)}.py #{release_path}/settings/deployed.py"
93
+ execute "ln -sf #{release_path}/wsgi/wsgi.py #{release_path}/wsgi/live.wsgi"
94
+ end
95
+ end
96
+
97
+ end
98
+
99
+ namespace :django do
100
+
101
+ def django(args, flags="", run_on=:all)
102
+ on roles(run_on) do |h|
103
+ manage_path = File.join(release_path, fetch(:django_project_dir) || '', 'manage.py')
104
+ execute "source #{release_path}/virtualenv/bin/activate && #{release_path}/virtualenv/bin/python #{manage_path} #{fetch(:django_settings)} #{args} #{flags}"
105
+ end
106
+ end
107
+
108
+ after 'deploy:restart', 'django:restart_celery'
109
+
110
+ desc "Setup Django environment"
111
+ task :setup do
112
+ if fetch(:django_compressor)
113
+ invoke 'django:compress'
114
+ end
115
+ invoke 'django:compilemessages'
116
+ invoke 'django:collectstatic'
117
+ invoke 'django:symlink_settings'
118
+ if !fetch(:nginx)
119
+ invoke 'django:symlink_wsgi'
120
+ end
121
+ invoke 'django:migrate'
122
+ end
123
+
124
+ desc "Compile Messages"
125
+ task :compilemessages do
126
+ if fetch :compilemessages
127
+ django("compilemessages")
128
+ end
129
+ end
130
+
131
+ desc "Restart Celery"
132
+ task :restart_celery do
133
+ if fetch(:celery_name)
134
+ invoke 'django:restart_celeryd'
135
+ invoke 'django:restart_celerybeat'
136
+ end
137
+ if fetch(:celery_names)
138
+ invoke 'django:restart_named_celery_processes'
139
+ end
140
+ end
141
+
142
+ desc "Restart Celeryd"
143
+ task :restart_celeryd do
144
+ on roles(:jobs) do
145
+ execute "sudo service celeryd-#{fetch(:celery_name)} restart"
146
+ end
147
+ end
148
+
149
+ desc "Restart Celerybeat"
150
+ task :restart_celerybeat do
151
+ on roles(:jobs) do
152
+ execute "sudo service celerybeat-#{fetch(:celery_name)} restart"
153
+ end
154
+ end
155
+
156
+ desc "Restart named celery processes"
157
+ task :restart_named_celery_processes do
158
+ on roles(:jobs) do
159
+ fetch(:celery_names).each { | celery_name, celery_beat |
160
+ execute "sudo service celeryd-#{celery_name} restart"
161
+ if celery_beat
162
+ execute "sudo service celerybeat-#{celery_name} restart"
163
+ end
164
+ }
165
+ end
166
+ end
167
+
168
+ desc "Run django-compressor"
169
+ task :compress do
170
+ django("compress")
171
+ end
172
+
173
+ desc "Run django's collectstatic"
174
+ task :collectstatic do
175
+ if fetch(:create_s3_bucket)
176
+ invoke 's3:create_bucket'
177
+ on roles(:web) do
178
+ django("collectstatic", "-i *.coffee -i *.less -i node_modules/* -i bower_components/* --noinput --clear")
179
+ end
180
+ else
181
+ django("collectstatic", "-i *.coffee -i *.less -i node_modules/* -i bower_components/* --noinput")
182
+ end
183
+
184
+ end
185
+
186
+ desc "Symlink django settings to deployed.py"
187
+ task :symlink_settings do
188
+ settings_path = File.join(release_path, fetch(:django_settings_dir))
189
+ on roles(:all) do
190
+ execute "ln -s #{settings_path}/#{fetch(:django_settings)}.py #{settings_path}/deployed.py"
191
+ end
192
+ end
193
+
194
+ desc "Symlink wsgi script to live.wsgi"
195
+ task :symlink_wsgi do
196
+ on roles(:web) do
197
+ wsgi_path = File.join(release_path, fetch(:wsgi_path, 'wsgi'))
198
+ wsgi_file_name = fetch(:wsgi_file_name, 'main.wsgi')
199
+ execute "ln -sf #{wsgi_path}/#{wsgi_file_name} #{wsgi_path}/live.wsgi"
200
+ end
201
+ end
202
+
203
+ desc "Run django migrations"
204
+ task :migrate do
205
+ if fetch(:multidb)
206
+ django("sync_all", '--noinput', run_on=:web)
207
+ else
208
+ django("migrate", "--noinput", run_on=:web)
209
+ end
210
+ end
211
+ end
212
+
213
+ namespace :nodejs do
214
+
215
+ desc 'Install node modules'
216
+ task :npm_install do
217
+ on roles(:web) do
218
+ path = fetch(:npm_path) ? File.join(release_path, fetch(:npm_path)) : release_path
219
+ within path do
220
+ execute 'npm', 'install', fetch(:npm_install_production, '--production')
221
+ end
222
+ end
223
+ end
224
+
225
+ desc 'Run npm tasks'
226
+ task :npm do
227
+ invoke 'nodejs:npm_install'
228
+ on roles(:web) do
229
+ path = fetch(:npm_path) ? File.join(release_path, fetch(:npm_path)) : release_path
230
+ within path do
231
+ fetch(:npm_tasks).each do |task, args|
232
+ execute "./node_modules/.bin/#{task}", args
233
+ end
234
+ end
235
+ end
236
+ end
237
+
238
+ end
239
+
240
+
241
+ before 'deploy:cleanup', 's3:cleanup'
242
+
243
+ namespace :s3 do
244
+
245
+ desc 'Clean up old s3 buckets'
246
+ task :cleanup do
247
+ if fetch(:create_s3_bucket)
248
+ on roles(:web) do
249
+ releases = capture(:ls, '-xtr', releases_path).split
250
+ if releases.count >= fetch(:keep_releases)
251
+ directories = releases.last(fetch(:keep_releases))
252
+ require 'fog'
253
+ storage = Fog::Storage.new({
254
+ aws_access_key_id: fetch(:aws_access_key),
255
+ aws_secret_access_key: fetch(:aws_secret_key),
256
+ provider: "AWS"
257
+ })
258
+ buckets = storage.directories.all.select { |b| b.key.start_with? fetch(:s3_bucket_prefix) }
259
+ buckets = buckets.select { |b| not directories.include?(b.key.split('-').last) }
260
+ buckets.each do |old_bucket|
261
+ files = old_bucket.files.map{ |file| file.key }
262
+ storage.delete_multiple_objects(old_bucket.key, files) unless files.empty?
263
+ storage.delete_bucket(old_bucket.key)
264
+ end
265
+ end
266
+ end
267
+ end
268
+ end
269
+
270
+ desc 'Create a new bucket in s3 to deploy static files to'
271
+ task :create_bucket do
272
+ settings_path = File.join(release_path, fetch(:django_settings_dir))
273
+ s3_settings_path = File.join(settings_path, 's3_settings.py')
274
+ bucket_name = "#{fetch(:s3_bucket_prefix)}-#{asset_timestamp.sub('.', '')}"
275
+
276
+ on roles(:all) do
277
+ execute %Q|echo "STATIC_URL = 'https://s3.amazonaws.com/#{bucket_name}/'" > #{s3_settings_path}|
278
+ execute %Q|echo "AWS_ACCESS_KEY_ID = '#{fetch(:aws_access_key)}'" >> #{s3_settings_path}|
279
+ execute %Q|echo "AWS_SECRET_ACCESS_KEY = '#{fetch(:aws_secret_key)}'" >> #{s3_settings_path}|
280
+ execute %Q|echo "AWS_STORAGE_BUCKET_NAME = '#{bucket_name}'" >> #{s3_settings_path}|
281
+ execute %Q|echo 'from .s3_settings import *' >> #{settings_path}/#{fetch(:django_settings)}.py|
282
+ execute %Q|echo 'STATICFILES_STORAGE = "storages.backends.s3boto.S3BotoStorage"' >> #{settings_path}/#{fetch(:django_settings)}.py|
283
+ end
284
+
285
+ require 'fog'
286
+ storage = Fog::Storage.new({
287
+ aws_access_key_id: fetch(:aws_access_key),
288
+ aws_secret_access_key: fetch(:aws_secret_key),
289
+ provider: "AWS"
290
+ })
291
+ storage.put_bucket(bucket_name)
292
+ storage.put_bucket_policy(bucket_name, {
293
+ 'Statement' => [{
294
+ 'Sid' => 'AddPerm',
295
+ 'Effect' => 'Allow',
296
+ 'Principal' => '*',
297
+ 'Action' => ['s3:GetObject'],
298
+ 'Resource' => ["arn:aws:s3:::#{bucket_name}/*"]
299
+ }]
300
+ })
301
+ storage.put_bucket_cors(bucket_name, {
302
+ "CORSConfiguration" => [{
303
+ "AllowedOrigin" => ["*"],
304
+ "AllowedHeader" => ["*"],
305
+ "AllowedMethod" => ["GET"],
306
+ "MaxAgeSeconds" => 3000
307
+ }]
308
+ })
309
+
310
+ end
311
+
312
+ end
File without changes
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-django-systemd
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.5.6
5
+ platform: ruby
6
+ authors:
7
+ - Matthew J. Morrison & adapted by Augusto Carvalho
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3'
27
+ description: capistrano-django-systemd provides a solid basis for common django deployment
28
+ email: augusto.unit@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/capistrano/django.rb
34
+ - lib/django_capistrano.rb
35
+ homepage: https://github.com/augustocarvalho/capistrano-django
36
+ licenses: []
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project:
54
+ rubygems_version: 2.6.14.1
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: capistrano-django-systemd - Welcome to easy deployment with Ruby over SSH
58
+ for Django/Python using Gunicorn
59
+ test_files: []