opsworks-deploy 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -1
- data/lib/opsworks-deploy.rb +2 -0
- data/lib/opsworks/deploy/deploy.rb +26 -11
- data/lib/opsworks/deploy/version.rb +1 -1
- data/lib/opsworks/tasks.rb +9 -0
- data/lib/opsworks/tasks/opsworks.rake +5 -5
- data/opsworks-deploy.gemspec +1 -1
- data/spec/opsworks_deploy_spec.rb +6 -11
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24dc7f0f3e5b457e1a50978e238da61496e5e82f
|
4
|
+
data.tar.gz: 019421049e24a5fdca62366e212a8097ab855ce4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39e9117976d50cef7805b2a581aa353db0c999de01daa34340cc0ce19d4f5b3fd239435e5b0230d51f0b352d36317ac29616a52b916c1581ff35de2ce8e6ecf8
|
7
|
+
data.tar.gz: bcbcc9d037a8a858236b9d97dd9052289000d3c9d63ebdda322b2dfd5113bab74f46250f542bc58d67272dbebfcb97276d8b40c09bcc7f9bb125d3b31d9b5495
|
data/README.md
CHANGED
@@ -39,10 +39,18 @@ config/stacks.json
|
|
39
39
|
|
40
40
|
Then run:
|
41
41
|
|
42
|
-
|
42
|
+
ENV=staging AWS_CONFIG_FILE=~/.aws_config rake opsworks:deploy
|
43
43
|
|
44
44
|
Note, your IAM keys should only allow deploy access to OpsWorks, but you should never check them into source control.
|
45
45
|
|
46
|
+
## Without Rails
|
47
|
+
|
48
|
+
To use with other ruby applications, e.g. Sinatra, add the following line to your `Rakefile`:
|
49
|
+
|
50
|
+
require "opsworks/tasks"
|
51
|
+
|
52
|
+
This will load the rake task like above.
|
53
|
+
|
46
54
|
## Testing
|
47
55
|
|
48
56
|
Use rspec for test
|
data/lib/opsworks-deploy.rb
CHANGED
@@ -27,17 +27,33 @@ module Opsworks::Deploy
|
|
27
27
|
return true if deployment_desc.data[:status] == 'successful'
|
28
28
|
end
|
29
29
|
|
30
|
-
|
30
|
+
# Look for config/stacks.json or stacks.json
|
31
|
+
def self.get_config_stacks
|
32
|
+
cwd = Dir.getwd
|
33
|
+
files = ["#{cwd}/config/stacks.json","#{cwd}/stacks.json"]
|
34
|
+
|
35
|
+
if !cwd.nil? && cwd.length > 0
|
36
|
+
files.each do |file|
|
37
|
+
if File.exists?(file)
|
38
|
+
return JSON(File.read(file))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
return nil
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.get_stack(env=nil)
|
47
|
+
|
48
|
+
# First try to get from env, then stack files
|
31
49
|
if !ENV['STACK_ID'].nil? && !ENV['APP_ID'].nil?
|
32
50
|
return {stack_id: ENV['STACK_ID'], app_id: ENV['APP_ID']}
|
33
|
-
elsif
|
34
|
-
|
35
|
-
stacks = JSON(File.read("#{Rails.root}/config/stacks.json"))
|
36
|
-
raise "Missing stacks configuration for #{rails_env}" if stacks[rails_env].empty?
|
51
|
+
elsif stacks = get_config_stacks
|
52
|
+
raise "Missing stacks configuration for #{env} in stacks.json" if stacks[env].nil?
|
37
53
|
|
38
|
-
return stacks[
|
54
|
+
return stacks[env]
|
39
55
|
else
|
40
|
-
raise "Must set STACK_ID
|
56
|
+
raise "Must set STACK_ID and APP_ID or have config/stacks.json for env `#{env}`"
|
41
57
|
end
|
42
58
|
end
|
43
59
|
|
@@ -66,14 +82,13 @@ module Opsworks::Deploy
|
|
66
82
|
opts = {
|
67
83
|
migrate: true,
|
68
84
|
wait: false,
|
69
|
-
|
85
|
+
env: nil
|
70
86
|
}.merge(opts)
|
71
87
|
|
72
|
-
stack = Opsworks::Deploy.get_stack(opts[:
|
88
|
+
stack = Opsworks::Deploy.get_stack(opts[:env]) # Get stack environment
|
73
89
|
|
74
90
|
Opsworks::Deploy.configure_aws! # Ensure we are properly configured
|
75
|
-
|
76
|
-
p stack
|
91
|
+
|
77
92
|
deployment = AWS.ops_works.client.create_deployment( stack_id: stack[:stack_id] || stack['stack_id'], app_id: stack[:app_id] || stack['app_id'], command: {name: 'deploy', args: {"migrate" => [ opts[:migrate] ? "true" : "false"] }} )
|
78
93
|
|
79
94
|
puts deployment.inspect
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# Loads opsworks-deploy tasks from non-Rails application
|
2
|
+
|
3
|
+
# See: http://pivotallabs.com/how-i-test-rake-tasks/
|
4
|
+
# See: http://stackoverflow.com/questions/15446153/ruby-rake-load-tasks-from-a-gem
|
5
|
+
# See: http://stackoverflow.com/questions/5458134/how-do-i-import-rake-tasks-from-a-gem-when-using-sinatra
|
6
|
+
require File.join(File.dirname(__FILE__), '../opsworks-deploy')
|
7
|
+
|
8
|
+
spec = Gem::Specification.find_by_name 'opsworks-deploy'
|
9
|
+
load "#{spec.gem_dir}/lib/opsworks/tasks/opsworks.rake"
|
@@ -2,15 +2,15 @@
|
|
2
2
|
namespace :opsworks do
|
3
3
|
|
4
4
|
desc 'Deploy to Opsworks'
|
5
|
-
task :deploy, [:
|
6
|
-
|
5
|
+
task :deploy, [:env,:migrate] => [] do |t, args|
|
6
|
+
env = args[:env] || ENV['ENV'] || ENV['RAILS_ENV']
|
7
7
|
migrate = args[:migrate] == "true" || args[:migrate] == "t"
|
8
8
|
|
9
|
-
raise ArgumentError, "Please pass
|
9
|
+
raise ArgumentError, "Please pass env as argument or set ENV or RAILS_ENV environment var" if env.nil? || env == ""
|
10
10
|
|
11
|
-
puts "Deploying #{
|
11
|
+
puts "Deploying #{env}#{migrate ? " and running migrations" : ""}..."
|
12
12
|
|
13
|
-
Opsworks::Deploy.deploy(
|
13
|
+
Opsworks::Deploy.deploy(env: env, migrate: migrate)
|
14
14
|
|
15
15
|
puts "Finished successfully"
|
16
16
|
end
|
data/opsworks-deploy.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["hayesgm@gmail.com"]
|
11
11
|
spec.description = %q{Quick and easy rake task for deploying to AWS OpsWorks}
|
12
12
|
spec.summary = %q{A quick rake task that will deploy to AWS OpsWorks. This can be added as a post-step in Continuous Integration. `rake opsworks:deply`}
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "https://github.com/hayesgm/opsworks-deploy"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
@@ -7,7 +7,6 @@ describe 'opsworks:deploy rake task' do
|
|
7
7
|
|
8
8
|
before(:all) do
|
9
9
|
load File.expand_path("../../lib/opsworks/tasks/opsworks.rake", __FILE__)
|
10
|
-
Rake::Task.define_task(:environment)
|
11
10
|
end
|
12
11
|
|
13
12
|
after(:each) do
|
@@ -15,14 +14,14 @@ describe 'opsworks:deploy rake task' do
|
|
15
14
|
end
|
16
15
|
|
17
16
|
it "should call invoke with argument when given arg" do
|
18
|
-
expect(Opsworks::Deploy).to receive(:deploy).with(
|
17
|
+
expect(Opsworks::Deploy).to receive(:deploy).with(env: 'test-1', migrate: false)
|
19
18
|
Rake::Task["opsworks:deploy"].invoke('test-1')
|
20
19
|
end
|
21
20
|
|
22
21
|
it "should call invoke with argument when given env" do
|
23
22
|
begin
|
24
23
|
ENV['RAILS_ENV'] = "test-2"
|
25
|
-
expect(Opsworks::Deploy).to receive(:deploy).with(
|
24
|
+
expect(Opsworks::Deploy).to receive(:deploy).with(env: 'test-2', migrate: false)
|
26
25
|
Rake::Task["opsworks:deploy"].invoke
|
27
26
|
ensure
|
28
27
|
ENV['RAILS_ENV'] = nil
|
@@ -43,12 +42,10 @@ describe 'opsworks:deploy rake task' do
|
|
43
42
|
}
|
44
43
|
|
45
44
|
# Mock ENV vars
|
46
|
-
ENV['
|
45
|
+
ENV['ENV'] = "test-3"
|
47
46
|
ENV['IAM_KEY'] = ENV['IAM_SECRET'] = "a"
|
48
47
|
|
49
|
-
# Allow
|
50
|
-
Rails = double("rails")
|
51
|
-
expect(Rails).to receive(:root).and_return(".").twice
|
48
|
+
# Allow file config
|
52
49
|
expect(File).to receive(:exists?).and_return(true)
|
53
50
|
expect(File).to receive(:read).and_return(config.to_json)
|
54
51
|
|
@@ -67,7 +64,7 @@ describe 'opsworks:deploy rake task' do
|
|
67
64
|
# Call rake task
|
68
65
|
Rake::Task["opsworks:deploy"].invoke
|
69
66
|
ensure # clear ENV vars
|
70
|
-
ENV['
|
67
|
+
ENV['ENV'] = ENV['IAM_KEY'] = ENV['IAM_SECRET'] = nil
|
71
68
|
end
|
72
69
|
end
|
73
70
|
|
@@ -83,9 +80,7 @@ describe 'opsworks:deploy rake task' do
|
|
83
80
|
# Mock ENV vars
|
84
81
|
ENV['IAM_KEY'] = ENV['IAM_SECRET'] = "a"
|
85
82
|
|
86
|
-
# Allow
|
87
|
-
Rails = double("rails")
|
88
|
-
expect(Rails).to receive(:root).and_return(".").twice
|
83
|
+
# Allow file config
|
89
84
|
expect(File).to receive(:exists?).and_return(true)
|
90
85
|
expect(File).to receive(:read).and_return(config.to_json)
|
91
86
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opsworks-deploy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geoff Hayes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -111,11 +111,12 @@ files:
|
|
111
111
|
- lib/opsworks/deploy/deploy.rb
|
112
112
|
- lib/opsworks/deploy/railtie.rb
|
113
113
|
- lib/opsworks/deploy/version.rb
|
114
|
+
- lib/opsworks/tasks.rb
|
114
115
|
- lib/opsworks/tasks/opsworks.rake
|
115
116
|
- opsworks-deploy.gemspec
|
116
117
|
- spec/opsworks_deploy_spec.rb
|
117
118
|
- spec/spec_helper.rb
|
118
|
-
homepage:
|
119
|
+
homepage: https://github.com/hayesgm/opsworks-deploy
|
119
120
|
licenses:
|
120
121
|
- MIT
|
121
122
|
metadata: {}
|
@@ -143,3 +144,4 @@ summary: A quick rake task that will deploy to AWS OpsWorks. This can be added
|
|
143
144
|
test_files:
|
144
145
|
- spec/opsworks_deploy_spec.rb
|
145
146
|
- spec/spec_helper.rb
|
147
|
+
has_rdoc:
|