heroploy 0.0.6 → 0.0.7.beta

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: 43d2a2c41a7f6cf4df2a3bd702909a8f3187e86b
4
- data.tar.gz: d38defbf1034e876710827b2df4f389f4775e614
3
+ metadata.gz: 14831f804b67f92cda8c6114f55f8b62979f57d2
4
+ data.tar.gz: e042e03695b5e29b37c0bea862032cffe540248e
5
5
  SHA512:
6
- metadata.gz: fc5fd21d2bdd1642f9c5c1abc145072b07d7744df3b51d76be6a9d17562bf1e325accadbd4536910f4538d15fa1974b238d543f54387ec74197f9dc05f80bc10
7
- data.tar.gz: c34743eeda303b04f3865f83f1efdb8951df103b086c0d2dbda6b7280c5e174a0fb2eb97244fed6eb5a2a705b9acd167ee24f6014008de52e94f660163ba692a
6
+ metadata.gz: 81ebc92f623e7cd3622dbed4a8aaddb919567dde3d98078242c7738bac34350efbaaa2c3a3c2bd92869dbcdafd939aae54208e8370408d45e9699ba3932bc2b7
7
+ data.tar.gz: dcf831f48268d598dfb1b53d3bcbc05b93e31656b123556dc0b5b674c42b8c83577f7cbc8dd6a0bfb3eb11bc8a6903c1afb1ca14feb156f8354c69af0814a35c
@@ -1,3 +1,5 @@
1
+ require 'rake/tasklib'
2
+
1
3
  module Heroploy
2
4
  class Shell
3
5
  extend FileUtils
@@ -2,6 +2,8 @@ require 'heroploy/config/deployment_config'
2
2
  require 'heroploy/config/environment'
3
3
  require 'heroploy/config/shared_env'
4
4
  require 'heroploy/config/remote_config'
5
+ require 'heroploy/commands/shell'
6
+ require 'heroploy/commands/git'
5
7
 
6
8
  module Heroploy
7
9
  module Config
@@ -10,6 +12,8 @@ module Heroploy
10
12
  attr_accessor :environments
11
13
  attr_accessor :shared_env
12
14
  attr_accessor :remote_configs
15
+
16
+ include Commands::Git
13
17
 
14
18
  def [](env_name)
15
19
  environments.select{ |env| env.name == env_name }.first
@@ -35,6 +39,19 @@ module Heroploy
35
39
  self[env_config.name].variables.merge!(env_config.variables)
36
40
  end
37
41
  end
42
+
43
+ def load_remotes!
44
+ unless remote_configs.nil?
45
+ remote_configs.each do |remote_config|
46
+ git_clone(remote_config.repository, remote_config.name) do
47
+ remote_config.files.each do |filename|
48
+ config_file = File.join(Dir.pwd, remote_config.name, filename)
49
+ merge_config(Heroploy::Config::DeploymentConfig.load(config_file))
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
38
55
  end
39
56
  end
40
57
  end
@@ -4,7 +4,7 @@ module Heroploy
4
4
  attr_accessor :required
5
5
  attr_accessor :variables
6
6
 
7
- def initialize(attrs)
7
+ def initialize(attrs = {})
8
8
  attrs ||= {}
9
9
  @required = attrs['required'] || []
10
10
  @variables = attrs['variables'] || {}
@@ -0,0 +1,37 @@
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
@@ -33,16 +33,7 @@ module Heroploy
33
33
  def define_load_configs_task
34
34
  desc 'load remote configs'
35
35
  task :load_remote_configs do
36
- unless deployment_config.remote_configs.nil?
37
- deployment_config.remote_configs.each do |remote_config|
38
- git_clone(remote_config.repository, remote_config.name) do
39
- remote_config.files.each do |filename|
40
- config_file = File.join(Dir.pwd, remote_config.name, filename)
41
- deployment_config.merge_config(Heroploy::Config::DeploymentConfig.load(config_file))
42
- end
43
- end
44
- end
45
- end
36
+ deployment_config.load_remotes!
46
37
  end
47
38
  end
48
39
 
@@ -1,3 +1,3 @@
1
1
  module Heroploy
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7.beta"
3
3
  end
data/lib/heroploy.rb CHANGED
@@ -2,3 +2,4 @@ require "rails"
2
2
 
3
3
  require "heroploy/version"
4
4
  require "heroploy/engine" if defined?(Rails) && Rails::VERSION::MAJOR >= 3
5
+ require "heroploy/config/var_reader"
data/spec/factories.rb CHANGED
@@ -39,8 +39,15 @@ FactoryGirl.define do
39
39
  end
40
40
  end
41
41
 
42
+ factory :shared_env, :class => Heroploy::Config::SharedEnv do
43
+ required []
44
+ variables {}
45
+ end
46
+
42
47
  factory :deployment_config, :class => Heroploy::Config::DeploymentConfig do
43
48
  travis_repo "my-travis-user/my-travis-repo"
49
+
50
+ shared_env nil
44
51
 
45
52
  environments {
46
53
  [
@@ -0,0 +1,67 @@
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
data/spec/spec_helper.rb CHANGED
@@ -15,6 +15,7 @@ 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'
18
19
 
19
20
  require 'support/shell_support'
20
21
  require 'support/shared_contexts/rake'
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.6
4
+ version: 0.0.7.beta
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-02-22 00:00:00.000000000 Z
11
+ date: 2014-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -151,6 +151,7 @@ files:
151
151
  - lib/heroploy/config/environment_checks.rb
152
152
  - lib/heroploy/config/remote_config.rb
153
153
  - lib/heroploy/config/shared_env.rb
154
+ - lib/heroploy/config/var_reader.rb
154
155
  - lib/heroploy/engine.rb
155
156
  - lib/heroploy/tasks/check_task_lib.rb
156
157
  - lib/heroploy/tasks/deploy_task_lib.rb
@@ -169,6 +170,7 @@ files:
169
170
  - spec/lib/heroploy/config/environment_spec.rb
170
171
  - spec/lib/heroploy/config/remote_config_spec.rb
171
172
  - spec/lib/heroploy/config/shared_env_spec.rb
173
+ - spec/lib/heroploy/config/var_reader_spec.rb
172
174
  - spec/lib/heroploy/tasks/check_all_spec.rb
173
175
  - spec/lib/heroploy/tasks/check_branch_spec.rb
174
176
  - spec/lib/heroploy/tasks/check_config_spec.rb
@@ -197,9 +199,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
197
199
  version: '0'
198
200
  required_rubygems_version: !ruby/object:Gem::Requirement
199
201
  requirements:
200
- - - '>='
202
+ - - '>'
201
203
  - !ruby/object:Gem::Version
202
- version: '0'
204
+ version: 1.3.1
203
205
  requirements: []
204
206
  rubyforge_project:
205
207
  rubygems_version: 2.0.3
@@ -218,6 +220,7 @@ test_files:
218
220
  - spec/lib/heroploy/config/environment_spec.rb
219
221
  - spec/lib/heroploy/config/remote_config_spec.rb
220
222
  - spec/lib/heroploy/config/shared_env_spec.rb
223
+ - spec/lib/heroploy/config/var_reader_spec.rb
221
224
  - spec/lib/heroploy/tasks/check_all_spec.rb
222
225
  - spec/lib/heroploy/tasks/check_branch_spec.rb
223
226
  - spec/lib/heroploy/tasks/check_config_spec.rb