mascherano 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,25 +2,70 @@
2
2
 
3
3
  # Mascherano
4
4
 
5
- TODO: Write a gem description
5
+ Capistrano 3.x recipes
6
6
 
7
7
  ## Installation
8
8
 
9
9
  Add this line to your application's Gemfile:
10
10
 
11
- gem 'mascherano'
11
+ ```ruby
12
+ gem 'mascherano'
13
+ ```
12
14
 
13
15
  And then execute:
14
16
 
15
- $ bundle
17
+ ```bash
18
+ $ bundle
19
+ ```
16
20
 
17
21
  Or install it yourself as:
18
22
 
19
- $ gem install mascherano
23
+ ```bash
24
+ $ gem install mascherano
25
+ ```
20
26
 
27
+ ## Recipes
28
+
29
+ Mascherano currently have several recipes:
30
+
31
+ | recipe | description |
32
+ |----------------|-------------------------------------------------------------------------------------------------------|
33
+ | __env__ | Manage application configuration on `.env` file |
34
+ | __foreman__ | Manage Procfile application for [Foreman](http://ddollar.github.io/foreman) |
35
+ | __figaro__ | Manage configuration, usually `application.yml` for [Figaro](https://github.com/laserlemon/figaro) |
36
+ | __go__ | Manage and ability to deploy go application |
37
+ | __upstart__ | Manage application management using Upstart |
38
+ | __token__ | Manage and generate random secret token |
39
+ | __passenger__ | Manage Pushion Passenger based application |
40
+ | _more to come_ | _pull request are welcome ;)_ |
41
+
42
+ This package also provides a `noscm` recipe for when you don't need source code on your deployment box (usually application already compiled).
43
+
44
+ ```ruby
45
+ # deploy.rb
46
+ set :application, 'mascherano'
47
+ set :scm, :noscm
48
+ ```
21
49
  ## Usage
22
50
 
23
- TODO: Write usage instructions here
51
+ Make sure you have `Capfile` in the root of your project, so you can add these lines (choose which one you're using):
52
+
53
+ ```ruby
54
+ require 'mascherano/env'
55
+ require 'mascherano/figaro'
56
+ require 'mascherano/foreman'
57
+ require 'mascherano/go'
58
+ require 'mascherano/upstart'
59
+ ```
60
+
61
+ Then on `config/deploy/{env}.rb` you can customize the options:
62
+
63
+ ```ruby
64
+ set :env_file, '.staging.env'
65
+ set :foreman_procfile, -> { release_path.join('procfiles', 'staging') }
66
+ ```
67
+
68
+ See the `lib/mascherano/task/*.cap` for more options.
24
69
 
25
70
  ## Contributing
26
71
 
@@ -0,0 +1 @@
1
+ load File.expand_path('../tasks/noscm.cap', __FILE__)
@@ -0,0 +1,8 @@
1
+ namespace :noscm do
2
+ task :check do; end
3
+ task :create_release do
4
+ on roles(:all) do
5
+ execute :mkdir, '-p', release_path
6
+ end
7
+ end
8
+ end
@@ -0,0 +1 @@
1
+ load File.expand_path('../tasks/go.cap', __FILE__)
@@ -0,0 +1 @@
1
+ load File.expand_path('../tasks/passenger.cap', __FILE__)
@@ -5,11 +5,12 @@ namespace :env do
5
5
  You can override any of these defaults by setting the variables shown below.
6
6
 
7
7
  set :env_file, ".env"
8
+ set :env_roles, :all
8
9
  set :target_file, -> { shared_path.join('.env') }
9
10
  DESC
10
11
  task :upload do
11
- on roles(:app) do
12
- upload! fetch(:env_file), fetch(:env_target), via: :scp
12
+ on roles(fetch(:env_roles)) do
13
+ upload! fetch(:env_file), fetch(:env_target)
13
14
  end
14
15
  end
15
16
 
@@ -17,8 +18,8 @@ namespace :env do
17
18
  Symlink the .env file to the release_path
18
19
  DESC
19
20
  task :symlink do
20
- on roles(:app) do
21
- execute :ln, "-sf #{fetch(:env_target)} #{release_path.join('.env')}"
21
+ on roles(fetch(:env_roles)) do
22
+ execute :ln, '-sf', fetch(:env_target), release_path.join('.env')
22
23
  end
23
24
  end
24
25
  end
@@ -26,6 +27,7 @@ end
26
27
  namespace :load do
27
28
  task :defaults do
28
29
  set :env_file, ".env"
30
+ set :env_roles, :all
29
31
  set :env_target, -> { shared_path.join('.env') }
30
32
  end
31
33
  end
@@ -1,3 +1,5 @@
1
+ require 'stringio'
2
+
1
3
  namespace :figaro do
2
4
  desc <<-DESC
3
5
  Upload application config to the server
@@ -9,24 +11,24 @@ namespace :figaro do
9
11
  set :figaro_to_env, false
10
12
  DESC
11
13
  task :upload do
12
- on roles(:app) do
14
+ figaro_data = nil
15
+
16
+ run_locally do
13
17
  figaro_stage = fetch(:stage)
14
18
  figaro_tmp = "figaro-#{figaro_stage}"
15
19
 
16
- run_locally do
17
- if fetch(:figaro_to_env)
18
- figaro_cmd = %Q(Figaro.vars("#{figaro_stage}").split)
19
- else
20
- figaro_cmd = %Q(Figaro.env("#{figaro_stage}").to_yaml)
21
- end
22
-
23
- execute :bundle, "exec rails runner 'puts #{figaro_cmd}' > #{figaro_tmp}"
20
+ if fetch(:figaro_to_env)
21
+ figaro_cmd = %Q(Figaro.vars("#{figaro_stage}").split)
22
+ else
23
+ figaro_cmd = %Q(Figaro.env("#{figaro_stage}").to_yaml)
24
24
  end
25
25
 
26
- upload! figaro_tmp, fetch(:figaro_target), via: :scp
26
+ figaro_data = execute(:rails, "runner 'puts #{figaro_cmd}'").stdout
27
+ end
27
28
 
28
- run_locally do
29
- execute :rm, figaro_tmp
29
+ if figaro_data
30
+ on roles(fetch(:figaro_roles)) do
31
+ upload! StringIO.new(figaro_data), fetch(:figaro_target)
30
32
  end
31
33
  end
32
34
  end
@@ -35,8 +37,8 @@ namespace :figaro do
35
37
  Symlink the application config to the release_path
36
38
  DESC
37
39
  task :symlink do
38
- on roles(:app) do
39
- execute :ln, "-sf #{fetch(:figaro_target)} #{fetch(:figaro_config)}"
40
+ on roles(fetch(:figaro_roles)) do
41
+ execute :ln, '-sf', fetch(:figaro_target), fetch(:figaro_config)
40
42
  end
41
43
  end
42
44
  end
@@ -46,6 +48,7 @@ namespace :load do
46
48
  set :figaro_target, -> { shared_path.join('application.yml') }
47
49
  set :figaro_config, -> { release_path.join('config', 'application.yml') }
48
50
  set :figaro_to_env, false
51
+ set :figaro_roles, :app
49
52
  end
50
53
  end
51
54
 
@@ -12,12 +12,14 @@ namespace :foreman do
12
12
  set :foreman_app, -> { fetch(:application) }
13
13
  set :foreman_user, -> { fetch(:user) }
14
14
  set :foreman_log, -> { shared_path.join('log') }
15
+ set :foreman_pids, -> { shared_path.join('pids') }
15
16
  set :foreman_concurrency, false
16
17
  set :foreman_sudo, false
18
+ set :foreman_roles, :all
17
19
  DESC
18
20
 
19
21
  task :export do
20
- on roles(:all) do
22
+ on roles(fetch(:foreman_roles)) do
21
23
  within release_path do
22
24
  concurrency = fetch(:foreman_concurrency)
23
25
  sudo = fetch(:foreman_sudo)
@@ -29,6 +31,7 @@ namespace :foreman do
29
31
  args << %Q(-a #{fetch(:foreman_app)})
30
32
  args << %Q(-u #{fetch(:foreman_user)})
31
33
  args << %Q(-l #{fetch(:foreman_log)})
34
+ args << %Q(-r #{fetch(:foreman_pids)})
32
35
  args << %Q(-c #{concurrency}) if concurrency
33
36
 
34
37
  cmd = "foreman export #{args.join(' ')}"
@@ -53,8 +56,10 @@ namespace :load do
53
56
  set :foreman_app, -> { fetch(:application) }
54
57
  set :foreman_user, -> { fetch(:user) }
55
58
  set :foreman_log, -> { shared_path.join('log') }
59
+ set :foreman_pids, -> { shared_path.join('pids') }
56
60
  set :foreman_concurrency, false
57
61
  set :foreman_sudo, false
62
+ set :foreman_roles, :all
58
63
  end
59
64
  end
60
65
 
@@ -0,0 +1,46 @@
1
+ namespace :go do
2
+ desc <<-DESC
3
+ Compile the go application locally
4
+
5
+ You can override any of these defaults by setting the variables shown below.
6
+
7
+ set :go_input, 'api.go'
8
+ set :go_output, 'api'
9
+ set :go_os, 'linux'
10
+ set :go_arch, 'amd64'
11
+ set :go_roles, :app
12
+ set :go_target, -> { release_path.join(fetch(:go_output)) }
13
+ DESC
14
+ task :build do
15
+ on roles(fetch(:go_roles)) do
16
+ run_locally do
17
+ go_flags = {
18
+ 'GOOS' => fetch(:go_os),
19
+ 'GOARCH' => fetch(:go_arch)
20
+ }
21
+
22
+ with(go_flags) do
23
+ execute :go, 'build', '-o', fetch(:go_output), fetch(:go_input)
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ desc 'Upload compiled application to the server'
30
+ task :upload do
31
+ on roles(fetch(:go_roles)) do
32
+ upload! fetch(:go_output), fetch(:go_target)
33
+ end
34
+ end
35
+ end
36
+
37
+ namespace :load do
38
+ task :defaults do
39
+ set :go_input, 'api.go'
40
+ set :go_output, 'api'
41
+ set :go_os, 'linux'
42
+ set :go_arch, 'amd64'
43
+ set :go_roles, :app
44
+ set :go_target, -> { release_path.join(fetch(:go_output)) }
45
+ end
46
+ end
@@ -0,0 +1,42 @@
1
+ namespace :passenger do
2
+ desc 'Start passenger'
3
+ task :start do
4
+ on roles(fetch(:passenger_roles)) do
5
+ within current_path do
6
+ execute fetch(:passenger_cmd), 'start', '-e', fetch(:passenger_env), '-p', fetch(:passenger_port), '-d'
7
+ end
8
+ end
9
+ end
10
+
11
+ desc 'Stop passenger'
12
+ task :stop do
13
+ on roles(fetch(:passenger_roles)) do
14
+ within current_path do
15
+ execute fetch(:passenger_cmd), 'stop', '-p', fetch(:passenger_port)
16
+ end
17
+ end
18
+ end
19
+
20
+ desc 'Restart passenger'
21
+ task :restart do
22
+ on roles(fetch(:passenger_roles)) do
23
+ within current_path do
24
+ if test " [ -f tmp/pids/passenger.#{fetch(:passenger_port)}.pid ] "
25
+ invoke 'passenger:stop'
26
+ end
27
+
28
+ invoke 'passenger:start'
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ namespace :load do
35
+ task :defaults do
36
+ set :passenger_cmd, 'bundle exec passenger'
37
+ set :passenger_env, -> { fetch(:stage) }
38
+ set :passenger_port, 9292
39
+ set :passenger_roles, :app
40
+ end
41
+ end
42
+
@@ -0,0 +1,33 @@
1
+ require 'securerandom'
2
+ require 'stringio'
3
+
4
+ def generate_token(n)
5
+ SecureRandom.hex(n)
6
+ end
7
+
8
+ namespace :token do
9
+ desc 'Generate random token'
10
+ task :generate do
11
+ on roles(fetch(:token_roles)) do
12
+ info generate_token(fetch(:token_length))
13
+ end
14
+ end
15
+
16
+ desc 'Upload random token as a file on remote server'
17
+ task :upload do
18
+ on roles(fetch(:token_roles)) do
19
+ token = generate_token(fetch(:token_length))
20
+ io = StringIO.new(token)
21
+ upload! io, fetch(:token_target)
22
+ end
23
+ end
24
+ end
25
+
26
+ namespace :load do
27
+ task :defaults do
28
+ set :token_length, 64
29
+ set :token_target, -> { shared_path.join('.token') }
30
+ set :token_roles, :app
31
+ end
32
+ end
33
+
@@ -1,29 +1,30 @@
1
- def cmd(service_name, action, sudo = false)
2
- sudo_cmd = sudo ? 'sudo ' : ''
3
- "#{sudo_cmd} service #{service_name} #{action}"
1
+ def build_cmd(service_name, action, sudo = false)
2
+ cmd = "service #{service_name} #{action}"
3
+ cmd = "sudo " + cmd if sudo
4
+ cmd
4
5
  end
5
6
 
6
7
  namespace :upstart do
7
8
  desc "Start the application services"
8
9
  task :start do
9
- on roles(:app) do
10
- execute cmd(fetch(:upstart_service), 'start', fetch(:upstart_sudo))
10
+ on roles(fetch(:upstart_roles)) do
11
+ execute build_cmd(fetch(:upstart_service), 'start', fetch(:upstart_sudo))
11
12
  end
12
13
  end
13
14
 
14
15
  desc "Stop the application services"
15
16
  task :stop do
16
- on roles(:app) do
17
- execute cmd(fetch(:upstart_service), 'stop', fetch(:upstart_sudo))
17
+ on roles(fetch(:upstart_roles)) do
18
+ execute build_cmd(fetch(:upstart_service), 'stop', fetch(:upstart_sudo))
18
19
  end
19
20
  end
20
21
 
21
22
  desc "Restart the application services"
22
23
  task :restart do
23
- on roles(:app) do
24
- cmd_sq = cmd(fetch(:upstart_service), 'start', fetch(:upstart_sudo))
24
+ on roles(fetch(:upstart_roles)) do
25
+ cmd_sq = build_cmd(fetch(:upstart_service), 'start', fetch(:upstart_sudo))
25
26
  cmd_sq += ' || '
26
- cmd_sq += cmd(fetch(:upstart_service), 'restart', fetch(:upstart_sudo))
27
+ cmd_sq += build_cmd(fetch(:upstart_service), 'restart', fetch(:upstart_sudo))
27
28
 
28
29
  execute cmd_sq
29
30
  end
@@ -34,6 +35,7 @@ namespace :load do
34
35
  task :defaults do
35
36
  set :upstart_service, -> { fetch(:application) }
36
37
  set :upstart_sudo, false
38
+ set :upstart_roles, :app
37
39
  end
38
40
  end
39
41
 
@@ -0,0 +1 @@
1
+ load File.expand_path('../tasks/token.cap', __FILE__)
@@ -1,3 +1,3 @@
1
1
  module Mascherano
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mascherano
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-11 00:00:00.000000000 Z
12
+ date: 2013-10-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
@@ -72,14 +72,22 @@ files:
72
72
  - README.md
73
73
  - Rakefile
74
74
  - img/mascherano-logo.png
75
+ - lib/capistrano/noscm.rb
76
+ - lib/capistrano/tasks/noscm.cap
75
77
  - lib/mascherano.rb
76
78
  - lib/mascherano/env.rb
77
79
  - lib/mascherano/figaro.rb
78
80
  - lib/mascherano/foreman.rb
81
+ - lib/mascherano/go.rb
82
+ - lib/mascherano/passenger.rb
79
83
  - lib/mascherano/tasks/env.cap
80
84
  - lib/mascherano/tasks/figaro.cap
81
85
  - lib/mascherano/tasks/foreman.cap
86
+ - lib/mascherano/tasks/go.cap
87
+ - lib/mascherano/tasks/passenger.cap
88
+ - lib/mascherano/tasks/token.cap
82
89
  - lib/mascherano/tasks/upstart.cap
90
+ - lib/mascherano/token.rb
83
91
  - lib/mascherano/upstart.rb
84
92
  - lib/mascherano/version.rb
85
93
  - mascherano.gemspec
@@ -96,12 +104,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
104
  - - ! '>='
97
105
  - !ruby/object:Gem::Version
98
106
  version: '0'
107
+ segments:
108
+ - 0
109
+ hash: -3389475692804839278
99
110
  required_rubygems_version: !ruby/object:Gem::Requirement
100
111
  none: false
101
112
  requirements:
102
113
  - - ! '>='
103
114
  - !ruby/object:Gem::Version
104
115
  version: '0'
116
+ segments:
117
+ - 0
118
+ hash: -3389475692804839278
105
119
  requirements: []
106
120
  rubyforge_project:
107
121
  rubygems_version: 1.8.23
@@ -109,4 +123,3 @@ signing_key:
109
123
  specification_version: 3
110
124
  summary: Capistrano 3.x recipes
111
125
  test_files: []
112
- has_rdoc: