cap_compute_engine 0.0.2
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 +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +61 -0
- data/Rakefile +2 -0
- data/cap_compute_engine.gemspec +23 -0
- data/lib/cap_compute_engine.rb +8 -0
- data/lib/cap_compute_engine/instance.rb +19 -0
- data/lib/cap_compute_engine/instance_list.rb +28 -0
- data/lib/cap_compute_engine/version.rb +3 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 03bc39ba26ced122d98402e8d827828b676e30e9
|
4
|
+
data.tar.gz: 96c8bd2c1fd4973dc2fd14ce7c4f208e83a0c871
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3fff21c63944c3baeed8f0dbacbe69a8f0a53de63856100741d100ecce37f493d534377ffda250b347285d6427eda684145a10f184717aa5f91049c7feed3bd5
|
7
|
+
data.tar.gz: 587ee2b0482461829f7436c03bf812c30315301683b3eee05326e36e9b5cc6ce0faf89110bb6c035b522b788bce71b53dcb74d80da01f4b773448f1e09cf72ff
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 kotohata
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# CapComputeEngine
|
2
|
+
|
3
|
+
Simple utilities for capistrano for google compute engine.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'cap_compute_engine', git: 'https://github.com/t-kot/cap_compute_engine', require: false
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
# To get all compute engine vm instances
|
18
|
+
list = CapComputeEngine::InstanceList.get
|
19
|
+
|
20
|
+
# To select tagged instances from list
|
21
|
+
tagged_list = list.with_tag('app-server')
|
22
|
+
|
23
|
+
# To get external ips from list
|
24
|
+
tagged_list.external_ips
|
25
|
+
# => ['104.155.xxx.xxx', '123.111.xxx.xxx']
|
26
|
+
|
27
|
+
# To allow instances to access cloud sql instance
|
28
|
+
tagged_list.authorize_cloud_sql('cloud-sql-instance-name')
|
29
|
+
|
30
|
+
```
|
31
|
+
|
32
|
+
|
33
|
+
### for capistrano (my suggestion)
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
require 'cap_compute_engine'
|
37
|
+
|
38
|
+
|
39
|
+
list = CapComputeEngine::InstanceList.get
|
40
|
+
list.authorize_cloud_sql('cloud-sql-instance-name')
|
41
|
+
|
42
|
+
role :app, list.with_tag('app-server').external_ips
|
43
|
+
role :web, list.with_tag('web-server').external_ips
|
44
|
+
role :db, list.with_tag('db-server').external_ips
|
45
|
+
role :sidekiq, list.with_tag('sidekiq-server').external_ips
|
46
|
+
|
47
|
+
```
|
48
|
+
|
49
|
+
## TODO
|
50
|
+
|
51
|
+
Very rough code so maybe not work for specific environments.
|
52
|
+
should make `CapComputeEngine::InstanceList.get` to receive arguments such as project name, or should create configure method `CapComputeEngine.configure { |config| ...}`
|
53
|
+
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
1. Fork it ( https://github.com/[my-github-username]/cap_compute_engine/fork )
|
58
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
59
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
60
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
61
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cap_compute_engine/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cap_compute_engine"
|
8
|
+
spec.version = CapComputeEngine::VERSION
|
9
|
+
spec.authors = ["kotohata"]
|
10
|
+
spec.email = ["kotohata@attracie.com"]
|
11
|
+
spec.summary = %q{Cap production deploy}
|
12
|
+
spec.description = %q{Cap production deploy}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module CapComputeEngine
|
2
|
+
class Instance
|
3
|
+
def initialize(hash)
|
4
|
+
@hash = hash.with_indifferent_access
|
5
|
+
end
|
6
|
+
|
7
|
+
def tags
|
8
|
+
@hash[:tags][:items] || []
|
9
|
+
end
|
10
|
+
|
11
|
+
def external_ip
|
12
|
+
@hash[:networkInterfaces].first[:accessConfigs].first[:natIP]
|
13
|
+
end
|
14
|
+
|
15
|
+
def has_tag?(tag_name)
|
16
|
+
tags.include?(tag_name)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'cap_compute_engine/instance'
|
2
|
+
|
3
|
+
module CapComputeEngine
|
4
|
+
class InstanceList
|
5
|
+
def initialize(instances = [])
|
6
|
+
@instances = instances
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.get
|
10
|
+
json = `gcloud compute instances list --format json`
|
11
|
+
|
12
|
+
array = JSON.parse(json)
|
13
|
+
InstanceList.new(array.map { |instance_hash| Instance.new(instance_hash) })
|
14
|
+
end
|
15
|
+
|
16
|
+
def with_tag(tag_name)
|
17
|
+
InstanceList.new(@instances.select { |ins| ins.has_tag?(tag_name) })
|
18
|
+
end
|
19
|
+
|
20
|
+
def external_ips
|
21
|
+
@instances.map(&:external_ip).compact
|
22
|
+
end
|
23
|
+
|
24
|
+
def authorize_cloud_sql(name)
|
25
|
+
`gcloud sql instances patch #{name} --authorized-networks "#{external_ips.join(',')}"`
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cap_compute_engine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kotohata
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Cap production deploy
|
42
|
+
email:
|
43
|
+
- kotohata@attracie.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- cap_compute_engine.gemspec
|
54
|
+
- lib/cap_compute_engine.rb
|
55
|
+
- lib/cap_compute_engine/instance.rb
|
56
|
+
- lib/cap_compute_engine/instance_list.rb
|
57
|
+
- lib/cap_compute_engine/version.rb
|
58
|
+
homepage: ''
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.6.2
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: Cap production deploy
|
82
|
+
test_files: []
|