ludwig 0.0.3 → 0.1.0

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: 0b60bb41e36584ba8aac79780e599d4e9bea3249
4
- data.tar.gz: 8863a356d1a716d4f85fed2b303025ec06cd99ea
3
+ metadata.gz: 08cbeeb28adc2c14fff362d279c6b0c171b6558e
4
+ data.tar.gz: bc8bd272d8e319b3ecaedb2d56698fb19bb19db0
5
5
  SHA512:
6
- metadata.gz: 170c200fdabfcd32cae8d1afa9bb82083f2eb3c03f3cd007b867e2d8e82ec0161b501e9cf326f44f758076cd45877d297cc56818bda0ee6f10c59eba08c17bec
7
- data.tar.gz: 83224d7dc22c138b0178c683eb5bda14cdd4eea9bc425b377c768c5a0b4a70c90393fcd290aa83c8339c36e2a4f9f40bbeefd520daccd20d1ff393cec6c26170
6
+ metadata.gz: bcbb49bef423ec620cf3db17e999e2765210cc844d73511232b0647eae3fe98af94943f83199d3c77c2f9c31c71b502ac62606c575e0e764ea4421b392f37cde
7
+ data.tar.gz: 5e65e62e116101a295553a1503a4d718a0f90e993672f9f22d05688c6962c54a2a5669169aea28876ac6a2328a7c7740addde51a9e72803825faff9103f2327d
@@ -13,20 +13,20 @@ module Ludwig
13
13
  global_option('-d', '--debug', 'Enable debug mode') { $debug = true }
14
14
  global_option('-c', '--config filename', String, 'Set config filename') { |config_file| @config_file = config_file }
15
15
 
16
- command :up do |c|
17
- c.syntax = 'ludwig up [options]'
18
- c.summary = 'Generate docker-compose.yml and launch docker-compose'
16
+ command :compose do |c|
17
+ c.syntax = 'ludwig compose [options]'
18
+ c.summary = 'Generate docker-compose.yml'
19
19
  c.action do |args, options|
20
20
  generate_compose_file
21
- system 'docker-compose up'
22
21
  end
23
22
  end
24
23
 
25
- command :build do |c|
26
- c.syntax = 'ludwig build [options]'
27
- c.summary = 'Generate docker-compose.yml'
24
+ command :up do |c|
25
+ c.syntax = 'ludwig up [options]'
26
+ c.summary = 'Generate docker-compose.yml and launch docker-compose'
28
27
  c.action do |args, options|
29
28
  generate_compose_file
29
+ system 'docker-compose up'
30
30
  end
31
31
  end
32
32
 
@@ -1,44 +1,37 @@
1
1
  module Ludwig
2
- class Service < Struct.new(:project, :name, :data, :config)
3
- ACTION_MAP = {
4
- volumes: :volumes_action,
5
- links: :links_action,
6
- env_file: :prefix_path,
7
- build: :prefix_path
8
- }
9
-
2
+ Service = Struct.new(:project, :name, :data, :config) do
10
3
  def generate_yaml
11
- new_data = data.each_with_object({}) do |(key, value), memo|
12
- memo[key] = execute_action(key, value)
13
- end
4
+ transform_data
5
+ merge_extra_links
6
+ new_data
7
+ end
8
+
9
+ private
14
10
 
11
+ def merge_extra_links
15
12
  if extra_links = config["extra_links"][name]
16
13
  new_data["links"] ||= []
17
14
  new_data["links"] += extra_links.map do |app|
18
15
  "#{sanitize(app)}_#{config["default_app"]}:#{sanitize(app)}"
19
16
  end
20
17
  end
18
+ end
21
19
 
22
- new_data
20
+ def new_data
21
+ @new_data ||= {}
23
22
  end
24
23
 
25
- def execute_action(key, obj)
26
- action = ACTION_MAP[key.to_sym]
27
- action ? send(action, obj) : obj
24
+ def sanitize(input)
25
+ input.gsub(/-/, "_")
28
26
  end
29
27
 
30
- def volumes_action(volumes)
31
- volumes.map do |volume|
32
- local, remote = volume.split(":")
33
- if local =~ /^\.\/?/
34
- "#{prefix_path(local)}:#{remote}"
35
- else
36
- volume
37
- end
28
+ def transform_data
29
+ data.each do |key, value|
30
+ new_data[key] = try("transform_#{key}", value) || value
38
31
  end
39
32
  end
40
33
 
41
- def links_action(links)
34
+ def transform_links(links)
42
35
  links.map do |link|
43
36
  link_name, link_alias = link.split(":")
44
37
  link_alias = link_name if link_alias.nil?
@@ -46,12 +39,26 @@ module Ludwig
46
39
  end
47
40
  end
48
41
 
49
- def prefix_path(path)
42
+ def transform_path(path)
50
43
  "../#{project}/#{path}"
51
44
  end
45
+ alias_method :transform_build, :transform_path
46
+ alias_method :transform_env_file, :transform_path
52
47
 
53
- def sanitize(input)
54
- input.gsub(/-/, "_")
48
+ def transform_ports(ports)
49
+ return ports if config['expose_ports'][name]
50
+ ports.map { |port| port.to_s.split(':').last }
51
+ end
52
+
53
+ def transform_volumes(volumes)
54
+ volumes.map do |volume|
55
+ local, remote = volume.split(":")
56
+ local =~ /^\.\/?/ ? "#{transform_path(local)}:#{remote}" : volume
57
+ end
58
+ end
59
+
60
+ def try(*a, &b)
61
+ respond_to?(a.first, true) ? send(*a, &b) : nil
55
62
  end
56
63
  end
57
64
  end
@@ -1,3 +1,3 @@
1
1
  module Ludwig
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ludwig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Stolz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-08 00:00:00.000000000 Z
11
+ date: 2016-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander