fig-newton 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0149f90fb2855e3060d519a5efd81185415e5903
4
+ data.tar.gz: 4f80142b52ec00b8c9c5c2b066bfdbe3680064bd
5
+ SHA512:
6
+ metadata.gz: f1f33d19d3c97d96e0a50d69dd0ef6b22e219e807b2c93827e7d6a0bab61769aff8ff299489bfe71a791081eef29db9bdc8089e8973a54c13de478a049c41ac7
7
+ data.tar.gz: b8f73c5a25fab085bde862dbec15ac3b526b713a6f0fe0e8babad3b13e01877d0316d70e6ecb57fc60177f7c722848fb23116bd19709a383ba9c5bc5e28b619f
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ vendor
16
+ bin
@@ -0,0 +1,262 @@
1
+ AllCops:
2
+ Include:
3
+ - '**/Rakefile'
4
+ - '**/config.ru'
5
+ Exclude:
6
+ - 'db/**/*'
7
+ - 'config/**/*'
8
+ - 'bin/**/*'
9
+ - 'vendor/**/*'
10
+
11
+ AccessorMethodName:
12
+ Enabled: false
13
+
14
+ ActionFilter:
15
+ Enabled: false
16
+
17
+ Alias:
18
+ Enabled: false
19
+
20
+ ArrayJoin:
21
+ Enabled: false
22
+
23
+ AsciiComments:
24
+ Enabled: false
25
+
26
+ AsciiIdentifiers:
27
+ Enabled: false
28
+
29
+ Attr:
30
+ Enabled: false
31
+
32
+ BlockNesting:
33
+ Enabled: false
34
+
35
+ CaseEquality:
36
+ Enabled: false
37
+
38
+ CharacterLiteral:
39
+ Enabled: false
40
+
41
+ ClassAndModuleChildren:
42
+ Enabled: false
43
+
44
+ ClassLength:
45
+ Enabled: false
46
+
47
+ ClassVars:
48
+ Enabled: false
49
+
50
+ CollectionMethods:
51
+ PreferredMethods:
52
+ find: detect
53
+ reduce: inject
54
+ collect: map
55
+ find_all: select
56
+
57
+ ColonMethodCall:
58
+ Enabled: false
59
+
60
+ CommentAnnotation:
61
+ Enabled: false
62
+
63
+ CyclomaticComplexity:
64
+ Enabled: false
65
+
66
+ Delegate:
67
+ Enabled: false
68
+
69
+ DeprecatedHashMethods:
70
+ Enabled: false
71
+
72
+ Documentation:
73
+ Enabled: false
74
+
75
+ DotPosition:
76
+ EnforcedStyle: trailing
77
+
78
+ DoubleNegation:
79
+ Enabled: false
80
+
81
+ EachWithObject:
82
+ Enabled: false
83
+
84
+ EmptyLiteral:
85
+ Enabled: false
86
+
87
+ Encoding:
88
+ Enabled: false
89
+
90
+ EvenOdd:
91
+ Enabled: false
92
+
93
+ FileName:
94
+ Enabled: false
95
+
96
+ FlipFlop:
97
+ Enabled: false
98
+
99
+ FormatString:
100
+ Enabled: false
101
+
102
+ GlobalVars:
103
+ Enabled: false
104
+
105
+ GuardClause:
106
+ Enabled: false
107
+
108
+ IfUnlessModifier:
109
+ Enabled: false
110
+
111
+ IfWithSemicolon:
112
+ Enabled: false
113
+
114
+ Lambda:
115
+ Enabled: false
116
+
117
+ LambdaCall:
118
+ Enabled: false
119
+
120
+ LineEndConcatenation:
121
+ Enabled: false
122
+
123
+ LineLength:
124
+ Max: 120
125
+
126
+ MethodLength:
127
+ Enabled: false
128
+
129
+ ModuleFunction:
130
+ Enabled: false
131
+
132
+ NegatedIf:
133
+ Enabled: false
134
+
135
+ NegatedWhile:
136
+ Enabled: false
137
+
138
+ Next:
139
+ Enabled: false
140
+
141
+ NilComparison:
142
+ Enabled: false
143
+
144
+ Not:
145
+ Enabled: false
146
+
147
+ NumericLiterals:
148
+ Enabled: false
149
+
150
+ OneLineConditional:
151
+ Enabled: false
152
+
153
+ OpMethod:
154
+ Enabled: false
155
+
156
+ ParameterLists:
157
+ Enabled: false
158
+
159
+ PercentLiteralDelimiters:
160
+ Enabled: false
161
+
162
+ PerlBackrefs:
163
+ Enabled: false
164
+
165
+ PredicateName:
166
+ NamePrefixBlacklist:
167
+ - is_
168
+
169
+ Proc:
170
+ Enabled: false
171
+
172
+ RaiseArgs:
173
+ Enabled: false
174
+
175
+ RegexpLiteral:
176
+ Enabled: false
177
+
178
+ SelfAssignment:
179
+ Enabled: false
180
+
181
+ SingleLineBlockParams:
182
+ Enabled: false
183
+
184
+ SingleLineMethods:
185
+ Enabled: false
186
+
187
+ SignalException:
188
+ Enabled: false
189
+
190
+ SpecialGlobalVars:
191
+ Enabled: false
192
+
193
+ StringLiterals:
194
+ EnforcedStyle: double_quotes
195
+
196
+ VariableInterpolation:
197
+ Enabled: false
198
+
199
+ TrailingComma:
200
+ Enabled: false
201
+
202
+ TrivialAccessors:
203
+ Enabled: false
204
+
205
+ VariableInterpolation:
206
+ Enabled: false
207
+
208
+ WhenThen:
209
+ Enabled: false
210
+
211
+ WhileUntilModifier:
212
+ Enabled: false
213
+
214
+ WordArray:
215
+ Enabled: false
216
+
217
+ # Lint
218
+
219
+ AmbiguousOperator:
220
+ Enabled: false
221
+
222
+ AmbiguousRegexpLiteral:
223
+ Enabled: false
224
+
225
+ AssignmentInCondition:
226
+ Enabled: false
227
+
228
+ ConditionPosition:
229
+ Enabled: false
230
+
231
+ DeprecatedClassMethods:
232
+ Enabled: false
233
+
234
+ ElseLayout:
235
+ Enabled: false
236
+
237
+ HandleExceptions:
238
+ Enabled: false
239
+
240
+ InvalidCharacterLiteral:
241
+ Enabled: false
242
+
243
+ LiteralInCondition:
244
+ Enabled: false
245
+
246
+ LiteralInInterpolation:
247
+ Enabled: false
248
+
249
+ Loop:
250
+ Enabled: false
251
+
252
+ ParenthesesAsGroupedExpression:
253
+ Enabled: false
254
+
255
+ RequireParentheses:
256
+ Enabled: false
257
+
258
+ UnderscorePrefixedVariableName:
259
+ Enabled: false
260
+
261
+ Void:
262
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fig-newton.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem "rspec", "~> 3.1.0"
8
+ gem "fakefs", "~> 0.5.0"
9
+ end
@@ -0,0 +1,35 @@
1
+ # `fig-newton`
2
+
3
+ Wrapper tooling around fig to manage application stacks.
4
+
5
+ ## Rationale
6
+
7
+ `fig` is fantastic for keeping track of the various pieces required to describe dockerized applications. However, it's descriptor is not great for SOA applications, as any change to architecture would require changing the `fig.yml` of all pieces. `fig-newton` attempts to address that shortcoming by letting individual applications be described using fig, while stacks of applications can be described using a similar yml file.
8
+
9
+ ## Usage
10
+
11
+ ```
12
+ fig-newton [OPTIONS] <COMMAND> <STACK_NAME>
13
+ ```
14
+
15
+ ### `init STACK_NAME`
16
+
17
+ Generate a skeleton description file for the `STACK_NAME` application stack
18
+
19
+ ### `clone STACK_NAME`
20
+
21
+ #### Options
22
+
23
+ | Option | Meaning |
24
+ | ------ | ------- |
25
+ | parent_directory | The parent directory of the cloned repositories. Can be an absolute path or relative to the current directory |
26
+
27
+ Use `git` to pull down the repositories for the given stack
28
+
29
+ ### `up STACK_NAME`
30
+
31
+ Bring up all the applications defined for the given stack. Equivalent to running `fig up` in each application directory.
32
+
33
+ ### `down STACK_NAME`
34
+
35
+ Bring down all the applications defined for the given stack. Equivalent to running `fig down` in each application directory.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "fig-newton"
4
+
5
+ begin
6
+ require "fig-newton/cli"
7
+ FigNewton::CLI.start
8
+ rescue Interrupt
9
+ puts "\nQuitting..."
10
+ exit 1
11
+ rescue SystemExit => e
12
+ exit e.status
13
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "fig-newton/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fig-newton"
8
+ spec.version = FigNewton::VERSION
9
+ spec.authors = ["Sean Dunn"]
10
+ spec.email = ["sedunn@adobe.com"]
11
+ spec.summary = "Wrapper tooling around fig to manage application stacks."
12
+ spec.description = "Wrapper tooling around fig to manage application stacks."
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.bindir = "exe"
18
+ spec.executables = ["fig-newton"]
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "thor", "~> 0.19.1"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
@@ -0,0 +1,5 @@
1
+ require "fig-newton/version"
2
+
3
+ module FigNewton
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,51 @@
1
+ module FigNewton
2
+ class App
3
+ def initialize(name, config)
4
+ @name = name
5
+ @repo = config["repo"]
6
+ @dir = config["dir"] || dir_from_repo
7
+ end
8
+
9
+ def clone(parent_directory = ".")
10
+ clone_directory = full_dir(parent_directory)
11
+
12
+ puts "-- Cloning #{full_repo} to '#{clone_directory}'"
13
+ `git clone #{full_repo} #{clone_directory} &>/dev/null`
14
+ end
15
+
16
+ def up(parent_directory)
17
+ source_directory = full_dir(parent_directory)
18
+
19
+ puts "-- Bringing up #{@name} in '#{source_directory}'"
20
+ `cd #{source_directory} && fig up -d`
21
+ end
22
+
23
+ def down(parent_directory)
24
+ source_directory = full_dir(parent_directory)
25
+
26
+ puts "-- Bringing down #{@name} in '#{source_directory}'"
27
+ `cd #{source_directory} && fig kill`
28
+ end
29
+
30
+ private
31
+
32
+ attr_accessor :name, :repo, :dir
33
+
34
+ def full_repo
35
+ @full_repo ||= case
36
+ when @repo.match(/\w+:\/\//)
37
+ repo
38
+ else
39
+ "https://github.com/#{@repo}"
40
+ end
41
+ end
42
+
43
+ def full_dir(parent)
44
+ File.join(parent, @dir)
45
+ end
46
+
47
+ def dir_from_repo
48
+ repo.split("/").last
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,45 @@
1
+ require "thor"
2
+
3
+ module FigNewton
4
+ class CLI < Thor
5
+ desc "init STACK_NAME", "Generate a skeleton description file for the STACK_NAME application stack"
6
+ option :force, type: :boolean,
7
+ default: false,
8
+ desc: "Overwrite file if it already exists"
9
+ def init(stack_name)
10
+ require "fig-newton/commands/init"
11
+ command = FigNewton::Commands::Init.new(stack_name)
12
+ command.run(options[:force])
13
+ end
14
+
15
+ desc "clone STACK_NAME", "Use git to pull down the repositories for the given stack"
16
+ option :parent_directory, type: :string,
17
+ default: ".",
18
+ desc: "The parent directory of the cloned repositories"
19
+ def clone(stack_name)
20
+ require "fig-newton/commands/clone"
21
+ command = FigNewton::Commands::Clone.new(stack_name)
22
+ command.run(options[:parent_directory])
23
+ end
24
+
25
+ desc "up STACK_NAME", "Bring up all the applications defined for the given stack. Equivalent to running fig up in each application directory."
26
+ option :parent_directory, type: :string,
27
+ default: ".",
28
+ desc: "The parent directory of the cloned repositories"
29
+ def up(stack_name)
30
+ require "fig-newton/commands/up"
31
+ command = FigNewton::Commands::Up.new(stack_name)
32
+ command.run(options[:parent_directory])
33
+ end
34
+
35
+ desc "down STACK_NAME", "Bring down all the applications defined for the given stack. Equivalent to running fig down in each application directory."
36
+ option :parent_directory, type: :string,
37
+ default: ".",
38
+ desc: "The parent directory of the cloned repositories"
39
+ def down(stack_name)
40
+ require "fig-newton/commands/down"
41
+ command = FigNewton::Commands::Down.new(stack_name)
42
+ command.run(options[:parent_directory])
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,21 @@
1
+ require "pp"
2
+ require "fig-newton/config"
3
+
4
+ module FigNewton
5
+ module Commands
6
+ class Clone
7
+ def initialize(stack_name)
8
+ @stack_name = stack_name
9
+ @config = FigNewton::Config.from_file(@stack_name)
10
+ end
11
+
12
+ def run(parent_directory)
13
+ config.apps.each { |app| app.clone(parent_directory) }
14
+ end
15
+
16
+ private
17
+
18
+ attr_accessor :config, :stack_name
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ require "fig-newton/config"
2
+
3
+ module FigNewton
4
+ module Commands
5
+ class Down
6
+ def initialize(stack_name)
7
+ @stack_name = stack_name
8
+ @config = FigNewton::Config.from_file(@stack_name)
9
+ end
10
+
11
+ def run(parent_directory)
12
+ config.apps.each { |app| app.down(parent_directory) }
13
+ end
14
+
15
+ private
16
+
17
+ attr_accessor :config, :stack_name
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,48 @@
1
+ require "fig-newton/config"
2
+
3
+ module FigNewton
4
+ module Commands
5
+ class Init
6
+ def initialize(stack_name)
7
+ @stack_name = stack_name
8
+ @yaml = nil
9
+ end
10
+
11
+ def run(forced = false)
12
+ generate_yaml
13
+ write_yaml(forced)
14
+ end
15
+
16
+ private
17
+
18
+ def generate_yaml
19
+ @yaml = unindent(<<-YAML)
20
+ name: #{@stack_name}
21
+ apps:
22
+ tugboat:
23
+ repo: "behance/tugboat"
24
+ example-app:
25
+ repo: "behance/example"
26
+ dir: "xmp"
27
+ YAML
28
+ end
29
+
30
+ def write_yaml(forced)
31
+ if File.exist?(stack_filename) && !forced
32
+ puts "The file \"#{stack_filename}\" already exists. Use --force to overwrite it"
33
+ return
34
+ end
35
+
36
+ File.open(stack_filename, "w") { |f| f.write(@yaml) }
37
+ end
38
+
39
+ def stack_filename
40
+ @filename ||= FigNewton::Config.filepath_from_stack(@stack_name)
41
+ end
42
+
43
+ def unindent(s)
44
+ s.gsub(/^#{s.scan(/^[ \t]+(?=\S)/).min}/, "")
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,20 @@
1
+ require "fig-newton/config"
2
+
3
+ module FigNewton
4
+ module Commands
5
+ class Up
6
+ def initialize(stack_name)
7
+ @stack_name = stack_name
8
+ @config = FigNewton::Config.from_file(@stack_name)
9
+ end
10
+
11
+ def run(parent_directory)
12
+ config.apps.each { |app| app.up(parent_directory) }
13
+ end
14
+
15
+ private
16
+
17
+ attr_accessor :config, :stack_name
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,36 @@
1
+ require "yaml"
2
+ require "fig-newton/app"
3
+
4
+ module FigNewton
5
+ class Config
6
+ def self.filepath_from_stack(stack_name)
7
+ File.join(".", "#{stack_name}.yml")
8
+ end
9
+
10
+ def self.from_file(stack_name)
11
+ filename = filepath_from_stack(stack_name)
12
+ data = YAML::load_file(filename)
13
+
14
+ new(data, filename)
15
+ end
16
+
17
+ def initialize(data, filename)
18
+ @data = data
19
+ @filename = filename
20
+ end
21
+
22
+ def name
23
+ data["name"]
24
+ end
25
+
26
+ def apps
27
+ @apps ||= data["apps"].map do |name, config|
28
+ FigNewton::App.new(name, config)
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ attr_accessor :data, :filename
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module FigNewton
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ require "fig-newton/commands/init"
2
+
3
+ describe FigNewton::Commands::Init do
4
+ end
@@ -0,0 +1,7 @@
1
+ require "fakefs/spec_helpers"
2
+
3
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
4
+
5
+ RSpec.configure do |config|
6
+ config.include FakeFS::SpecHelpers
7
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fig-newton
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sean Dunn
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-02-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.19.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Wrapper tooling around fig to manage application stacks.
56
+ email:
57
+ - sedunn@adobe.com
58
+ executables:
59
+ - fig-newton
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rubocop.yml"
65
+ - Gemfile
66
+ - README.md
67
+ - Rakefile
68
+ - exe/fig-newton
69
+ - fig-newton.gemspec
70
+ - lib/fig-newton.rb
71
+ - lib/fig-newton/app.rb
72
+ - lib/fig-newton/cli.rb
73
+ - lib/fig-newton/commands/clone.rb
74
+ - lib/fig-newton/commands/down.rb
75
+ - lib/fig-newton/commands/init.rb
76
+ - lib/fig-newton/commands/up.rb
77
+ - lib/fig-newton/config.rb
78
+ - lib/fig-newton/version.rb
79
+ - spec/commands/init_spec.rb
80
+ - spec/spec_helper.rb
81
+ homepage: ''
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.2.2
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Wrapper tooling around fig to manage application stacks.
105
+ test_files:
106
+ - spec/commands/init_spec.rb
107
+ - spec/spec_helper.rb
108
+ has_rdoc: