producer-rails 0.1.1 → 0.2.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
2
  SHA1:
3
- metadata.gz: 3ecea15a3878eeff0a016f4524e97990a47c2f26
4
- data.tar.gz: dae3fa6716e2ab50d81d8de1b0c853a8edbc710f
3
+ metadata.gz: e47134856bd5d3447bc62bfc3be0b9fef1afa1f6
4
+ data.tar.gz: a1ef63458c408b2e8fb7379c4e788ff2b392cdda
5
5
  SHA512:
6
- metadata.gz: bd71e1361a7475fded1790e97c3ffd13514305750655573a84152c35045a827fff6a7caf85afa97f3b7adbf57e8b6041396d0fdc9997f44c65fa3ee4e6ada57d
7
- data.tar.gz: d3a352ff6b085b11951cd100fe12d980889edfaa797d4ec922911c476bd8a72f71395f1d718ce03ad479571bfb923f46168132933078f93b264c9f0d0c42d49f
6
+ metadata.gz: 07e1b5dfc4d6f4418c23c75e9faab80c552f04b894b657cbfa2a9bd0f2a754f6b6f730a04d1aa3db6f55aa3255731f5f61cc098b4d6ea5e98700054cc0c9d383
7
+ data.tar.gz: 34c13ff707c882f577bddeb4263482d4af0456f5f4a09a18b669dfb4965104703bcb78885508fff6d70581efee44c24a36ec06af9d704b028b7e68f6e0d7a0d0
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.2
6
+ - ruby-head
7
+ - 2.1
8
+ before_script:
9
+ - ssh-keygen -f ~/.ssh/id_rsa -t rsa -N ''
10
+ - cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
11
+ - chmod 600 ~/.ssh/authorized_keys
12
+ - eval `ssh-agent -s`
13
+ - ssh-add ~/.ssh/id_rsa
data/Guardfile ADDED
@@ -0,0 +1,7 @@
1
+ directories %w[features lib]
2
+
3
+ guard :cucumber, cli: '--format pretty --quiet', all_on_start: false do
4
+ watch(%r{\Afeatures/.+\.feature\z})
5
+ watch(%r{\Afeatures/support/.+\.rb\z}) { 'features' }
6
+ watch(%r{\Afeatures/step_definitions/.+_steps\.rb\z}) { 'features' }
7
+ end
data/LICENSE ADDED
@@ -0,0 +1,30 @@
1
+ Copyright 2014 Thibault Jouan. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions are
5
+ met:
6
+
7
+ * Redistributions of source code must retain the above copyright
8
+ notice, this list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright
11
+ notice, this list of conditions and the following disclaimer in
12
+ the documentation and/or other materials provided with the
13
+ distribution.
14
+
15
+ * Neither the name of the software nor the names of its contributors
16
+ may be used to endorse or promote products derived from this
17
+ software without specific prior written permission.
18
+
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS "AS IS" AND
21
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
+ PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS
24
+ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27
+ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
30
+ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ producer-rails
2
+ ==============
3
+
4
+ Ruby on Rails specific macros and tests for [producer][].
5
+
6
+ [![Version][badge-version-img]][badge-version-uri]
7
+
8
+
9
+ Usage
10
+ -----
11
+
12
+ ```ruby
13
+ # config/deploy.rb
14
+ require 'producer/rails'
15
+
16
+ set :repository, 'git.example:repository_path'
17
+ set :app_path, 'deployment_path'
18
+
19
+ deploy
20
+ ```
21
+
22
+ ```
23
+ # Deploy for the first time:
24
+ $ producer config/deploy.rb -t host.example -- init
25
+
26
+ # Deploy updated application (with application restart):
27
+ $ producer config/deploy.rb -t host.example -- update
28
+
29
+ # Start application
30
+ $ producer config/deploy.rb -t host.example -- start
31
+
32
+ # Stop application
33
+ $ producer config/deploy.rb -t host.example -- stop
34
+
35
+ # Restart application
36
+ $ producer config/deploy.rb -t host.example -- restart
37
+ ```
38
+
39
+
40
+
41
+ [producer]: https://github.com/tjouan/producer-core
42
+ [badge-version-img]: https://img.shields.io/gem/v/producer-rails.svg?style=flat-square
43
+ [badge-version-uri]: https://rubygems.org/gems/producer-rails
@@ -0,0 +1,40 @@
1
+ @sshd @sshd_gem_env
2
+ Feature: producer recipe arguments usage
3
+
4
+ Background:
5
+ Given a rails app repository
6
+
7
+ Scenario: `init' recipe argument is given
8
+ Given I write a standard deployment recipe
9
+ When I execute the deployment recipe with "init" recipe argument
10
+ Then the deployed app must be initialized
11
+
12
+ Scenario: `update' recipe argument is given
13
+ Given I make the initial deployment
14
+ And I make a change in the rails app repository
15
+ And I write a standard deployment recipe
16
+ When I execute the deployment recipe with "update" recipe argument
17
+ Then the deployed app repository must be up to date
18
+
19
+ @unicorn_kill
20
+ Scenario: `start' recipe argument is given
21
+ Given I make the initial deployment
22
+ And I write a standard deployment recipe
23
+ When I execute the deployment recipe with "start" recipe argument
24
+ Then the deployed app unicorn server must be running
25
+
26
+ Scenario: `stop' recipe argument is given
27
+ Given I make the initial deployment
28
+ And I start the deployed app
29
+ And I write a standard deployment recipe
30
+ When I execute the deployment recipe with "stop" recipe argument
31
+ Then the deployed app unicorn server must not be running
32
+
33
+ @unicorn_kill
34
+ Scenario: `restart' recipe argument is given
35
+ Given I make the initial deployment
36
+ And I start the deployed app
37
+ And the deployed app unicorn server is running with a certain pid
38
+ And I write a standard deployment recipe
39
+ When I execute the deployment recipe with "restart" recipe argument
40
+ Then the deployed app unicorn server must have a different pid
@@ -2,34 +2,29 @@
2
2
  Feature: `deploy_init' macro
