capistrano-foreman_export 0.0.2
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +81 -0
- data/Rakefile +1 -0
- data/capistrano-foreman_export.gemspec +25 -0
- data/lib/capistrano-foreman_export.rb +0 -0
- data/lib/capistrano/foreman_export.rb +1 -0
- data/lib/capistrano/foreman_export/backend.rb +1 -0
- data/lib/capistrano/foreman_export/backend/supervisord.rb +46 -0
- data/lib/capistrano/foreman_export/version.rb +5 -0
- data/lib/capistrano/tasks/foreman.cap +77 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ef81705c7a150367ed8dc5ec5cdc348c189bb8e3
|
4
|
+
data.tar.gz: 4c17528f1861a2987a22e5c39d223cef11f7c95b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9ab0eed418a5fb34d6a78e3d02006db6642e437d9c64cae41638eb1779e7302adec2f13c2fc3d48d0fa39c58110b4b396bd182238eedd481ec20df79b544507f
|
7
|
+
data.tar.gz: ef50c02950ee766bdd60212ebdc8377257be3d0f795975df78c7933ee1851b70e8f66a000cbe576f10a9ec3306f59cb0d92abab7ef16184b6fa639b6b000f357
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Katsuma Ito
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# Capistrano::ForemanExport
|
2
|
+
|
3
|
+
Capistrano task for foreman. Supervisord is supported.
|
4
|
+
Export supervisord configuration from Procfile using `foreman export`.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'capistrano-foreman_export'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install capistrano-foreman_export
|
19
|
+
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Add this line to your `Capfile`:
|
24
|
+
|
25
|
+
require 'capistrano/foreman_export'
|
26
|
+
|
27
|
+
If you want to restart the application after deploy, add this line to your `config/deploy.rb`:
|
28
|
+
|
29
|
+
after 'deploy', 'foreman:export'
|
30
|
+
after 'deploy', 'foreman:restart'
|
31
|
+
|
32
|
+
Configurable options:
|
33
|
+
|
34
|
+
set :foreman_backend, Capistrano::ForemanExport::Backend::Supervisord
|
35
|
+
set :foreman_roles, :app
|
36
|
+
set :foreman_port, 5000
|
37
|
+
set :foreman_output, '/etc/supervisor.d'
|
38
|
+
set :foreman_root, -> { release_path }
|
39
|
+
set :foreman_app, -> { fetch(:application) }
|
40
|
+
set :foreman_procfile, -> { release_path.join('Procfile') }
|
41
|
+
set :foreman_log, -> { release_path.join('log') }
|
42
|
+
set :foreman_user, 'nginx'
|
43
|
+
set :foreman_env_variables, { RAILS_ENV: 'development', FOO: 'Bar' }
|
44
|
+
|
45
|
+
This would be:
|
46
|
+
|
47
|
+
$ cat /my_app/shared/RUNTIME_ENV
|
48
|
+
RAILS_ENV=development
|
49
|
+
FOO=Bar
|
50
|
+
|
51
|
+
$ bundle exec foreman export supervisord /etc/supervisor.d \
|
52
|
+
--port 5000 \
|
53
|
+
--root /my_app/releases/201409081122 \
|
54
|
+
--app my_app \
|
55
|
+
--procfile /my_app/releases/201409081122/Procfile \
|
56
|
+
--log /my_app/releases/201409081122/log \
|
57
|
+
--env /my_app/shared/RUNTIME_ENV,/my_app/releases/201409081122/.env \
|
58
|
+
--user nginx
|
59
|
+
|
60
|
+
### Environment Variables
|
61
|
+
|
62
|
+
# This translates to SOME_ENV_VARIABLES=1 and save to RUNTIME_ENV file.
|
63
|
+
set :foreman_env_variables, { some_env_variables: 1 }
|
64
|
+
|
65
|
+
## Capistrano Tasks
|
66
|
+
|
67
|
+
Export supervisord configuration from Procfile:
|
68
|
+
|
69
|
+
cap foreman:export
|
70
|
+
|
71
|
+
(Restart|Start|Stop) the applications:
|
72
|
+
|
73
|
+
cap foreman:(restart|start|stop)
|
74
|
+
|
75
|
+
## Contributing
|
76
|
+
|
77
|
+
1. Fork it
|
78
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
79
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
80
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
81
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capistrano/foreman_export/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "capistrano-foreman_export"
|
8
|
+
spec.version = Capistrano::ForemanExport::VERSION
|
9
|
+
spec.authors = ["Katsuma Ito"]
|
10
|
+
spec.email = ["katsumai@gmail.com"]
|
11
|
+
spec.description = %q{Capistrano task for foreman}
|
12
|
+
spec.summary = %q{Capistrano task for foreman}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'capistrano', '~> 3.2'
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path('../tasks/foreman.cap', __FILE__)
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'capistrano/foreman_export/backend/supervisord'
|
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
module Capistrano
|
3
|
+
module ForemanExport
|
4
|
+
module Backend
|
5
|
+
class Supervisord
|
6
|
+
|
7
|
+
def name
|
8
|
+
"supervisord"
|
9
|
+
end
|
10
|
+
|
11
|
+
def start_cmd(app_name)
|
12
|
+
wrap_bash <<-CMD
|
13
|
+
#{shell_add_if_new(app_name)}
|
14
|
+
supervisorctl start #{app_name}:*
|
15
|
+
CMD
|
16
|
+
end
|
17
|
+
|
18
|
+
def stop_cmd(app_name)
|
19
|
+
wrap_bash <<-CMD
|
20
|
+
supervisorctl stop #{app_name}:*
|
21
|
+
CMD
|
22
|
+
end
|
23
|
+
|
24
|
+
def restart_cmd(app_name)
|
25
|
+
wrap_bash <<-CMD
|
26
|
+
#{shell_add_if_new(app_name)}
|
27
|
+
supervisorctl restart #{app_name}:*
|
28
|
+
CMD
|
29
|
+
end
|
30
|
+
|
31
|
+
def shell_add_if_new(app_name)
|
32
|
+
"supervisorctl reread; sleep 3; supervisorctl status | grep -w -- '#{app_name}' | grep -qv grep || supervisorctl add #{app_name}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def wrap_bash(cmd)
|
36
|
+
"/bin/bash -c \"#{undent(cmd)}\""
|
37
|
+
end
|
38
|
+
|
39
|
+
def undent(str)
|
40
|
+
# from https://github.com/msmorgan/homebrew/blob/master/Library/Homebrew/extend/string.rb
|
41
|
+
str.gsub(/^.{#{str.slice(/^ +/).length}}/, '')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'capistrano/foreman_export/backend'
|
2
|
+
|
3
|
+
namespace :load do
|
4
|
+
task :defaults do
|
5
|
+
set :foreman_backend, Capistrano::ForemanExport::Backend::Supervisord
|
6
|
+
set :foreman_roles, :app
|
7
|
+
set :foreman_port, 5000
|
8
|
+
set :foreman_root, -> { release_path }
|
9
|
+
set :foreman_app, -> { fetch(:application) }
|
10
|
+
set :foreman_procfile, -> { release_path.join('Procfile') }
|
11
|
+
set :foreman_log, -> { release_path.join('log') }
|
12
|
+
set :foreman_user, 'nginx'
|
13
|
+
set :foreman_env_variables, {}
|
14
|
+
set :foreman_output, '/etc/supervisor.d'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
namespace :foreman do
|
19
|
+
|
20
|
+
desc "export"
|
21
|
+
task :export do
|
22
|
+
on roles(fetch(:foreman_roles)) do
|
23
|
+
within release_path do
|
24
|
+
invoke 'foreman:export_env_variables'
|
25
|
+
execute :sudo, "touch #{release_path}/.env"
|
26
|
+
options = []
|
27
|
+
options << "--port #{fetch(:foreman_port)}" if fetch(:foreman_port)
|
28
|
+
options << "--root #{fetch(:foreman_root)}" if fetch(:foreman_root)
|
29
|
+
options << "--app #{fetch(:foreman_app)}" if fetch(:foreman_app)
|
30
|
+
options << "--procfile #{fetch(:foreman_procfile)}" if fetch(:foreman_procfile)
|
31
|
+
options << "--log #{fetch(:foreman_log)}" if fetch(:foreman_log)
|
32
|
+
options << "--user #{fetch(:foreman_user)}" if fetch(:foreman_user)
|
33
|
+
options << "--env #{release_path.join('.env')},#{env_variable_path}"
|
34
|
+
execute :sudo, [ "env PATH=$PATH", "bundle exec",
|
35
|
+
"foreman export", backend.name, fetch(:foreman_output), options
|
36
|
+
]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :export_env_variables do
|
42
|
+
on roles(fetch(:foreman_roles)) do
|
43
|
+
envs = fetch(:foreman_env_variables).map {|k,v| %(#{k.upcase}=#{v}) }.join("\n")
|
44
|
+
envfile = StringIO.new(envs)
|
45
|
+
upload! envfile, env_variable_path
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "start"
|
50
|
+
task :start do
|
51
|
+
on roles(fetch(:foreman_roles)) do
|
52
|
+
execute :sudo, backend.start_cmd(fetch(:foreman_app))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
desc "stop"
|
57
|
+
task :stop do
|
58
|
+
on roles(fetch(:foreman_roles)) do
|
59
|
+
execute :sudo, backend.stop_cmd(fetch(:foreman_app))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
desc "restart"
|
64
|
+
task :restart do
|
65
|
+
on roles(fetch(:foreman_roles)) do
|
66
|
+
execute :sudo, backend.restart_cmd(fetch(:foreman_app))
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def backend
|
72
|
+
@backend ||= fetch(:foreman_backend).new
|
73
|
+
end
|
74
|
+
|
75
|
+
def env_variable_path
|
76
|
+
shared_path.join('RUNTIME_ENV')
|
77
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-foreman_export
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Katsuma Ito
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-14 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.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Capistrano task for foreman
|
56
|
+
email:
|
57
|
+
- katsumai@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- capistrano-foreman_export.gemspec
|
68
|
+
- lib/capistrano-foreman_export.rb
|
69
|
+
- lib/capistrano/foreman_export.rb
|
70
|
+
- lib/capistrano/foreman_export/backend.rb
|
71
|
+
- lib/capistrano/foreman_export/backend/supervisord.rb
|
72
|
+
- lib/capistrano/foreman_export/version.rb
|
73
|
+
- lib/capistrano/tasks/foreman.cap
|
74
|
+
homepage: ''
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.0.3
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Capistrano task for foreman
|
98
|
+
test_files: []
|