cap-gce 1.1.0 → 1.1.1

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: 6eef30cfd574fe40156cd90133d646c233fa99c6
4
- data.tar.gz: bb80ec04fb247ce1a4c0905d2c3db9699e208e9d
3
+ metadata.gz: 88e63844a2c34b9af653090013440de8d55c2124
4
+ data.tar.gz: 283e0bba1985f7f8ea2ee103602722d961d9c529
5
5
  SHA512:
6
- metadata.gz: 3b7c36cb89fc86cd76a004d3776819050bf46e5b27896b7b6416b95ef059ca2f15eb8777d061d01fca9be846693d424c927f356ef96c69a9ae37853493cf1b20
7
- data.tar.gz: d0443ab299a1dccd5a5c32ae6fe67ad8b6010655e27f89830192e0231946e08c506287eb2c2960b619f43952d79a7ea9434ae6d758d584f5673e2c59c1b27009
6
+ metadata.gz: 724aae1655c9c4c4521457fe4a0f1bc70d2094f3dccfa29e142651abbc14b689074728d7c535cf4bf8b54e6d0e31194a3121db2b5342760883d3ea2ca5748cc8
7
+ data.tar.gz: c0dc16e2c8152de58c8a20aeabac53f27b2750ae61ea5fa2d7f19765e9ae99916bdd667fa27753e408fa19c20a805eefaca772ae6b8ccbf154ccb4f88d9f3d29
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # Cap::Gce
1
+ # Cap-GCE
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/cap-gce.svg)](http://badge.fury.io/rb/cap-gce) [![Code Climate](https://codeclimate.com/github/iscreen/cap-gce.png)](https://codeclimate.com/github/iscreen/cap-gce)
2
4
 
3
5
  Cap-GCE is used to generate Capistrano namespaces and tasks from Google Cloud Compute Engine instance metadata, dynamically building the list of servers to be deployed to.
4
6
 
@@ -69,6 +71,84 @@ set :gce_contact_point, nil # nat_ip, network_ip
69
71
 
70
72
  ## Usage
71
73
 
74
+ Imagine you have four servers on Google Cloud Platform named and metadata as follows:
75
+
76
+ <table>
77
+ <tr>
78
+ <td>'Name' metadata</td>
79
+ <td>'Roles' metadata</td>
80
+ <td>'Stages' metadata</td>
81
+ </tr>
82
+ <tr>
83
+ <td>server-1</td>
84
+ <td>web</td>
85
+ <td>production</td>
86
+ </tr>
87
+ <tr>
88
+ <td>server-2</td>
89
+ <td>web,app</td>
90
+ <td>production</td>
91
+ </tr>
92
+ <tr>
93
+ <td>server-3</td>
94
+ <td>app,db</td>
95
+ <td>production</td>
96
+ </tr>
97
+ <tr>
98
+ <td>server-4</td>
99
+ <td>web,db,app</td>
100
+ <td>staging</td>
101
+ </tr>
102
+ </table>
103
+
104
+ Imagine also that we've called our app "testapp", as defined in `config/deploy.rb` like so:
105
+
106
+ set :application, "testapp"
107
+
108
+ ### Defining the roles in `config/deploy/[stage].rb`
109
+
110
+ To define a role, edit `config/deploy/[stage].rb` and add the following:
111
+
112
+ gce_role :web
113
+
114
+ Let's say we edited `config/deploy/production.rb`. Adding this configuration to the file would assign
115
+ the role `:web` to any instance that has the following properties:
116
+ * has a metadata called "Roles" that contains the string "web"
117
+ * has a metadata called "Project" that contains the string "testapp"
118
+ * has a metadata called "Stages" that contains the current stage we're executing (in this case, "production")
119
+
120
+ Looking at the above table, we can see we would match `server-1` and `server-2`. (You can have multiple
121
+ roles in metadata separated by commas.)
122
+
123
+ Now we can define the other roles:
124
+
125
+ gce_role :app
126
+ gce_role :db
127
+
128
+ In the "production" stage, the `:app` role would apply to `server-2` and `server-3`, and the `:db`
129
+ role would apply to `server-3`.
130
+
131
+ In the "staging" stage, all roles would apply *only* to `server-4`.
132
+
133
+ ### Servers belonging to multiple projects
134
+
135
+ If you require your servers to have multiple projects deployed to them, you can simply specify
136
+ all the project names you want to the server to be part of in the 'Projects' metadata, separated
137
+ by commas. For example, you could place a server in the `testapp` and `myapp` projects by
138
+ setting the 'Projects' metadata to `testapp,myapp`.
139
+
140
+ ### Servers in multiple stages
141
+
142
+ If your use-case requires servers to be in multiple stages, simply specify all the stages you want
143
+ the server to be in 'Stages' metadata, separated by commas. For example, you could place a server in
144
+ the `production` and `staging` stages by setting the 'Stages' metadata to `production,staging`.
145
+
146
+ ### Tasks and deployment
147
+
148
+ You can now define your tasks for these roles in exactly the same way as you would if you weren't
149
+ using this gem.
150
+
151
+
72
152
  ## Utility tasks
73
153
 
74
154
  Cap-GCE adds a few utility tasks to Capistrano for displaying information about the instances that you will be deploying to. Note that unlike Capistrano 2.x, all tasks require a stage.
@@ -128,7 +208,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
128
208
 
129
209
  ## Contributing
130
210
 
131
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cap-gce. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
211
+ Bug reports and pull requests are welcome on GitHub at https://github.com/iscreen/cap-gce. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
132
212
 
133
213
 
134
214
  ## License
data/lib/cap-gce/utils.rb CHANGED
@@ -20,7 +20,9 @@ module CapGCE
20
20
  end
21
21
 
22
22
  def tag_value(instance, key)
23
- instance.metadata.items.find({}) { |t| t.key == key.to_s }.value
23
+ find = instance.metadata.items.detect { |t| t.key == key.to_s }
24
+ return nil unless find
25
+ find.value
24
26
  end
25
27
 
26
28
  def self.contact_point_mapping
@@ -47,6 +49,7 @@ module CapGCE
47
49
  end
48
50
 
49
51
  def self.nat_ip(instance)
52
+ return [] if (instance.network_interfaces.map(&:access_configs).flatten - [nil]).empty?
50
53
  instance.network_interfaces.map(&:access_configs).flatten.map(&:nat_ip) - [nil]
51
54
  end
52
55
 
@@ -1,3 +1,3 @@
1
1
  module CapGCE
2
- VERSION = '1.1.0'.freeze
2
+ VERSION = '1.1.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cap-gce
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dean Lin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-15 00:00:00.000000000 Z
11
+ date: 2017-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-api-client