3
3
 
4
4
  Background:
5
- Given a rails app repository in remote directory "repos/my_app"
6
- And a recipe with:
7
- """
8
- require 'producer/rails'
9
-
10
- set :repository, 'repos/my_app'
11
- set :app_path, 'deploys/my_app'
12
- set :www_workers, 2
13
-
14
- deploy_init
15
-
16
- """
5
+ Given a rails app repository
6
+ And I write a deployment recipe calling "deploy_init"
17
7
 
18
8
  Scenario: clones the app in configured remote directory
19
- When I successfully execute the recipe on remote target
20
- Then the remote file "deploys/my_app/config.ru" must exist
9
+ When I execute the deployment recipe
10
+ Then the deployed app repository must be cloned
21
11
 
22
12
  Scenario: configures the database connection
23
- When I successfully execute the recipe on remote target
24
- Then the remote file "deploys/my_app/config/database.yml" must contain exactly:
25
- """
26
- default: &default
27
- adapter: postgresql
28
- encoding: unicode
29
- pool: 5
13
+ When I execute the deployment recipe
14
+ Then the deployed app must have its database connection configured
15
+
16
+ Scenario: installs dependencies with bundler
17
+ When I execute the deployment recipe
18
+ Then the deployed app must have its dependencies installed
19
+
20
+ Scenario: executes database migrations
21
+ When I execute the deployment recipe
22
+ Then the deployed app must have its database migrations up
30
23
 
31
- production:
32
- <<: *default
33
- database: some_host_test
24
+ Scenario: generates a secret key for production
25
+ When I execute the deployment recipe
26
+ Then the deployed app must have secret key setup
34
27
 
35
- """
28
+ Scenario: configures unicorn server
29
+ When I execute the deployment recipe
30
+ Then the deployed app must have unicorn configuration
@@ -0,0 +1,14 @@
1
+ @sshd @sshd_gem_env
2
+ Feature: `deploy_restart' macro
3
+
4
+ Background:
5
+ Given a rails app repository
6
+ And I make the initial deployment
7
+ And I start the deployed app
8
+ And the deployed app unicorn server is running with a certain pid
9
+ And I write a deployment recipe calling "deploy_restart"
10
+
11
+ @unicorn_kill
12
+ Scenario: restarts unicorn server
13
+ When I execute the deployment recipe
14
+ Then the deployed app unicorn server must have a different pid
@@ -0,0 +1,12 @@
1
+ @sshd @sshd_gem_env
2
+ Feature: `deploy_start' macro
3
+
4
+ Background:
5
+ Given a rails app repository
6
+ And I make the initial deployment
7
+ And I write a deployment recipe calling "deploy_start"
8
+
9
+ @unicorn_kill
10
+ Scenario: starts unicorn server
11
+ When I execute the deployment recipe
12
+ Then the deployed app unicorn server must be running
@@ -0,0 +1,12 @@
1
+ @sshd @sshd_gem_env
2
+ Feature: `deploy_stop' macro
3
+
4
+ Background:
5
+ Given a rails app repository
6
+ And I make the initial deployment
7
+ And I start the deployed app
8
+ And I write a deployment recipe calling "deploy_stop"
9
+
10
+ Scenario: stops unicorn server
11
+ When I execute the deployment recipe
12
+ Then the deployed app unicorn server must not be running
@@ -0,0 +1,12 @@
1
+ @sshd @sshd_gem_env
2
+ Feature: `deploy_update' macro
3
+
4
+ Background:
5
+ Given a rails app repository
6
+ And I make the initial deployment
7
+ And I make a change in the rails app repository
8
+ And I write a deployment recipe calling "deploy_update"
9
+
10
+ Scenario: updates the deployed app repository
11
+ When I execute the deployment recipe
12
+ Then the deployed app repository must be up to date
@@ -0,0 +1,131 @@
1
+ RECIPE_PATH = 'recipe.rb'.freeze
2
+ DEPLOY_PATH = 'deploys/my_app'.freeze
3
+
4
+ def deploy_recipe_write(repository, macro)
5
+ @deploy_path = DEPLOY_PATH
6
+ write_file RECIPE_PATH, <<-eoh
7
+ require 'producer/rails'
8
+
9
+ set :repository, '#{repository}'
10
+ set :app_path, '#{@deploy_path}'
11
+
12
+ #{macro}
13
+ eoh
14
+ end
15
+
16
+ def deploy_recipe_run(rargv: [])
17
+ run_recipe remote: true, check: true, rargv: rargv, options: '-v'
18
+ end
19
+
20
+ Given /^I write a deployment recipe calling "([^"]+)"$/ do |macro|
21
+ deploy_recipe_write @repository, macro
22
+ end
23
+
24
+ Given /^I write a standard deployment recipe$/ do
25
+ deploy_recipe_write @repository, 'deploy'
26
+ end
27
+
28
+ Given /^I make the initial deployment$/ do
29
+ deploy_recipe_write @repository, 'deploy_init'
30
+ deploy_recipe_run
31
+ end
32
+
33
+ Given /^I start the deployed app$/ do
34
+ deploy_recipe_write @repository, 'deploy_start'
35
+ deploy_recipe_run
36
+ end
37
+
38
+ Given /^the deployed app unicorn server is running with a certain pid$/ do
39
+ in_current_dir do
40
+ @deploy_unicorn_pid = File.read("#{@deploy_path}/tmp/run/www.pid").to_i
41
+ end
42
+ end
43
+
44
+ When /^I execute the deployment recipe$/ do
45
+ deploy_recipe_run
46
+ end
47
+
48
+ When /^I execute the deployment recipe with "([^"]+)" recipe argument$/ do |arg|
49
+ deploy_recipe_run rargv: [arg]
50
+ end
51
+
52
+ Then /^the deployed app must be initialized$/ do
53
+ step 'the deployed app must have unicorn configuration'
54
+ end
55
+
56
+ Then /^the deployed app repository must be cloned$/ do
57
+ in_current_dir do
58
+ expect(`git -C #{@deploy_path} log --oneline -1`)
59
+ .to include 'Add generated rails app'
60
+ end
61
+ end
62
+
63
+ Then /^the deployed app repository must be up to date$/ do
64
+ in_current_dir do
65
+ expect(`git -C #{@deploy_path} log --oneline -1`).to include 'Make change'
66
+ end
67
+ end
68
+
69
+ Then /^the deployed app must have its database connection configured$/ do
70
+ check_file_content "#{@deploy_path}/config/database.yml", <<-eoh
71
+ default: &default
72
+ adapter: postgresql
73
+ encoding: unicode
74
+ pool: 5
75
+
76
+ production:
77
+ <<: *default
78
+ database: some_host_test
79
+ eoh
80
+ end
81
+
82
+ Then /^the deployed app must have its dependencies installed$/ do
83
+ check_file_presence "#{@deploy_path}/Gemfile.lock", true
84
+ end
85
+
86
+ Then /^the deployed app must have its database migrations up$/ do
87
+ unset_bundler_env_vars
88
+ with_env 'RUBYLIB' => nil, 'RAILS_ENV' => 'production' do
89
+ in_current_dir do
90
+ expect(`cd #{@deploy_path} && bundle exec rake db:migrate:status`)
91
+ .to match /up\s+\d+\s+Create users/
92
+ end
93
+ end
94
+ end
95
+
96
+ Then /^the deployed app must have secret key setup$/ do
97
+ in_current_dir do
98
+ secrets = YAML.load(File.read("#{@deploy_path}/config/secrets.yml"))
99
+ expect(secrets['production']['secret_key_base']).to be
100
+ end
101
+ end
102
+
103
+ Then /^the deployed app must have unicorn configuration$/ do
104
+ check_file_content "#{@deploy_path}/config/unicorn.rb", <<-eoh
105
+ worker_processes 2
106
+ timeout 60
107
+ preload_app false
108
+ pid 'tmp/run/www.pid'
109
+ listen "\#{ENV['HOME']}/#{@deploy_path}/tmp/run/www.sock"
110
+ eoh
111
+ end
112
+
113
+ Then /^the deployed app unicorn server must be running$/ do
114
+ pid_path = "#{@deploy_path}/tmp/run/www.pid"
115
+ check_file_presence pid_path, true
116
+ in_current_dir do
117
+ expect { expect(Process.kill(0, File.read(pid_path).to_i)).to eq 1 }
118
+ .not_to raise_error
119
+ end
120
+ end
121
+
122
+ Then /^the deployed app unicorn server must not be running$/ do
123
+ check_file_presence "#{@deploy_path}/tmp/run/www.pid", false
124
+ end
125
+
126
+ Then /^the deployed app unicorn server must have a different pid$/ do
127
+ in_current_dir do
128
+ expect(File.read("#{@deploy_path}/tmp/run/www.pid").to_i)
129
+ .not_to eq @deploy_unicorn_pid
130
+ end
131
+ end
@@ -0,0 +1,34 @@
1
+ Given /^a rails app repository$/ do
2
+ @repository = 'repos/my_app'
3
+ env = {
4
+ 'BUNDLE_GEMFILE' => nil,
5
+ 'RUBYLIB' => nil,
6
+ 'RUBYOPT' => nil
7
+ }
8
+ in_current_dir do
9
+ [
10
+ "rails new --database=postgresql --skip-bundle #{@repository} > /dev/null",
11
+ "rm -f #{@repository}/config/secrets.yml",
12
+ "echo gem \\'unicorn\\' >> #{@repository}/Gemfile",
13
+ "cd #{@repository} && bundle install > /dev/null",
14
+ "cd #{@repository} && bundle exec rails g model User name:string > /dev/null 2>&1",
15
+ "rm -f #{@repository}/config/database.yml",
16
+ "echo /config/database.yml > #{@repository}/.gitignore",
17
+ "echo /config/secrets.yml >> #{@repository}/.gitignore",
18
+ "echo /log/*.log >> #{@repository}/.gitignore",
19
+ "echo /public/assets/ >> #{@repository}/.gitignore",
20
+ "echo /tmp/ >> #{@repository}/.gitignore",
21
+ "git -C #{@repository} init > /dev/null",
22
+ "git -C #{@repository} config user.email bob@example",
23
+ "git -C #{@repository} config user.name Bob",
24
+ "git -C #{@repository} add . > /dev/null",
25
+ "git -C #{@repository} commit -m 'Add generated rails app' > /dev/null"
26
+ ].each { |cmd| fail unless with_env(env) { system cmd } }
27
+ end
28
+ end
29
+
30
+ Given /^I make a change in the rails app repository$/ do
31
+ in_current_dir do
32
+ fail unless system "git -C #{@repository} commit --allow-empty -m 'Make change'"
33
+ end
34
+ end
@@ -3,19 +3,6 @@ require 'producer/core/testing/cucumber'
3
3
 
4
4
  GEMRC = "gem: --no-ri --no-rdoc\n".freeze
5
5
 
6
- Before('@sshd_gem_env_bundler') do
7
- env = { 'GEM_HOME' => "#{ENV['HOME']}/.gem" }
8
- write_file '.gemrc', GEMRC
9
- write_file '.ssh/rc', <<-eoh
10
- export GEM_HOME=#{env['GEM_HOME']}
11
- export PATH=#{env['GEM_HOME']}/bin:$PATH
12
- eoh
13
- with_env(env) do
14
- unset_bundler_env_vars
15
- fail unless system 'gem install bundler > /dev/null'
16
- end
17
- end
18
-
19
6
  Before('@sshd_gem_env') do
20
7
  write_file '.gemrc', GEMRC
21
8
  write_file '.ssh/rc', <<-eoh
@@ -24,3 +11,14 @@ export PATH=#{ENV['GEM_HOME']}/bin:$PATH
24
11
  export RAILS_ENV=production
25
12
  eoh
26
13
  end
14
+
15
+ After('@unicorn_kill') do
16
+ in_current_dir do
17
+ pid = File.read("#{@deploy_path}/tmp/run/www.pid").to_i
18
+ Process.kill('QUIT', pid)
19
+ end
20
+ end
21
+
22
+ Before do
23
+ system 'dropdb --if-exists some_host_test > /dev/null'
24
+ end
@@ -1,8 +1,8 @@
1
+ require 'producer/stdlib'
2
+ require 'securerandom'
3
+
1
4
  module Producer
2
5
  module Rails
3
- require 'producer/stdlib'
4
- require 'securerandom'
5
-
6
6
  class << self
7
7
  def define_macro(name, &block)
8
8
  ::Producer::Core::Recipe.define_macro(name, block)
@@ -14,77 +14,70 @@ module Producer
14
14
  end
15
15
 
16
16
  UNICORN_CONF_PATH = 'config/unicorn.rb'.freeze
17
+ WWW_WORKERS = 2
18
+ WWW_TIMEOUT = 60
17
19
  WWW_PID_PATH = 'tmp/run/www.pid'.freeze
18
20
  WWW_SOCK_PATH = 'tmp/run/www.sock'.freeze
19
21
  BUNDLER_UNSET_GROUPS = %w[development test].freeze
20
22
 
21
- define_macro :deploy do
22
- app_path = get :app_path
23
-
24
- if ENV.key? 'DEPLOY_INIT'
25
- deploy_init app_path
26
- else
27
- deploy_update app_path
28
- end
29
-
30
- assets_update app_path if set? :assets_update
31
-
32
- deploy_restart
23
+ define_macro :_deploy_registry_setup do
24
+ set :database, target.sub(?., ?_) unless set? :database
33
25
  end
34
26
 
35
- define_macro :deploy_init do |app_path = get(:app_path)|
36
- app_path ||= get :app_path
27
+ define_macro :deploy do |path = get(:app_path)|
28
+ _deploy_registry_setup
37
29
 
38
- ensure_dir app_path, mode: 0701
39
- git_clone get(:repository), app_path
40
- app_init app_path,
41
- dirs: (get :app_mkdir, []),
42
- files: (get :app_mkfile, [])
43
- db_config app_path
44
- bundle_install app_path, (get :bundler_unset, [])
45
- db_init app_path
46
- db_seed app_path if set? :db_seed
47
- secrets_init app_path
48
- www_config app_path
30
+ case recipe_argv[0]
31
+ when 'init' then deploy_init
32
+ when 'update' then deploy_update
33
+ when 'start' then deploy_start
34
+ when 'stop' then deploy_stop
35
+ when 'restart' then deploy_restart
36
+ end
49
37
  end
50
38
 
51
- define_macro :deploy_update do |app_path = nil|
52
- app_path ||= get :app_path
39
+ define_macro :deploy_init do |path = get(:app_path)|
40
+ _deploy_registry_setup
53
41
 
54
- git_update app_path
55
- bundle_install app_path
56
- db_migrate app_path
57
- db_seed app_path if set? :db_seed
58
- www_config app_path
42
+ ensure_dir path, mode: 0711
43
+ git_clone get(:repository), path
44
+ app_init path,
45
+ dirs: get(:app_mkdir, []),
46
+ files: get(:app_mkfile, [])
47
+ db_config path
48
+ bundle_install path, get(:bundler_unset, [])
49
+ db_init path
50
+ db_seed path if set? :db_seed
51
+ secrets_init path
52
+ www_config path
53
+ assets_update path if set? :assets_update
59
54
  end
60
55
 
61
- define_macro :deploy_restart do |app_path = nil|
62
- app_path ||= get :app_path
56
+ define_macro :deploy_update do |path = get(:app_path)|
57
+ _deploy_registry_setup
63
58
 
64
- if ENV.key?('DEPLOY_INIT') || ENV.key?('DEPLOY_START')
65
- deploy_start
66
- else
67
- deploy_stop
68
- deploy_start
69
- end
59
+ git_update path
60
+ db_config path
61
+ bundle_install path
62
+ db_migrate path
63
+ db_seed path if set? :db_seed
64
+ www_config path
65
+ assets_update path if set? :assets_update
70
66
  end
71
67
 
72
- define_macro :deploy_stop do
73
- app_path ||= get :app_path
74
- www_pid_path = (get :www_pid_path, WWW_PID_PATH)
75
- processes = (get :processes, nil)
76
-
77
- app_stop if processes
78
- www_stop app_path, www_pid_path
68
+ define_macro :deploy_restart do |path = get(:app_path)|
69
+ deploy_stop path
70
+ deploy_start path
79
71
  end
80
72
 
81
- define_macro :deploy_start do
82
- app_path ||= get :app_path
83
- www_pid_path = (get :www_pid_path, WWW_PID_PATH)
84
- processes = (get :processes, nil)
73
+ define_macro :deploy_stop do |path = get(:app_path)|
74
+ app_stop if set? :processes
75
+ www_stop path, get(:www_pid_path, WWW_PID_PATH)
76
+ end
85
77
 
86
- www_start app_path, www_pid_path
87
- app_start app_path, processes if processes
78
+ define_macro :deploy_start do |path = get(:app_path)|
79
+ www_start path, get(:www_pid_path, WWW_PID_PATH)
80
+ app_start path, get(:processes, nil) if set? :processes
88
81
  end
89
82
 
90
83
  define_test :bundle_installed? do |gemfile|
@@ -116,8 +109,7 @@ module Producer
116
109
  end
117
110
 
118
111
  define_macro :db_config do |path|
119
- path = "#{path}/config/database.yml"
120
- conf = <<-eoh
112
+ file_write_once "#{path}/config/database.yml", <<-eoh
121
113
  default: &default
122
114
  adapter: postgresql
123
115
  encoding: unicode
@@ -125,20 +117,20 @@ default: &default
125
117
 
126
118
  production:
127
119
  <<: *default
128
- database: #{target.sub '.', '_'}
129
- eoh
130
-
131
- file_write_once path, conf
120
+ database: #{get :database}
121
+ eoh
132
122
  end
133
123
 
134
124
  define_macro :db_init do |path|
135
- condition { no_sh 'psql -l | grep -E "^ +%s"' % target }
125
+ condition { no_sh 'psql -l | grep -E "^ +%s"' % get(:database) }
136
126
 
137
127
  sh "cd #{path} && bundle exec rake db:create db:migrate"
138
128
  end
139
129
 
140
130
  define_macro :db_migrate do |path|
141
- condition { sh "cd #{path} && bundle exec rake db:migrate:status | grep -E '^ +down'" }
131
+ condition do
132
+ sh "cd #{path} && bundle exec rake db:migrate:status | grep -E '^ +down'"
133
+ end
142
134
 
143
135
  sh "cd #{path} && bundle exec rake db:migrate"
144
136
  end
@@ -148,33 +140,29 @@ production:
148
140
  end
149
141
 
150
142
  define_macro :secrets_init do |path|
151
- path = "#{path}/config/secrets.yml"
143
+ secrets_path = "#{path}/config/secrets.yml"
152
144
  conf = <<-eoh
153
145
  production:
154
146
  secret_key_base: #{SecureRandom.hex(64)}
155
147
  eoh
156
148
 
157
- condition { no_file? path }
149
+ condition { no_file? secrets_path }
158
150
 
159
- file_write path, conf
151
+ file_write secrets_path, conf
160
152
  end
161
153
 
162
154
  define_macro :www_config do |path|
163
155
  www_config_path = File.join(
164
156
  path,
165
- (get :www_config_path, UNICORN_CONF_PATH)
157
+ get(:www_config_path, UNICORN_CONF_PATH)
166
158
  )
167
- conf = <<-eoh
168
- worker_processes #{get :www_workers}
169
- timeout #{get :www_timeout, 60}
159
+ file_write_once www_config_path, <<-eoh
160
+ worker_processes #{get :www_workers, WWW_WORKERS}
161
+ timeout #{get :www_timeout, WWW_TIMEOUT}
170
162
  preload_app false
171
163
  pid '#{get :www_pid_path, WWW_PID_PATH}'
172
- listen "\#{ENV['HOME']}/#{path}/#{(get :www_sock_path, WWW_SOCK_PATH)}"
164
+ listen "\#{ENV['HOME']}/#{path}/#{get(:www_sock_path, WWW_SOCK_PATH)}"
173
165
  eoh
174
-
175
- condition { no_file_contains www_config_path, conf }
176
-
177
- file_write www_config_path, conf
178
166
  end
179
167
 
180
168
  define_macro :assets_update do |path|
@@ -184,30 +172,32 @@ listen "\#{ENV['HOME']}/#{path}/#{(get :www_sock_path, WWW_SOCK_PATH)
184
172
  sh "cd #{path} && find public/assets -type f -exec chmod 644 {} \\;"
185
173
  end
186
174
 
187
- define_macro :app_start do |app_path, processes|
175
+ define_macro :app_start do |path, processes|
188
176
  condition { no_sh 'tmux has-session -t app' }
189
177
 
190
- sh "cd #{app_path} && tmux new -d -s app 'foreman start -c #{processes}; zsh'"
178
+ sh "cd #{path} && tmux new -d -s app 'foreman start -c #{processes}; zsh'"
191
179
  end
