hanzo 0.5 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/hanzo/modules/deploy.rb +12 -19
- data/lib/hanzo/version.rb +1 -1
- data/spec/cli/deploy_spec.rb +23 -44
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f2163d68dba551ae26f662a1e0feef58ce68189
|
4
|
+
data.tar.gz: 28cd31d65ed3326257f96a45a757a0434d7ddacd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69325cbe09fc4fac847142901acb2c5e144a65dc15546c50095600b78d94c094c0525c5322338784faca7be2a590384c7d526dd10ae664f6a848a9b1d5b08302
|
7
|
+
data.tar.gz: 382cee77dcbd708ccbe8334c7211d5256b132bf06469bc8d32160247e23e84d0890f0538ac79121f90870bfd1d236aea233d87de6ffd1b8e875be8713d1b20ba
|
data/README.md
CHANGED
@@ -25,11 +25,17 @@ gem 'hanzo'
|
|
25
25
|
Create an `.hanzo.yml` file at the root of your app that will contain a map of
|
26
26
|
remotes, with the remote as the key and the Heroku application name as the value.
|
27
27
|
|
28
|
+
You can also specify commands that can be ran on the application after a
|
29
|
+
successful deploy. Hanzo will prompt to run each of them, they each will be ran
|
30
|
+
with `heroku run` and the application will be restarted at the end.
|
31
|
+
|
28
32
|
```yaml
|
29
33
|
remotes:
|
30
34
|
qa: heroku-app-name-qa
|
31
35
|
staging: heroku-app-name-staging
|
32
36
|
production: heroku-app-name-production
|
37
|
+
after_deploy:
|
38
|
+
- rake db:migrate
|
33
39
|
```
|
34
40
|
|
35
41
|
### Install remotes
|
data/lib/hanzo/modules/deploy.rb
CHANGED
@@ -4,12 +4,6 @@ module Hanzo
|
|
4
4
|
UnknownEnvironment = Class.new(StandardError)
|
5
5
|
UninstalledEnvironment = Class.new(StandardError)
|
6
6
|
|
7
|
-
# Constants
|
8
|
-
MIGRATION_COMMANDS = {
|
9
|
-
'db/migrate' => 'rake db:migrate',
|
10
|
-
'priv/repo/migrations' => 'mix ecto.migrate'
|
11
|
-
}
|
12
|
-
|
13
7
|
protected
|
14
8
|
|
15
9
|
def initialize_variables
|
@@ -20,7 +14,7 @@ module Hanzo
|
|
20
14
|
def initialize_cli
|
21
15
|
initialize_help && return if @env.nil?
|
22
16
|
|
23
|
-
deploy &&
|
17
|
+
deploy && run_after_deploy_commands
|
24
18
|
rescue UnknownEnvironment
|
25
19
|
Hanzo.unindent_print "Environment `#{@env}` doesn't exist. Add it to .hanzo.yml and run:\n hanzo install remotes", :red
|
26
20
|
Hanzo.unindent_print "\nFor more information, read https://github.com/mirego/hanzo#install-remotes", :red
|
@@ -48,14 +42,21 @@ module Hanzo
|
|
48
42
|
Hanzo.run "git push -f #{@env} #{branch}:master"
|
49
43
|
end
|
50
44
|
|
51
|
-
def
|
52
|
-
return
|
53
|
-
|
45
|
+
def run_after_deploy_commands
|
46
|
+
return unless after_deploy_commands.any?
|
47
|
+
|
48
|
+
after_deploy_commands.each do |command|
|
49
|
+
next unless Hanzo.agree("Run `#{command}` on #{@env}?")
|
50
|
+
Hanzo.run "heroku run #{command} --remote #{@env}"
|
51
|
+
end
|
54
52
|
|
55
|
-
Hanzo.run "heroku run #{migration_command} --remote #{@env}"
|
56
53
|
Hanzo.run "heroku ps:restart --remote #{@env}"
|
57
54
|
end
|
58
55
|
|
56
|
+
def after_deploy_commands
|
57
|
+
Hanzo.config['after_deploy'] || []
|
58
|
+
end
|
59
|
+
|
59
60
|
def validate_environment_existence!
|
60
61
|
raise UnknownEnvironment unless fetcher.exist?
|
61
62
|
raise UninstalledEnvironment unless fetcher.installed?
|
@@ -64,13 +65,5 @@ module Hanzo
|
|
64
65
|
def fetcher
|
65
66
|
@fetcher ||= Hanzo::Fetchers::Environment.new(@env)
|
66
67
|
end
|
67
|
-
|
68
|
-
def migration_directory
|
69
|
-
MIGRATION_COMMANDS.keys.find { |directory| Dir.exist?(directory) }
|
70
|
-
end
|
71
|
-
|
72
|
-
def migration_command
|
73
|
-
MIGRATION_COMMANDS[migration_directory]
|
74
|
-
end
|
75
68
|
end
|
76
69
|
end
|
data/lib/hanzo/version.rb
CHANGED
data/spec/cli/deploy_spec.rb
CHANGED
@@ -2,32 +2,23 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Hanzo::CLI do
|
4
4
|
describe :deploy do
|
5
|
-
let(:
|
6
|
-
let(:
|
7
|
-
let(:
|
8
|
-
let(:heroku_remotes) { { 'production' => 'heroku-app-production' } }
|
9
|
-
let(:migration_dir) { 'db/migrate' }
|
10
|
-
|
11
|
-
let(:migration_question) { 'Run database migrations?' }
|
12
|
-
let(:deploy_question) { "Branch to deploy in #{env}:" }
|
13
|
-
|
14
|
-
let(:migration_cmd) { "heroku run rake db:migrate --remote #{env}" }
|
15
|
-
let(:restart_cmd) { "heroku ps:restart --remote #{env}" }
|
16
|
-
let(:deploy_cmd) { "git push -f #{env} #{branch}:master" }
|
5
|
+
let(:deploy!) { Hanzo::CLI.new(['deploy', 'production']) }
|
6
|
+
let(:deploy_question) { 'Branch to deploy in production:' }
|
7
|
+
let(:deploy_command) { "git push -f production 1.0.0:master" }
|
17
8
|
|
18
9
|
before do
|
19
10
|
expect(Hanzo::Installers::Remotes).to receive(:environments).and_return(['production'])
|
20
11
|
expect(Hanzo::Installers::Remotes).to receive(:installed_environments).and_return(['production'])
|
21
12
|
end
|
22
13
|
|
23
|
-
context 'successful deploy and without
|
24
|
-
let(:migrations_exist) { false }
|
14
|
+
context 'successful deploy and without after_deploy commands' do
|
25
15
|
let(:deploy_result) { true }
|
16
|
+
let(:config) { {} }
|
26
17
|
|
27
18
|
before do
|
28
|
-
|
29
|
-
expect(Hanzo).to receive(:ask).with(deploy_question).and_return(
|
30
|
-
expect(Hanzo).to receive(:run).with(
|
19
|
+
allow(Hanzo).to receive(:config).and_return(config)
|
20
|
+
expect(Hanzo).to receive(:ask).with(deploy_question).and_return('1.0.0')
|
21
|
+
expect(Hanzo).to receive(:run).with(deploy_command).once.and_return(deploy_result)
|
31
22
|
end
|
32
23
|
|
33
24
|
it 'should git push to heroku upstream' do
|
@@ -35,49 +26,37 @@ describe Hanzo::CLI do
|
|
35
26
|
end
|
36
27
|
end
|
37
28
|
|
38
|
-
context 'with existing
|
39
|
-
let(:
|
29
|
+
context 'with existing after_deploy commands' do
|
30
|
+
let(:config) { { 'after_deploy' => %w(foo bar) } }
|
40
31
|
|
41
32
|
before do
|
42
|
-
|
43
|
-
expect(Hanzo).to receive(:
|
33
|
+
allow(Hanzo).to receive(:config).and_return(config)
|
34
|
+
expect(Hanzo).to receive(:ask).with(deploy_question).and_return('1.0.0')
|
35
|
+
expect(Hanzo).to receive(:run).with(deploy_command).once.and_return(deploy_result)
|
44
36
|
end
|
45
37
|
|
46
38
|
context 'with successful deploy' do
|
47
39
|
let(:deploy_result) { true }
|
48
40
|
|
49
41
|
before do
|
50
|
-
expect(
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
expect(Hanzo).to receive(:agree).with(migration_question).and_return(true)
|
56
|
-
expect(Hanzo).to receive(:run).with(migration_cmd)
|
57
|
-
expect(Hanzo).to receive(:run).with(restart_cmd)
|
58
|
-
end
|
59
|
-
|
60
|
-
specify { deploy! }
|
42
|
+
expect(Hanzo).to receive(:agree).with('Run `foo` on production?').and_return(true)
|
43
|
+
expect(Hanzo).to receive(:run).with('heroku run foo --remote production')
|
44
|
+
expect(Hanzo).to receive(:agree).with('Run `bar` on production?').and_return(true)
|
45
|
+
expect(Hanzo).to receive(:run).with('heroku run bar --remote production')
|
46
|
+
expect(Hanzo).to receive(:run).with('heroku ps:restart --remote production')
|
61
47
|
end
|
62
48
|
|
63
|
-
|
64
|
-
before do
|
65
|
-
expect(Hanzo).to receive(:agree).with(migration_question).and_return(false)
|
66
|
-
expect(Hanzo).not_to receive(:run).with(migration_cmd)
|
67
|
-
expect(Hanzo).not_to receive(:run).with(restart_cmd)
|
68
|
-
end
|
69
|
-
|
70
|
-
specify { deploy! }
|
71
|
-
end
|
49
|
+
specify { deploy! }
|
72
50
|
end
|
73
51
|
|
74
52
|
context 'without successful deploy' do
|
75
53
|
let(:deploy_result) { false }
|
76
54
|
|
77
55
|
before do
|
78
|
-
expect(Hanzo).not_to receive(:agree)
|
79
|
-
expect(Hanzo).not_to receive(:run).with(
|
80
|
-
expect(Hanzo).not_to receive(:run).with(
|
56
|
+
expect(Hanzo).not_to receive(:agree)
|
57
|
+
expect(Hanzo).not_to receive(:run).with('heroku run foo --remote production')
|
58
|
+
expect(Hanzo).not_to receive(:run).with('heroku run bar --remote production')
|
59
|
+
expect(Hanzo).not_to receive(:run).with('heroku ps:restart --remote production')
|
81
60
|
end
|
82
61
|
|
83
62
|
specify { deploy! }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hanzo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.6'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Garneau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
150
|
version: '0'
|
151
151
|
requirements: []
|
152
152
|
rubyforge_project:
|
153
|
-
rubygems_version: 2.
|
153
|
+
rubygems_version: 2.6.8
|
154
154
|
signing_key:
|
155
155
|
specification_version: 4
|
156
156
|
summary: Hanzo is a tool to handle deployments in multiple environments on Heroku.
|