heroploy 0.0.7.beta.2 → 0.0.7.beta.3
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 +4 -4
- data/.travis.yml +1 -1
- data/README.md +2 -2
- data/Rakefile +6 -0
- data/features/check_tasks.feature +33 -0
- data/features/config_variables.feature +25 -0
- data/features/database_tasks.feature +28 -0
- data/features/deploy_tasks.feature +11 -0
- data/features/local_tasks.feature +10 -0
- data/features/steps/environment_steps.rb +98 -0
- data/features/support/env.rb +30 -0
- data/heroploy.gemspec +1 -0
- data/lib/heroploy/commands/heroku.rb +12 -4
- data/lib/heroploy/commands/rails.rb +15 -0
- data/lib/heroploy/tasks/env_task_lib.rb +39 -9
- data/lib/heroploy/version.rb +1 -1
- data/lib/heroploy.rb +1 -1
- data/spec/lib/heroploy/commands/heroku_spec.rb +21 -7
- data/spec/lib/heroploy/commands/rails_spec.rb +23 -0
- data/spec/lib/heroploy/tasks/db_spec.rb +44 -0
- data/spec/lib/heroploy/tasks/run_spec.rb +20 -0
- data/spec/spec_helper.rb +0 -1
- data/spec/support/shared_contexts/rake.rb +51 -30
- data/{spec → test}/factories.rb +17 -8
- metadata +39 -7
- data/lib/heroploy/config/var_reader.rb +0 -37
- data/spec/lib/heroploy/config/var_reader_spec.rb +0 -67
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6103a1641de18d652d573743069402de4e24791
|
4
|
+
data.tar.gz: b742b6eb75f47e99883975cbb3bd39413e044ade
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cacb1cde260230ac3c1b1c37d281aeeebe1f4d237194bfd3ee7ea3e0677153812a8f16a79e3b1d0579f0d45e208161c0ecc9a872ff7810181af9a51552dedba
|
7
|
+
data.tar.gz: 4f60d0b01c9ac2d5374c99ae06a54be7792011a97bd58868b3c965f54638386b026d97235fa0bdee38319e9d92b51158de320d13ccca054f20512a6da482f227
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
[](https://codeclimate.com/github/jbrunton/heroploy)
|
6
6
|
[](https://coveralls.io/r/jbrunton/heroploy?branch=master)
|
7
7
|
|
8
|
-
A few helpful rake tasks to
|
8
|
+
A few helpful rake tasks to automate configuring and deploying to Heroku apps.
|
9
9
|
|
10
10
|
## Installation
|
11
11
|
|
@@ -23,7 +23,7 @@ Or install it yourself as:
|
|
23
23
|
|
24
24
|
## Usage
|
25
25
|
|
26
|
-
**See [
|
26
|
+
**See the [documentation](https://github.com/jbrunton/heroploy/wiki/) for a more detailed description of the options available for configuring and deploying with Heroploy.**
|
27
27
|
|
28
28
|
|
29
29
|
Add a ```heroploy.yml``` file to your application's config directory which describes the Heroku apps you will deploy to, and the checks you would like when deploying to each.
|
data/Rakefile
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
Feature: Deployment checks
|
2
|
+
|
3
|
+
Scenario: Failing build check
|
4
|
+
|
5
|
+
Given a staging environment
|
6
|
+
When the travis build is failing
|
7
|
+
And I have "master" checked out
|
8
|
+
And I run "staging:deploy"
|
9
|
+
Then the task should fail with "Failing Travis build for branch master"
|
10
|
+
|
11
|
+
Scenario: Failing branch check
|
12
|
+
|
13
|
+
Given a staging environment
|
14
|
+
When I have "my-development-branch" checked out
|
15
|
+
And I run "staging:deploy"
|
16
|
+
Then the task should fail with "Cannot deploy branch my-development-branch to staging"
|
17
|
+
|
18
|
+
Scenario: Failing remote check
|
19
|
+
|
20
|
+
Given a staging environment
|
21
|
+
When I have "master" checked out
|
22
|
+
And my branch is ahead of origin
|
23
|
+
And I run "staging:deploy"
|
24
|
+
Then the task should fail with "Branch master is behind origin/master"
|
25
|
+
|
26
|
+
Scenario: Failing staged check
|
27
|
+
|
28
|
+
Given a production environment
|
29
|
+
And a staging environment
|
30
|
+
When I have "master" checked out
|
31
|
+
And my branch is ahead of staging
|
32
|
+
And I run "production:deploy"
|
33
|
+
Then the task should fail with "Changes not yet staged on staging"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
Feature: Config variables
|
2
|
+
|
3
|
+
Scenario: Set config variables
|
4
|
+
|
5
|
+
Given a development environment with variables:
|
6
|
+
"""
|
7
|
+
foo: bar
|
8
|
+
"""
|
9
|
+
When I run "development:config"
|
10
|
+
Then heroploy should execute "heroku config:set foo=bar --app my-development-app"
|
11
|
+
|
12
|
+
Scenario: Set shared config variables
|
13
|
+
|
14
|
+
Given a development environment with variables:
|
15
|
+
"""
|
16
|
+
foo: bar
|
17
|
+
"""
|
18
|
+
And a shared environment with variables:
|
19
|
+
"""
|
20
|
+
fizz: buzz
|
21
|
+
"""
|
22
|
+
When I run "development:config"
|
23
|
+
Then heroploy should execute "heroku config:set fizz=buzz foo=bar --app my-development-app"
|
24
|
+
|
25
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
Feature: Database tasks
|
2
|
+
|
3
|
+
Scenario: db:migrate
|
4
|
+
|
5
|
+
Given a production environment
|
6
|
+
When I run "production:db:migrate"
|
7
|
+
Then heroploy should execute "heroku run rake db:migrate --app my-production-app"
|
8
|
+
|
9
|
+
Scenario: db:reset
|
10
|
+
|
11
|
+
Given a production environment
|
12
|
+
When I run "production:db:reset"
|
13
|
+
Then heroploy should execute "heroku pg:reset DATABASE --confirm my-production-app --app my-production-app"
|
14
|
+
|
15
|
+
Scenario: db:seed
|
16
|
+
|
17
|
+
Given a production environment
|
18
|
+
When I run "production:db:seed"
|
19
|
+
Then heroploy should execute "heroku run rake db:seed --app my-production-app"
|
20
|
+
|
21
|
+
Scenario: db:recreate
|
22
|
+
|
23
|
+
Given a production environment
|
24
|
+
When I run "production:db:recreate"
|
25
|
+
Then heroploy should invoke "production:db:reset"
|
26
|
+
And heroploy should invoke "production:db:migrate"
|
27
|
+
And heroploy should invoke "production:db:seed"
|
28
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Feature: Deployment tasks
|
2
|
+
|
3
|
+
Scenario: Successful deployment
|
4
|
+
|
5
|
+
Given a development environment
|
6
|
+
When I run "development:deploy"
|
7
|
+
Then heroploy should invoke "development:check:all"
|
8
|
+
And heroploy should invoke "development:push"
|
9
|
+
And heroploy should invoke "development:config"
|
10
|
+
And heroploy should invoke "development:db:migrate"
|
11
|
+
And heroploy should invoke "development:tag"
|
@@ -0,0 +1,98 @@
|
|
1
|
+
def define_environment(env_type)
|
2
|
+
@environments ||= []
|
3
|
+
environment = build(:environment, env_type.to_sym)
|
4
|
+
@environments << environment
|
5
|
+
environment
|
6
|
+
end
|
7
|
+
|
8
|
+
Given(/^a (local|development|staging|production) environment$/) do |env_type|
|
9
|
+
define_environment(env_type)
|
10
|
+
end
|
11
|
+
|
12
|
+
Given(/^a (local|development|staging|production) environment with variables:$/) do |env_type, variables|
|
13
|
+
environment = define_environment(env_type)
|
14
|
+
environment.variables = YAML::load(variables) unless variables.nil?
|
15
|
+
end
|
16
|
+
|
17
|
+
Given(/^a shared environment with variables:$/) do |variables|
|
18
|
+
@shared_env = build(:shared_env, variables: YAML::load(variables))
|
19
|
+
end
|
20
|
+
|
21
|
+
def init_tasks
|
22
|
+
@shared_env ||= build(:shared_env)
|
23
|
+
deployment_config = build(:deployment_config, environments: @environments, shared_env: @shared_env)
|
24
|
+
Heroploy::Tasks::DeployTaskLib.new(deployment_config)
|
25
|
+
end
|
26
|
+
|
27
|
+
def stub_tasks
|
28
|
+
Rake::Task.tasks.each do |task|
|
29
|
+
allow(task).to receive(:execute).and_call_original
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def stub_travis
|
34
|
+
@travis_repo = build(:travis_repo)
|
35
|
+
Travis::Repository.stub(:find).and_return(@travis_repo)
|
36
|
+
|
37
|
+
@travis_build ||= build(:travis_build, :passed)
|
38
|
+
allow(@travis_repo).to receive(:branch).and_return(@travis_build)
|
39
|
+
end
|
40
|
+
|
41
|
+
When(/^I run "(.*?)"$/) do |task_name|
|
42
|
+
init_tasks
|
43
|
+
stub_travis
|
44
|
+
stub_tasks
|
45
|
+
|
46
|
+
begin
|
47
|
+
Rake::Task[task_name].invoke
|
48
|
+
rescue => error
|
49
|
+
@error = error
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
Then(/^heroploy should execute "(.*?)"$/) do |command|
|
54
|
+
expect(Heroploy::Shell).
|
55
|
+
to have_received(:exec).
|
56
|
+
with(command)
|
57
|
+
end
|
58
|
+
|
59
|
+
Then(/^heroploy should invoke "(.*?)"$/) do |task_name|
|
60
|
+
expect(Rake::Task[task_name]).
|
61
|
+
to have_received(:execute)
|
62
|
+
end
|
63
|
+
|
64
|
+
When(/^I have "(.*?)" checked out$/) do |branch_name|
|
65
|
+
@branch_name = branch_name
|
66
|
+
allow_any_instance_of(Heroploy::Tasks::CheckTaskLib).
|
67
|
+
to receive(:current_branch).
|
68
|
+
and_return(branch_name)
|
69
|
+
end
|
70
|
+
|
71
|
+
Given(/^the travis build is failing$/) do
|
72
|
+
@travis_build = build(:travis_build, :failed)
|
73
|
+
end
|
74
|
+
|
75
|
+
Then(/^the task should fail with "(.*?)"$/) do |expected_error|
|
76
|
+
unless @error.to_s == expected_error
|
77
|
+
if @error.nil?
|
78
|
+
raise "Expected failure with message '#{expected_error}' while executing task, but execution was successful"
|
79
|
+
else
|
80
|
+
puts "Expected failure with message '#{expected_error}' while executing task, but encountered:"
|
81
|
+
raise @error
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
When(/^my branch is ahead of origin$/) do
|
87
|
+
allow_any_instance_of(Heroploy::Tasks::CheckTaskLib).
|
88
|
+
to receive(:git_remote_behind?).
|
89
|
+
with('origin', @branch_name).
|
90
|
+
and_return(true)
|
91
|
+
end
|
92
|
+
|
93
|
+
When(/^my branch is ahead of staging$/) do
|
94
|
+
allow_any_instance_of(Heroploy::Tasks::CheckTaskLib).
|
95
|
+
to receive(:git_remote_behind?).
|
96
|
+
with('staging', 'master', @branch_name).
|
97
|
+
and_return(true)
|
98
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'heroploy'
|
2
|
+
require 'factory_girl'
|
3
|
+
require 'travis'
|
4
|
+
|
5
|
+
require 'cucumber/rspec/doubles'
|
6
|
+
|
7
|
+
require 'heroploy/config/deployment_config'
|
8
|
+
require 'heroploy/tasks/deploy_task_lib'
|
9
|
+
|
10
|
+
FactoryGirl.find_definitions
|
11
|
+
|
12
|
+
World(FactoryGirl::Syntax::Methods)
|
13
|
+
|
14
|
+
Before do
|
15
|
+
allow(Heroploy::Shell).to receive(:eval).and_return("")
|
16
|
+
allow(Heroploy::Shell).to receive(:exec)
|
17
|
+
|
18
|
+
allow_any_instance_of(Heroploy::Tasks::CheckTaskLib).to receive(:git_remote_exists?).
|
19
|
+
and_return(true)
|
20
|
+
|
21
|
+
allow_any_instance_of(Heroploy::Tasks::CheckTaskLib).to receive(:git_remote_has_branch?).
|
22
|
+
and_return(true)
|
23
|
+
|
24
|
+
allow_any_instance_of(Heroploy::Tasks::CheckTaskLib).to receive(:git_remote_behind?).
|
25
|
+
and_return(false)
|
26
|
+
|
27
|
+
Rake::Task.clear
|
28
|
+
end
|
29
|
+
|
30
|
+
|
data/heroploy.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "rake"
|
24
24
|
spec.add_development_dependency "rails"
|
25
25
|
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "cucumber"
|
26
27
|
spec.add_development_dependency "factory_girl"
|
27
28
|
spec.add_development_dependency "generator_spec"
|
28
29
|
spec.add_development_dependency "coveralls"
|
@@ -13,15 +13,23 @@ module Heroploy
|
|
13
13
|
heroku_exec("run #{cmd}", app_name)
|
14
14
|
end
|
15
15
|
|
16
|
-
def heroku_migrate(app_name)
|
17
|
-
heroku_run("rake db:migrate", app_name)
|
18
|
-
end
|
19
|
-
|
20
16
|
def heroku_config_set(shared_vars, env_vars, app_name)
|
21
17
|
merged_vars = shared_vars.merge(env_vars)
|
22
18
|
vars_string = merged_vars.collect.map{|key,value| "#{key}=#{value}"}.join(" ")
|
23
19
|
heroku_exec("config:set #{vars_string}", app_name)
|
24
20
|
end
|
21
|
+
|
22
|
+
def heroku_db_migrate(app_name)
|
23
|
+
heroku_run("rake db:migrate", app_name)
|
24
|
+
end
|
25
|
+
|
26
|
+
def heroku_db_reset(app_name)
|
27
|
+
heroku_exec("pg:reset DATABASE --confirm #{app_name}", app_name)
|
28
|
+
end
|
29
|
+
|
30
|
+
def heroku_db_seed(app_name)
|
31
|
+
heroku_run("rake db:seed", app_name)
|
32
|
+
end
|
25
33
|
end
|
26
34
|
end
|
27
35
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'heroploy/commands/shell'
|
2
|
+
|
3
|
+
module Heroploy
|
4
|
+
module Commands
|
5
|
+
module Rails
|
6
|
+
def rails_server(shared_vars, env_vars)
|
7
|
+
merged_vars = shared_vars.merge(env_vars)
|
8
|
+
vars_string = merged_vars.collect.map{|key,value| "#{key}=#{value}"}.join(" ")
|
9
|
+
cmd = "bundle exec rails s"
|
10
|
+
cmd = "#{vars_string} #{cmd}" unless vars_string.empty?
|
11
|
+
Shell.exec cmd
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -3,6 +3,7 @@ require 'rake/tasklib'
|
|
3
3
|
require 'heroploy/commands/heroku'
|
4
4
|
require 'heroploy/commands/git'
|
5
5
|
require 'heroploy/commands/checks'
|
6
|
+
require 'heroploy/commands/rails'
|
6
7
|
|
7
8
|
require 'heroploy/tasks/check_task_lib'
|
8
9
|
|
@@ -14,6 +15,7 @@ module Heroploy
|
|
14
15
|
include Commands::Git
|
15
16
|
include Commands::Heroku
|
16
17
|
include Commands::Checks
|
18
|
+
include Commands::Rails
|
17
19
|
|
18
20
|
attr_accessor :deployment_config
|
19
21
|
attr_accessor :env
|
@@ -26,9 +28,20 @@ module Heroploy
|
|
26
28
|
|
27
29
|
def define
|
28
30
|
namespace env.name do
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
if env.name == 'local'
|
32
|
+
define_run_task
|
33
|
+
else
|
34
|
+
define_check_tasks
|
35
|
+
define_git_tasks
|
36
|
+
define_db_tasks
|
37
|
+
define_heroku_tasks
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def define_run_task
|
43
|
+
task :run do
|
44
|
+
rails_server(deployment_config.shared_env.variables, env.variables)
|
32
45
|
end
|
33
46
|
end
|
34
47
|
|
@@ -53,20 +66,37 @@ module Heroploy
|
|
53
66
|
end
|
54
67
|
end
|
55
68
|
end
|
69
|
+
|
70
|
+
def define_db_tasks
|
71
|
+
namespace :db do
|
72
|
+
desc "run database migrations on #{env.name}"
|
73
|
+
task :migrate do
|
74
|
+
heroku_db_migrate(env.app)
|
75
|
+
end
|
76
|
+
|
77
|
+
desc "reset the database on #{env.name}"
|
78
|
+
task :reset do
|
79
|
+
heroku_db_reset(env.app)
|
80
|
+
end
|
81
|
+
|
82
|
+
desc "seed the database on #{env.name}"
|
83
|
+
task :seed do
|
84
|
+
heroku_db_seed(env.app)
|
85
|
+
end
|
86
|
+
|
87
|
+
desc "reset, migrate and seed the database"
|
88
|
+
task :recreate => [:reset, :migrate, :seed]
|
89
|
+
end
|
90
|
+
end
|
56
91
|
|
57
92
|
def define_heroku_tasks
|
58
|
-
desc "run database migrations on #{env.name}"
|
59
|
-
task :migrate do
|
60
|
-
heroku_migrate(env.app)
|
61
|
-
end
|
62
|
-
|
63
93
|
desc "set config variables"
|
64
94
|
task :config => :load_remote_configs do
|
65
95
|
heroku_config_set(deployment_config.shared_env.variables, env.variables, env.app)
|
66
96
|
end
|
67
97
|
|
68
98
|
desc "deploy to #{env.name}"
|
69
|
-
task :deploy => ['check:all', :push, :config, :migrate, :tag]
|
99
|
+
task :deploy => ['check:all', :push, :config, 'db:migrate', :tag]
|
70
100
|
end
|
71
101
|
end
|
72
102
|
end
|
data/lib/heroploy/version.rb
CHANGED
data/lib/heroploy.rb
CHANGED
@@ -21,13 +21,6 @@ describe Heroploy::Commands::Heroku do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
context "#heroku_migrate" do
|
25
|
-
it "runs rake db:migrate on the heroku server" do
|
26
|
-
expect_command("heroku run rake db:migrate --app my-app")
|
27
|
-
commands.heroku_migrate("my-app")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
24
|
context "#heroku_config_set" do
|
32
25
|
it "sets the values for the given config variables" do
|
33
26
|
common_vars = {'foo' => 'foo'}
|
@@ -36,4 +29,25 @@ describe Heroploy::Commands::Heroku do
|
|
36
29
|
commands.heroku_config_set(common_vars, env_vars, "my-app")
|
37
30
|
end
|
38
31
|
end
|
32
|
+
|
33
|
+
context "#heroku_db_migrate" do
|
34
|
+
it "runs rake db:migrate on the heroku server" do
|
35
|
+
expect_command("heroku run rake db:migrate --app my-app")
|
36
|
+
commands.heroku_db_migrate("my-app")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#heroku_db_reset" do
|
41
|
+
it "resets the database for the given app" do
|
42
|
+
expect_command("heroku pg:reset DATABASE --confirm my-app --app my-app")
|
43
|
+
commands.heroku_db_reset("my-app")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#heroku_db_seed" do
|
48
|
+
it "seeds the database for the given app" do
|
49
|
+
expect_command("heroku run rake db:seed --app my-app")
|
50
|
+
commands.heroku_db_seed("my-app")
|
51
|
+
end
|
52
|
+
end
|
39
53
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Heroploy::Commands::Rails do
|
4
|
+
before(:each) do
|
5
|
+
stub_shell
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:commands) { Object.new.extend(Heroploy::Commands::Rails) }
|
9
|
+
|
10
|
+
describe "#rails_server" do
|
11
|
+
it "starts a rails server" do
|
12
|
+
expect_command("bundle exec rails s")
|
13
|
+
commands.rails_server({}, {})
|
14
|
+
end
|
15
|
+
|
16
|
+
it "passes the given variables to the rails environment" do
|
17
|
+
local_variables = {'foo' => 'bar'}
|
18
|
+
shared_variables = {'fizz' => 'buzz'}
|
19
|
+
expect_command("fizz=buzz foo=bar bundle exec rails s")
|
20
|
+
commands.rails_server(shared_variables, local_variables)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "db:reset" do
|
4
|
+
let(:environment) { build(:environment, :production) }
|
5
|
+
include_context "rake"
|
6
|
+
|
7
|
+
it "invokes heroku_db_reset" do
|
8
|
+
expect_any_instance_of(Heroploy::Tasks::EnvTaskLib).to receive(:heroku_db_reset)
|
9
|
+
.with("my-production-app")
|
10
|
+
|
11
|
+
task.invoke
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "db:migrate" do
|
16
|
+
let(:environment) { build(:environment, :production) }
|
17
|
+
include_context "rake"
|
18
|
+
|
19
|
+
it "invokes heroku_db_migrate" do
|
20
|
+
expect_any_instance_of(Heroploy::Tasks::EnvTaskLib).to receive(:heroku_db_migrate)
|
21
|
+
.with("my-production-app")
|
22
|
+
|
23
|
+
task.invoke
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "db:seed" do
|
28
|
+
let(:environment) { build(:environment, :production) }
|
29
|
+
include_context "rake"
|
30
|
+
|
31
|
+
it "invokes heroku_db_seed" do
|
32
|
+
expect_any_instance_of(Heroploy::Tasks::EnvTaskLib).to receive(:heroku_db_seed)
|
33
|
+
.with("my-production-app")
|
34
|
+
|
35
|
+
task.invoke
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "db:recreate" do
|
40
|
+
let(:environment) { build(:environment, :production) }
|
41
|
+
include_context "rake"
|
42
|
+
|
43
|
+
its(:prerequisites) { should eq ['reset', 'migrate', 'seed'] }
|
44
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "run" do
|
4
|
+
let(:local_variables) { {'foo' => 'bar'} }
|
5
|
+
let(:shared_variables) { {'fizz' => 'buzz'} }
|
6
|
+
|
7
|
+
let(:shared_env) { build(:shared_env, variables: shared_variables) }
|
8
|
+
let(:local_env) { build(:environment, :local, variables: local_variables) }
|
9
|
+
|
10
|
+
let(:deployment_config) { build(:deployment_config, shared_env: shared_env, environments: [local_env]) }
|
11
|
+
|
12
|
+
include_context "rake"
|
13
|
+
|
14
|
+
it "invokes rails_server" do
|
15
|
+
expect_any_instance_of(Heroploy::Tasks::EnvTaskLib).to receive(:rails_server)
|
16
|
+
.with(shared_variables, local_variables)
|
17
|
+
|
18
|
+
task.invoke
|
19
|
+
end
|
20
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -15,7 +15,6 @@ require 'heroploy/tasks/deploy_task_lib'
|
|
15
15
|
require 'heroploy/config/deployment_config'
|
16
16
|
require 'heroploy/config/environment'
|
17
17
|
require 'heroploy/config/environment_checks'
|
18
|
-
require 'heroploy/config/var_reader'
|
19
18
|
|
20
19
|
require 'support/shell_support'
|
21
20
|
require 'support/shared_contexts/rake'
|
@@ -5,43 +5,64 @@
|
|
5
5
|
require "rake"
|
6
6
|
|
7
7
|
shared_context "rake" do
|
8
|
-
let(:task_name) {
|
9
|
-
if defined?(environment)
|
10
|
-
env_name = environment.name
|
11
|
-
elsif defined?(environments)
|
12
|
-
env_name = environments[0].name
|
13
|
-
else
|
14
|
-
env_name = deployment_config.environments[0].name
|
15
|
-
end
|
16
|
-
|
17
|
-
"#{env_name}:#{self.class.top_level_description}"
|
18
|
-
}
|
19
|
-
|
20
|
-
let(:task) { Rake::Task[task_name] }
|
21
|
-
|
22
8
|
subject { task }
|
23
|
-
|
9
|
+
let(:task) { Rake::Task[task_name] }
|
10
|
+
let(:task_name) { build_task_name }
|
11
|
+
|
24
12
|
before(:each) do
|
13
|
+
reset_rake_environment
|
14
|
+
create_deployment_tasks
|
15
|
+
stub_rake_tasks
|
16
|
+
stub_shell
|
17
|
+
end
|
18
|
+
|
19
|
+
def reset_rake_environment
|
25
20
|
Rake::Task.clear
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
deployment_config = build(:deployment_config)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
Heroploy::Tasks::DeployTaskLib.new(deployment_config)
|
38
|
-
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_deployment_tasks
|
24
|
+
Heroploy::Tasks::DeployTaskLib.new(build_deployment_config)
|
25
|
+
end
|
26
|
+
|
27
|
+
def stub_rake_tasks
|
39
28
|
Rake::Task.tasks.each do |task|
|
40
29
|
if task.name != task_name
|
41
30
|
task.stub(:execute)
|
42
31
|
end
|
43
32
|
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def build_environments
|
36
|
+
if defined?(environment)
|
37
|
+
[environment]
|
38
|
+
elsif defined?(environments)
|
39
|
+
environments
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def build_deployment_config
|
44
|
+
if defined?(deployment_config)
|
45
|
+
deployment_config
|
46
|
+
else
|
47
|
+
environments = build_environments
|
48
|
+
|
49
|
+
if environments.nil?
|
50
|
+
build(:deployment_config)
|
51
|
+
else
|
52
|
+
build(:deployment_config, environments: environments)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def build_task_name
|
58
|
+
if defined?(environment)
|
59
|
+
env_name = environment.name
|
60
|
+
elsif defined?(environments)
|
61
|
+
env_name = environments[0].name
|
62
|
+
else
|
63
|
+
env_name = deployment_config.environments[0].name
|
64
|
+
end
|
44
65
|
|
45
|
-
|
46
|
-
end
|
66
|
+
"#{env_name}:#{self.class.top_level_description}"
|
67
|
+
end
|
47
68
|
end
|
data/{spec → test}/factories.rb
RENAMED
@@ -5,11 +5,13 @@ FactoryGirl.define do
|
|
5
5
|
branch nil
|
6
6
|
travis false
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
[:local, :development].each do |t|
|
9
|
+
trait t do
|
10
|
+
pushed false
|
11
|
+
staged false
|
12
|
+
branch nil
|
13
|
+
travis false
|
14
|
+
end
|
13
15
|
end
|
14
16
|
|
15
17
|
trait :staging do
|
@@ -21,7 +23,7 @@ FactoryGirl.define do
|
|
21
23
|
|
22
24
|
trait :production do
|
23
25
|
pushed true
|
24
|
-
staged
|
26
|
+
staged 'staging'
|
25
27
|
branch 'master'
|
26
28
|
travis true
|
27
29
|
end
|
@@ -29,10 +31,16 @@ FactoryGirl.define do
|
|
29
31
|
|
30
32
|
factory :environment, :class => Heroploy::Config::Environment do
|
31
33
|
checks { build(:environment_checks) }
|
34
|
+
variables { {} }
|
35
|
+
|
36
|
+
trait :local do
|
37
|
+
name 'local'
|
38
|
+
end
|
32
39
|
|
33
40
|
[:development, :staging, :production].each do |t|
|
34
41
|
trait t do
|
35
42
|
name t.to_s
|
43
|
+
app "my-#{t.to_s}-app"
|
36
44
|
remote t.to_s
|
37
45
|
checks { build(:environment_checks, t) }
|
38
46
|
end
|
@@ -41,16 +49,17 @@ FactoryGirl.define do
|
|
41
49
|
|
42
50
|
factory :shared_env, :class => Heroploy::Config::SharedEnv do
|
43
51
|
required []
|
44
|
-
variables {}
|
52
|
+
variables { {} }
|
45
53
|
end
|
46
54
|
|
47
55
|
factory :deployment_config, :class => Heroploy::Config::DeploymentConfig do
|
48
56
|
travis_repo "my-travis-user/my-travis-repo"
|
49
57
|
|
50
|
-
shared_env
|
58
|
+
shared_env { build(:shared_env) }
|
51
59
|
|
52
60
|
environments {
|
53
61
|
[
|
62
|
+
build(:environment, :local),
|
54
63
|
build(:environment, :development),
|
55
64
|
build(:environment, :staging),
|
56
65
|
build(:environment, :production)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heroploy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.7.beta.
|
4
|
+
version: 0.0.7.beta.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Brunton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: cucumber
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: factory_girl
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,6 +151,13 @@ files:
|
|
137
151
|
- LICENSE.txt
|
138
152
|
- README.md
|
139
153
|
- Rakefile
|
154
|
+
- features/check_tasks.feature
|
155
|
+
- features/config_variables.feature
|
156
|
+
- features/database_tasks.feature
|
157
|
+
- features/deploy_tasks.feature
|
158
|
+
- features/local_tasks.feature
|
159
|
+
- features/steps/environment_steps.rb
|
160
|
+
- features/support/env.rb
|
140
161
|
- heroploy.gemspec
|
141
162
|
- lib/generators/heroploy/install/USAGE
|
142
163
|
- lib/generators/heroploy/install/install_generator.rb
|
@@ -145,13 +166,13 @@ files:
|
|
145
166
|
- lib/heroploy/commands/checks.rb
|
146
167
|
- lib/heroploy/commands/git.rb
|
147
168
|
- lib/heroploy/commands/heroku.rb
|
169
|
+
- lib/heroploy/commands/rails.rb
|
148
170
|
- lib/heroploy/commands/shell.rb
|
149
171
|
- lib/heroploy/config/deployment_config.rb
|
150
172
|
- lib/heroploy/config/environment.rb
|
151
173
|
- lib/heroploy/config/environment_checks.rb
|
152
174
|
- lib/heroploy/config/remote_config.rb
|
153
175
|
- lib/heroploy/config/shared_env.rb
|
154
|
-
- lib/heroploy/config/var_reader.rb
|
155
176
|
- lib/heroploy/engine.rb
|
156
177
|
- lib/heroploy/tasks/check_task_lib.rb
|
157
178
|
- lib/heroploy/tasks/deploy_task_lib.rb
|
@@ -159,18 +180,17 @@ files:
|
|
159
180
|
- lib/heroploy/tasks/env_var_task_lib.rb
|
160
181
|
- lib/heroploy/tasks/tasks.rake
|
161
182
|
- lib/heroploy/version.rb
|
162
|
-
- spec/factories.rb
|
163
183
|
- spec/lib/generators/heroploy/install_generator_spec.rb
|
164
184
|
- spec/lib/heroploy/commands/checks_spec.rb
|
165
185
|
- spec/lib/heroploy/commands/git_spec.rb
|
166
186
|
- spec/lib/heroploy/commands/heroku_spec.rb
|
187
|
+
- spec/lib/heroploy/commands/rails_spec.rb
|
167
188
|
- spec/lib/heroploy/commands/shell_spec.rb
|
168
189
|
- spec/lib/heroploy/config/deployment_config_spec.rb
|
169
190
|
- spec/lib/heroploy/config/environment_checks_spec.rb
|
170
191
|
- spec/lib/heroploy/config/environment_spec.rb
|
171
192
|
- spec/lib/heroploy/config/remote_config_spec.rb
|
172
193
|
- spec/lib/heroploy/config/shared_env_spec.rb
|
173
|
-
- spec/lib/heroploy/config/var_reader_spec.rb
|
174
194
|
- spec/lib/heroploy/tasks/check_all_spec.rb
|
175
195
|
- spec/lib/heroploy/tasks/check_branch_spec.rb
|
176
196
|
- spec/lib/heroploy/tasks/check_config_spec.rb
|
@@ -178,12 +198,15 @@ files:
|
|
178
198
|
- spec/lib/heroploy/tasks/check_remote_spec.rb
|
179
199
|
- spec/lib/heroploy/tasks/check_staged_spec.rb
|
180
200
|
- spec/lib/heroploy/tasks/check_travis_spec.rb
|
201
|
+
- spec/lib/heroploy/tasks/db_spec.rb
|
202
|
+
- spec/lib/heroploy/tasks/run_spec.rb
|
181
203
|
- spec/spec_helper.rb
|
182
204
|
- spec/support/customer_matchers/environment_matcher.rb
|
183
205
|
- spec/support/helpers/deploy_config_helper.rb
|
184
206
|
- spec/support/shared_contexts/generator.rb
|
185
207
|
- spec/support/shared_contexts/rake.rb
|
186
208
|
- spec/support/shell_support.rb
|
209
|
+
- test/factories.rb
|
187
210
|
homepage: ''
|
188
211
|
licenses:
|
189
212
|
- MIT
|
@@ -209,18 +232,24 @@ signing_key:
|
|
209
232
|
specification_version: 4
|
210
233
|
summary: Helpful rake tasks for deploying to Heroku
|
211
234
|
test_files:
|
212
|
-
-
|
235
|
+
- features/check_tasks.feature
|
236
|
+
- features/config_variables.feature
|
237
|
+
- features/database_tasks.feature
|
238
|
+
- features/deploy_tasks.feature
|
239
|
+
- features/local_tasks.feature
|
240
|
+
- features/steps/environment_steps.rb
|
241
|
+
- features/support/env.rb
|
213
242
|
- spec/lib/generators/heroploy/install_generator_spec.rb
|
214
243
|
- spec/lib/heroploy/commands/checks_spec.rb
|
215
244
|
- spec/lib/heroploy/commands/git_spec.rb
|
216
245
|
- spec/lib/heroploy/commands/heroku_spec.rb
|
246
|
+
- spec/lib/heroploy/commands/rails_spec.rb
|
217
247
|
- spec/lib/heroploy/commands/shell_spec.rb
|
218
248
|
- spec/lib/heroploy/config/deployment_config_spec.rb
|
219
249
|
- spec/lib/heroploy/config/environment_checks_spec.rb
|
220
250
|
- spec/lib/heroploy/config/environment_spec.rb
|
221
251
|
- spec/lib/heroploy/config/remote_config_spec.rb
|
222
252
|
- spec/lib/heroploy/config/shared_env_spec.rb
|
223
|
-
- spec/lib/heroploy/config/var_reader_spec.rb
|
224
253
|
- spec/lib/heroploy/tasks/check_all_spec.rb
|
225
254
|
- spec/lib/heroploy/tasks/check_branch_spec.rb
|
226
255
|
- spec/lib/heroploy/tasks/check_config_spec.rb
|
@@ -228,10 +257,13 @@ test_files:
|
|
228
257
|
- spec/lib/heroploy/tasks/check_remote_spec.rb
|
229
258
|
- spec/lib/heroploy/tasks/check_staged_spec.rb
|
230
259
|
- spec/lib/heroploy/tasks/check_travis_spec.rb
|
260
|
+
- spec/lib/heroploy/tasks/db_spec.rb
|
261
|
+
- spec/lib/heroploy/tasks/run_spec.rb
|
231
262
|
- spec/spec_helper.rb
|
232
263
|
- spec/support/customer_matchers/environment_matcher.rb
|
233
264
|
- spec/support/helpers/deploy_config_helper.rb
|
234
265
|
- spec/support/shared_contexts/generator.rb
|
235
266
|
- spec/support/shared_contexts/rake.rb
|
236
267
|
- spec/support/shell_support.rb
|
268
|
+
- test/factories.rb
|
237
269
|
has_rdoc:
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'heroploy/config/deployment_config'
|
2
|
-
|
3
|
-
module Heroploy
|
4
|
-
module Config
|
5
|
-
class VarReader
|
6
|
-
attr_accessor :deployment_config
|
7
|
-
|
8
|
-
def deployment_config
|
9
|
-
@deployment_config ||= begin
|
10
|
-
config = Heroploy::Config::DeploymentConfig.load
|
11
|
-
config.load_remotes! unless config.nil?
|
12
|
-
config
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def env_matcher_name
|
17
|
-
"Rails.env[#{Rails.env}]"
|
18
|
-
end
|
19
|
-
|
20
|
-
def [](var_name)
|
21
|
-
config_var = ENV[var_name.to_s]
|
22
|
-
config_var ||= begin
|
23
|
-
environment = deployment_config[env_matcher_name]
|
24
|
-
environment.variables[var_name.to_s] unless environment.nil?
|
25
|
-
end
|
26
|
-
config_var ||= begin
|
27
|
-
shared_env = deployment_config.shared_env
|
28
|
-
shared_env.variables[var_name.to_s] unless shared_env.nil?
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.config_vars
|
35
|
-
@config_vars ||= Config::VarReader.new
|
36
|
-
end
|
37
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Heroploy::Config::VarReader do
|
4
|
-
subject(:var_reader) { Heroploy::Config::VarReader.new }
|
5
|
-
|
6
|
-
describe "deployment_config" do
|
7
|
-
let(:expected_config) { build(:deployment_config) }
|
8
|
-
before { allow(Heroploy::Config::DeploymentConfig).to receive(:load).and_return(expected_config) }
|
9
|
-
|
10
|
-
it "loads and returns the deployment config" do
|
11
|
-
expect(var_reader.deployment_config).to eq(expected_config)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "caches the result" do
|
15
|
-
expect(Heroploy::Config::DeploymentConfig).to receive(:load).once
|
16
|
-
var_reader.deployment_config
|
17
|
-
var_reader.deployment_config
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "[]" do
|
22
|
-
context "if an environment variable is defined" do
|
23
|
-
before { allow(ENV).to receive(:[]).with('foo').and_return('bar') }
|
24
|
-
|
25
|
-
it "returns the value of the environment variable" do
|
26
|
-
expect(var_reader[:foo]).to eq('bar')
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context "if an environment matcher is defined" do
|
31
|
-
let(:deployment_config) do
|
32
|
-
build(:deployment_config,
|
33
|
-
:shared_env => build(:shared_env, :variables => {'fizz' => 'buzz'}),
|
34
|
-
:environments => [
|
35
|
-
build(:environment,
|
36
|
-
:name => 'Rails.env[test]',
|
37
|
-
:variables => {'foo' => 'baz'}
|
38
|
-
)
|
39
|
-
]
|
40
|
-
)
|
41
|
-
end
|
42
|
-
|
43
|
-
before do
|
44
|
-
allow(Heroploy::Config::DeploymentConfig).to receive(:load).
|
45
|
-
and_return(deployment_config)
|
46
|
-
|
47
|
-
allow(Rails).to receive(:env).and_return('test')
|
48
|
-
end
|
49
|
-
|
50
|
-
it "returns the variable for the matched environment" do
|
51
|
-
expect(var_reader[:foo]).to eq('baz')
|
52
|
-
end
|
53
|
-
|
54
|
-
it "returns shared environment variables" do
|
55
|
-
expect(var_reader[:fizz]).to eq('buzz')
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context "if no variables are defined" do
|
60
|
-
before { allow(Heroploy::Config::DeploymentConfig).to receive(:load).and_return(build(:deployment_config)) }
|
61
|
-
|
62
|
-
it "returns nil" do
|
63
|
-
expect(var_reader[:foo]).to eq(nil)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|