dployr 0.0.1
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/.editorconfig +9 -0
- data/.gitignore +7 -0
- data/.travis.yml +7 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +294 -0
- data/Rakefile +11 -0
- data/bin/dployr +4 -0
- data/dployr.gemspec +33 -0
- data/lib/dployr/cli/cli.rb +77 -0
- data/lib/dployr/cli/commands/config.rb +66 -0
- data/lib/dployr/cli/commands.rb +1 -0
- data/lib/dployr/compute/client.rb +28 -0
- data/lib/dployr/config/constants.rb +10 -0
- data/lib/dployr/config/create.rb +54 -0
- data/lib/dployr/config/file_utils.rb +36 -0
- data/lib/dployr/config/instance.rb +99 -0
- data/lib/dployr/configuration.rb +163 -0
- data/lib/dployr/init.rb +72 -0
- data/lib/dployr/logger.rb +11 -0
- data/lib/dployr/utils.rb +127 -0
- data/lib/dployr/version.rb +3 -0
- data/lib/dployr.rb +8 -0
- data/spec/config_file_utils_spec.rb +61 -0
- data/spec/config_instance_spec.rb +60 -0
- data/spec/configuration_spec.rb +516 -0
- data/spec/fixtures/Dployrfile +59 -0
- data/spec/fixtures/Dployrfile.yml +91 -0
- data/spec/fog_spec_.rb +44 -0
- data/spec/init_spec.rb +27 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/utils_spec.rb +317 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b382202193f87d485df3e630d80d00fe16757356
|
4
|
+
data.tar.gz: 84199d78c073963b72f65d641442bbf32e2cdf2c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7fe63977dac1afc5eaa20966a9500dee3c25af05ddbce63f9056d7376779f9b3a72ab2f72db8d190e5c62b486d0af13ac09e7f78890c8c3fc51cea0bf750ab28
|
7
|
+
data.tar.gz: 67406e12e53495591bb9e83066519adaf7d9a66c208e6d79c3e2b9a9bc1c324461f382bb664a9e76d90c57378525d6dc0ef145f1376e0222ba3a953b003bd5cb
|
data/.editorconfig
ADDED
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) Innotech and contributors
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,294 @@
|
|
1
|
+
# dployr [][travis] [][gemnasium] [][gem]
|
2
|
+
|
3
|
+
> Multicloud management and deployment made simple
|
4
|
+
|
5
|
+
> **Spoiler! Alpha project. Funny work in progress**
|
6
|
+
|
7
|
+
<table>
|
8
|
+
<tr>
|
9
|
+
<td><b>Version</b></td><td>alpha</td>
|
10
|
+
</tr>
|
11
|
+
<tr>
|
12
|
+
<td><b>Stage</b></td><td>WIP</td>
|
13
|
+
</tr>
|
14
|
+
</table>
|
15
|
+
|
16
|
+
## About
|
17
|
+
|
18
|
+
**Dployr** is a Ruby utility that simplifies cloud management
|
19
|
+
and deployment across different providers
|
20
|
+
|
21
|
+
You can configure your infraestructure and deployment from a simple configuration file which support built-in
|
22
|
+
rich features like templating and inheritance
|
23
|
+
|
24
|
+
Dployr only works in Ruby >= `1.9.x`
|
25
|
+
|
26
|
+
## Installation
|
27
|
+
|
28
|
+
```bash
|
29
|
+
$ gem install dployr
|
30
|
+
```
|
31
|
+
|
32
|
+
Or add it as dependency in your `Gemfile` or `.gemspec` file
|
33
|
+
```ruby
|
34
|
+
# gemspec
|
35
|
+
spec.add_dependency 'dployr', '>= 0.0.1'
|
36
|
+
# Gemfile
|
37
|
+
gem 'dployr', '>= 0.0.1'
|
38
|
+
```
|
39
|
+
|
40
|
+
## Usage
|
41
|
+
|
42
|
+
### Command-line interface
|
43
|
+
|
44
|
+
```
|
45
|
+
Usage: dployr <command> [options]
|
46
|
+
|
47
|
+
Commands
|
48
|
+
|
49
|
+
up start instances
|
50
|
+
halt stop instances
|
51
|
+
status retrieve the instances status
|
52
|
+
test run remote test in instances
|
53
|
+
deploy start, provision and test running instances
|
54
|
+
provision instance provisioning
|
55
|
+
config generate configuration in YAML format
|
56
|
+
init create a sample Dployrfile
|
57
|
+
|
58
|
+
Options
|
59
|
+
|
60
|
+
-e, --environment ENV environment to pass to the instances
|
61
|
+
-n, --name NAME template name identifier to load
|
62
|
+
-a, --attributes ATTRS aditional attributes to pass to the configuration in matrix query format
|
63
|
+
-p, --provider provider to use (allow multiple values comma-separated)
|
64
|
+
-r, --region region to use (allow multiple values comma-separated)
|
65
|
+
-h, --help help
|
66
|
+
|
67
|
+
```
|
68
|
+
|
69
|
+
### Programmatic API
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
Dployr::configure do |dployr|
|
73
|
+
|
74
|
+
dployr.config.add_instance({
|
75
|
+
attributes: {
|
76
|
+
name: "example",
|
77
|
+
instance_type: "m1.small",
|
78
|
+
version: "${VERSION}"
|
79
|
+
},
|
80
|
+
scripts: [
|
81
|
+
{ path: "configure.sh" }
|
82
|
+
],
|
83
|
+
providers: {
|
84
|
+
aws: {
|
85
|
+
attributes: {
|
86
|
+
network_id: "be457fca",
|
87
|
+
instance_type: "m1.small",
|
88
|
+
"type-%{name}" => "small"
|
89
|
+
},
|
90
|
+
regions: {
|
91
|
+
"eu-west-1a" => {
|
92
|
+
attributes: {
|
93
|
+
keypair: "vagrant-aws-ireland"
|
94
|
+
},
|
95
|
+
scripts: [
|
96
|
+
{ path: "router.sh", args: ["%{name}", "${region}", "${provider}"] }
|
97
|
+
]
|
98
|
+
}
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
102
|
+
})
|
103
|
+
|
104
|
+
end
|
105
|
+
```
|
106
|
+
|
107
|
+
## Features
|
108
|
+
|
109
|
+
`To do! but all will be cool :)`
|
110
|
+
|
111
|
+
## Configuration file
|
112
|
+
|
113
|
+
Configuration file must be called `Dployrfile`. It can be also a standard Ruby file
|
114
|
+
or a YAML file (adding the `.yml` or `.yaml` extension)
|
115
|
+
|
116
|
+
#### Data schema
|
117
|
+
|
118
|
+
Each configuration level supports the followings members:
|
119
|
+
|
120
|
+
- **attributes** `Object`
|
121
|
+
- **scripts** `Array`
|
122
|
+
- **providers** `Object`
|
123
|
+
- **authentication** `Object`
|
124
|
+
- **extends** `String|Array` Allows to inherits the current config object from others
|
125
|
+
|
126
|
+
#### Templating
|
127
|
+
|
128
|
+
Dployr allows templating features inside configuration values, in order
|
129
|
+
to provide an easy and clean way to dynamically replace values and self-referenced variables
|
130
|
+
inside the same configuration
|
131
|
+
|
132
|
+
Supported template values notations
|
133
|
+
|
134
|
+
##### Attributes
|
135
|
+
|
136
|
+
Attribute values are available to be referenciable from any part of the config document
|
137
|
+
|
138
|
+
Notation: `%{attribute-name}`
|
139
|
+
|
140
|
+
##### Iteration context variables
|
141
|
+
|
142
|
+
You can reference to the current `provider` or `region` of the current iteration context
|
143
|
+
|
144
|
+
Notation: `${region}`
|
145
|
+
|
146
|
+
##### Environment variables
|
147
|
+
|
148
|
+
Notation: `${HOME}`
|
149
|
+
|
150
|
+
#### Example
|
151
|
+
|
152
|
+
Featured example configuration file (YAML)
|
153
|
+
```yaml
|
154
|
+
---
|
155
|
+
default:
|
156
|
+
attributes:
|
157
|
+
name: "default"
|
158
|
+
prefix: dev
|
159
|
+
private_key_path: ~/pems/private.pem
|
160
|
+
authentication:
|
161
|
+
private_key_path: ~/.ssh/id_rsa
|
162
|
+
public_key_path: ~/.ssh/id_rsa.pub
|
163
|
+
username: ubuntu
|
164
|
+
providers:
|
165
|
+
aws:
|
166
|
+
attributes:
|
167
|
+
instance_type: m1.small
|
168
|
+
regions:
|
169
|
+
eu-west-1a:
|
170
|
+
attributes:
|
171
|
+
ami: ami-f5ca3682
|
172
|
+
keypair: vagrant-aws-ireland
|
173
|
+
security_groups:
|
174
|
+
- sg-576c7635
|
175
|
+
- sg-1e648a7b
|
176
|
+
subnet_id: subnet-be457fca
|
177
|
+
us-west-2b:
|
178
|
+
attributes:
|
179
|
+
ami: ami-c66608f6
|
180
|
+
keypair: vagrant-aws-oregon
|
181
|
+
security_groups:
|
182
|
+
- sg-88283cea
|
183
|
+
- sg-f233ca97
|
184
|
+
subnet_id: subnet-ef757e8d
|
185
|
+
gce:
|
186
|
+
attributes:
|
187
|
+
client_email: sample@mail.com
|
188
|
+
instance_type: m1.small
|
189
|
+
key_location: ~/pems/privatekey.p12
|
190
|
+
project_id: innotechapp
|
191
|
+
regions:
|
192
|
+
europe-west1-a:
|
193
|
+
attributes:
|
194
|
+
ami: centos-base-v5
|
195
|
+
instance_type: n1-standard-1
|
196
|
+
network: liberty-gce
|
197
|
+
scripts:
|
198
|
+
-
|
199
|
+
path: ./scripts/routes_allregions.sh
|
200
|
+
-
|
201
|
+
args: "%{name}"
|
202
|
+
path: ./scripts/updatedns.sh
|
203
|
+
|
204
|
+
|
205
|
+
custom:
|
206
|
+
name: 1
|
207
|
+
web-server:
|
208
|
+
attributes:
|
209
|
+
prefix: zeus-dev
|
210
|
+
authentication:
|
211
|
+
private_key_path: ~/.ssh/id_rsa
|
212
|
+
public_key_path: ~/.ssh/id_rsa.pub
|
213
|
+
username: ubuntu
|
214
|
+
providers:
|
215
|
+
aws:
|
216
|
+
regions:
|
217
|
+
attributes:
|
218
|
+
instance_type: m1.medium
|
219
|
+
gce:
|
220
|
+
attributes:
|
221
|
+
instance_type: m1.large
|
222
|
+
scripts:
|
223
|
+
-
|
224
|
+
args:
|
225
|
+
- "%{name}"
|
226
|
+
- "%{type}"
|
227
|
+
- "%{domain}"
|
228
|
+
path: ./scripts/configure.sh
|
229
|
+
-
|
230
|
+
args:
|
231
|
+
- "%{hydra}"
|
232
|
+
path: ./scripts/configureListener.sh
|
233
|
+
-
|
234
|
+
args:
|
235
|
+
- "%{$provider}-%{region}"
|
236
|
+
- "%{type}"
|
237
|
+
path: ./scripts/hydraProbe.sh
|
238
|
+
|
239
|
+
```
|
240
|
+
|
241
|
+
## Contributing
|
242
|
+
|
243
|
+
Feel free to report any issue you experiment via Github issues.
|
244
|
+
PR are also too much appreciated
|
245
|
+
|
246
|
+
Only PR which follows the [Ruby coding style][ruby-guide] guide will be accepted.
|
247
|
+
Aditionally, you must cover with test any new feature or refactor you do
|
248
|
+
|
249
|
+
We try to follow the [best RSpec][rspec-best] conventions in our tests
|
250
|
+
|
251
|
+
### Development
|
252
|
+
|
253
|
+
Only Ruby and Ruby gems are required for development.
|
254
|
+
To run the development rake tasks, you also need to have `bundler` installed.
|
255
|
+
|
256
|
+
Clone/fork this repository
|
257
|
+
```
|
258
|
+
$ git clone git@github.com:innotech/dployr.git && cd dployr
|
259
|
+
```
|
260
|
+
|
261
|
+
Install dependencies
|
262
|
+
```
|
263
|
+
$ bundle install
|
264
|
+
```
|
265
|
+
|
266
|
+
Before you push any changes, run test specs
|
267
|
+
```
|
268
|
+
$ rake test
|
269
|
+
```
|
270
|
+
|
271
|
+
To build a new version of the gem:
|
272
|
+
```
|
273
|
+
$ rake build
|
274
|
+
````
|
275
|
+
|
276
|
+
To publish the new version to Rubygems:
|
277
|
+
```
|
278
|
+
$ rake release
|
279
|
+
```
|
280
|
+
|
281
|
+
## Contributors
|
282
|
+
|
283
|
+
- [Tomas Aparicio](https://github.com/h2non)
|
284
|
+
- [Germán Ramos](https://github.com/germanramos)
|
285
|
+
|
286
|
+
## License
|
287
|
+
|
288
|
+
[MIT](http://opensource.org/licenses/MIT) © Innotech and contributors
|
289
|
+
|
290
|
+
[travis]: http://travis-ci.org/innotech/dployr
|
291
|
+
[gemnasium]: https://gemnasium.com/innotech/dployr
|
292
|
+
[gem]: http://rubygems.org/gems/dployr
|
293
|
+
[ruby-guide]: https://github.com/bbatsov/ruby-style-guide
|
294
|
+
[rspec-test]: http://betterspecs.org/
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "rspec/core/rake_task"
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
desc "Run specs"
|
5
|
+
RSpec::Core::RakeTask.new do |t|
|
6
|
+
t.verbose = false
|
7
|
+
t.rspec_opts = '--color --order defined --format documentation' # --fail-fast
|
8
|
+
end
|
9
|
+
|
10
|
+
task :test => :spec
|
11
|
+
task :default => :spec
|
data/bin/dployr
ADDED
data/dployr.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require 'dployr/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "dployr"
|
6
|
+
s.version = Dployr::VERSION
|
7
|
+
s.summary = "Multicloud management and deployment with asteroids made simple"
|
8
|
+
s.description = "Multicloud management and deployment with asteroids made simple with a rich programmatic API and featured CLI"
|
9
|
+
s.authors = ["Tomas Aparicio"]
|
10
|
+
s.email = ["nerds@innotechapp.com"]
|
11
|
+
s.homepage = "https://github.com/innotech/dployr"
|
12
|
+
s.license = "MIT"
|
13
|
+
s.rubyforge_project = "dployr"
|
14
|
+
|
15
|
+
s.bindir = "bin"
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.executables = ["dployr"]
|
18
|
+
|
19
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
20
|
+
s.extra_rdoc_files = %w[README.md]
|
21
|
+
|
22
|
+
s.add_dependency "fog", "~> 1.21"
|
23
|
+
s.add_dependency "deep_merge", "~> 1.0"
|
24
|
+
|
25
|
+
s.add_development_dependency "rake", "~> 10"
|
26
|
+
s.add_development_dependency "rspec", "~> 2"
|
27
|
+
|
28
|
+
s.required_ruby_version = ">= 1.9.3"
|
29
|
+
|
30
|
+
s.files = `git ls-files`.split("\n")
|
31
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
32
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
33
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'dployr'
|
3
|
+
require 'dployr/version'
|
4
|
+
require 'dployr/cli/commands'
|
5
|
+
|
6
|
+
command = ARGV[0]
|
7
|
+
options = {}
|
8
|
+
|
9
|
+
opt_parser = OptionParser.new do |opt|
|
10
|
+
opt.banner = " Usage: dployr <command> [options]"
|
11
|
+
opt.separator ""
|
12
|
+
opt.separator " Commands"
|
13
|
+
opt.separator ""
|
14
|
+
opt.separator " up start instances"
|
15
|
+
opt.separator " halt stop instances"
|
16
|
+
opt.separator " destroy destroy instances"
|
17
|
+
opt.separator " status retrieve the instances status"
|
18
|
+
opt.separator " test run remote test in instances"
|
19
|
+
opt.separator " deploy start, provision and test running instances"
|
20
|
+
opt.separator " provision instance provisioning"
|
21
|
+
opt.separator " config generate configuration in YAML format"
|
22
|
+
opt.separator " init create a sample Dployrfile"
|
23
|
+
opt.separator ""
|
24
|
+
opt.separator " Options"
|
25
|
+
opt.separator ""
|
26
|
+
|
27
|
+
opt.on("-e", "--environment ENV", "environment to pass to the instances") do |v|
|
28
|
+
options[:environment] = v
|
29
|
+
end
|
30
|
+
|
31
|
+
opt.on("-n", "--name NAME", "template name identifier to load") do |v|
|
32
|
+
options[:name] = v
|
33
|
+
end
|
34
|
+
|
35
|
+
opt.on("-a", "--attributes ATTRS", "aditional attributes to pass to the configuration in matrix query format") do |v|
|
36
|
+
options[:attributes] = v
|
37
|
+
end
|
38
|
+
|
39
|
+
opt.on("-p", "--provider", "provider to use (allow multiple values comma-separated)") do |v|
|
40
|
+
options[:provider] = v
|
41
|
+
end
|
42
|
+
|
43
|
+
opt.on("-r", "--region", "region to use (allow multiple values comma-separated)") do |v|
|
44
|
+
options[:provider] = v
|
45
|
+
end
|
46
|
+
|
47
|
+
opt.on("-v", "-V", "--version", "version") do
|
48
|
+
puts Dployr::VERSION
|
49
|
+
end
|
50
|
+
|
51
|
+
opt.on("-h", "--help", "help") do
|
52
|
+
puts opt_parser
|
53
|
+
end
|
54
|
+
|
55
|
+
opt.separator ""
|
56
|
+
end
|
57
|
+
|
58
|
+
opt_parser.parse!
|
59
|
+
|
60
|
+
case command
|
61
|
+
when "up"
|
62
|
+
puts "Command currently not available"
|
63
|
+
when "halt"
|
64
|
+
puts "Command currently not available"
|
65
|
+
when "status"
|
66
|
+
puts "Command currently not available"
|
67
|
+
when "provision"
|
68
|
+
puts "Command currently not available"
|
69
|
+
when "test"
|
70
|
+
puts "Command currently not available"
|
71
|
+
when "deploy"
|
72
|
+
puts "Command currently not available"
|
73
|
+
when "config"
|
74
|
+
Dployr::CLI::Config.new options
|
75
|
+
when "init"
|
76
|
+
Dployr::Config::Create.write_file
|
77
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'dployr'
|
3
|
+
require 'dployr/utils'
|
4
|
+
|
5
|
+
module Dployr
|
6
|
+
module CLI
|
7
|
+
class Config
|
8
|
+
|
9
|
+
include Dployr::Utils
|
10
|
+
|
11
|
+
def initialize(options)
|
12
|
+
@options = options
|
13
|
+
@name = options[:name]
|
14
|
+
@log = Logger.new STDOUT
|
15
|
+
@attributes = parse_attributes @options[:attributes]
|
16
|
+
|
17
|
+
begin
|
18
|
+
create
|
19
|
+
render_file
|
20
|
+
rescue Exception => e
|
21
|
+
@log.error e
|
22
|
+
Process.exit! false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def create
|
27
|
+
begin
|
28
|
+
@dployr = Dployr::Init.new @attributes
|
29
|
+
rescue Exception => e
|
30
|
+
raise "Cannot load the config: #{e}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def render_file
|
35
|
+
raise "Dployrfile was not found" if @dployr.file_path.nil?
|
36
|
+
raise "Configuration is missing" unless @dployr.config.exists?
|
37
|
+
begin
|
38
|
+
if @name
|
39
|
+
config = @dployr.config.get_config @name, @attributes
|
40
|
+
else
|
41
|
+
puts @attributes
|
42
|
+
config = @dployr.config.get_config_all @attributes
|
43
|
+
end
|
44
|
+
unless config.nil?
|
45
|
+
puts config.to_yaml
|
46
|
+
else
|
47
|
+
@log.info "Missing configuration data"
|
48
|
+
end
|
49
|
+
rescue Exception => e
|
50
|
+
raise "Cannot generate the config: #{e}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def parse_attributes(attributes)
|
55
|
+
if attributes.is_a? String
|
56
|
+
if @options[:attributes][0] == '-'
|
57
|
+
parse_flags attributes
|
58
|
+
else
|
59
|
+
parse_matrix attributes
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'dployr/cli/commands/config'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'fog'
|
2
|
+
|
3
|
+
module Dployr
|
4
|
+
module Compute
|
5
|
+
class Client
|
6
|
+
|
7
|
+
attr_reader :client
|
8
|
+
|
9
|
+
DEFAULT = {
|
10
|
+
provider: 'AWS'
|
11
|
+
}
|
12
|
+
|
13
|
+
def initialize(options)
|
14
|
+
@options = options
|
15
|
+
@client = Fog::Compute.new DEFAULT.merge options
|
16
|
+
end
|
17
|
+
|
18
|
+
def servers
|
19
|
+
@client.servers
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_server(options)
|
23
|
+
@client.servers.create options
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Dployr
|
2
|
+
module Config
|
3
|
+
module Create
|
4
|
+
|
5
|
+
FILENAME = 'Dployrfile'
|
6
|
+
|
7
|
+
RB_CONTENT = <<-EOS
|
8
|
+
Dployr::configure do |dployr|
|
9
|
+
dployr.config.set_default({
|
10
|
+
attributes: {
|
11
|
+
instance_type: "m1.medium"
|
12
|
+
}
|
13
|
+
})
|
14
|
+
|
15
|
+
dployr.config.add_instance('name', {
|
16
|
+
scripts: [
|
17
|
+
{ path: 'path/to/script.sh' }
|
18
|
+
]
|
19
|
+
})
|
20
|
+
end
|
21
|
+
EOS
|
22
|
+
|
23
|
+
YAML_CONTENT = <<-EOS
|
24
|
+
default:
|
25
|
+
attributes:
|
26
|
+
instance_type: m1.medium
|
27
|
+
instance:
|
28
|
+
attributes:
|
29
|
+
name: my_instance
|
30
|
+
scripts:
|
31
|
+
-
|
32
|
+
path: path/to/script.sh
|
33
|
+
EOS
|
34
|
+
|
35
|
+
module_function
|
36
|
+
|
37
|
+
def write_file(dir = Dir.pwd, type = 'rb')
|
38
|
+
yaml = type == 'yaml'
|
39
|
+
file_name = FILENAME
|
40
|
+
file_name += ".yaml" if yaml
|
41
|
+
content = yaml ? YAML_CONTENT : RB_CONTENT
|
42
|
+
begin
|
43
|
+
file = File.open "#{dir}/#{FILENAME}", "w"
|
44
|
+
file.write content
|
45
|
+
rescue IOError => e
|
46
|
+
raise e
|
47
|
+
ensure
|
48
|
+
file.close unless file == nil
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'dployr/config/constants'
|
3
|
+
|
4
|
+
module Dployr
|
5
|
+
module Config
|
6
|
+
module FileUtils
|
7
|
+
|
8
|
+
include Dployr::Config::Constants
|
9
|
+
|
10
|
+
module_function
|
11
|
+
|
12
|
+
def yaml_file?(str)
|
13
|
+
!(str =~ /\.y[a]?ml$/).nil?
|
14
|
+
end
|
15
|
+
|
16
|
+
def read_yaml(file_path)
|
17
|
+
YAML.load_file file_path
|
18
|
+
end
|
19
|
+
|
20
|
+
def discover(dir = Dir.pwd)
|
21
|
+
[nil].concat(EXTENSIONS).each do |ext|
|
22
|
+
(0..5).each do |n|
|
23
|
+
file_name = FILENAME
|
24
|
+
file_name += ".#{ext}" if ext
|
25
|
+
file_path = File.join dir, ('../' * n), file_name
|
26
|
+
if File.exists? file_path
|
27
|
+
return File.expand_path file_path, dir
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|