192
180
 
193
181
  define_macro :app_stop do
194
182
  sh 'tmux kill-session -t app'
195
183
  end
196
184
 
197
- define_macro :www_start do |app_path, www_pid_path|
198
- condition { no_file? [app_path, www_pid_path].join('/') }
185
+ define_macro :www_start do |path, www_pid_path|
186
+ condition { no_file? [path, www_pid_path].join('/') }
199
187
 
200
- sh "cd #{app_path} && bundle exec unicorn -c config/unicorn.rb -D"
188
+ sh "cd #{path} && bundle exec unicorn -c config/unicorn.rb -D"
201
189
  end
202
190
 
203
- define_macro :www_reload do |app_path, www_pid_path|
204
- sh "kill -HUP $(cat #{app_path}/#{www_pid_path})"
191
+ define_macro :www_reload do |path, www_pid_path|
192
+ sh "kill -HUP $(cat #{path}/#{www_pid_path})"
205
193
  end
206
194
 
207
- define_macro :www_stop do |app_path, www_pid_path|
208
- condition { file? [app_path, www_pid_path].join('/') }
195
+ define_macro :www_stop do |path, www_pid_path|
196
+ pid_path = [path, www_pid_path].join '/'
197
+
198
+ condition { file? pid_path }
209
199
 
210
- sh "kill -QUIT $(cat #{app_path}/#{www_pid_path}); sleep 1"
200
+ sh "kill -QUIT $(cat #{pid_path}); while [ -f #{pid_path} ]; do sleep 0.1; done"
211
201
  end
212
202
  end
213
203
  end
@@ -1,5 +1,5 @@
1
1
  module Producer
2
2
  module Rails
3
- VERSION = '0.1.1'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
5
5
  end
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.add_development_dependency 'aruba', '~> 0.6'
21
21
  s.add_development_dependency 'cucumber', '~> 2.0'
22
- s.add_development_dependency 'cucumber-sshd', '~> 0.2'
22
+ s.add_development_dependency 'cucumber-sshd', '~> 1.1'
23
23
  s.add_development_dependency 'rake', '~> 10.4'
24
24
  s.add_development_dependency 'rails', '~> 4.2'
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: producer-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibault Jouan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-05 00:00:00.000000000 Z
11
+ date: 2015-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: producer-core
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0.2'
75
+ version: '1.1'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0.2'
82
+ version: '1.1'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -116,10 +116,20 @@ extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
118
  - ".gitignore"
119
+ - ".travis.yml"
119
120
  - Gemfile
121
+ - Guardfile
122
+ - LICENSE
123
+ - README.md
120
124
  - Rakefile
125
+ - features/arguments.feature
121
126
  - features/deploy_init.feature
122
- - features/steps/rails_steps.rb
127
+ - features/deploy_restart.feature
128
+ - features/deploy_start.feature
129
+ - features/deploy_stop.feature
130
+ - features/deploy_update.feature
131
+ - features/steps/deploy_steps.rb
132
+ - features/steps/repository_steps.rb
123
133
  - features/support/env.rb
124
134
  - lib/producer/rails.rb
125
135
  - lib/producer/rails/version.rb
@@ -148,4 +158,3 @@ signing_key:
148
158
  specification_version: 4
149
159
  summary: producer rails addon
150
160
  test_files: []
151
- has_rdoc:
@@ -1,10 +0,0 @@
1
- Given /^a rails app repository in remote directory "([^"]+)"$/ do |dir|
2
- in_current_dir do
3
- [
4
- "rails new --database=postgresql --skip-bundle #{dir} > /dev/null",
5
- "git -C #{dir} init > /dev/null",
6
- "git -C #{dir} add . > /dev/null",
7
- "git -C #{dir} commit -m 'Add generated rails app' > /dev/null"
8
- ].each { |cmd| fail unless system cmd }
9
- end
10
- end