phoebo 0.2.3 → 0.2.4
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 +4 -4
- data/lib/phoebo/config.rb +90 -6
- data/lib/phoebo/config/image.rb +24 -2
- data/lib/phoebo/docker/image_builder.rb +7 -4
- data/lib/phoebo/version.rb +1 -1
- data/spec/phoebo/config_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79a698357c05fcfd2bf85d0e8e0401d21de7fd67
|
4
|
+
data.tar.gz: 8f194beb7a95e1fe063d3c3a3ecc6a8b9bf3abff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec764c25bd1cfbc49185cb3c66dae19fdc2660994be5ccc3cc9ee9f74b3882fb4e583ede1bb0506ef7f4f0e0d512cc646477ea6eb7217edb94fdfe9fc8d131e7
|
7
|
+
data.tar.gz: 42a9ecc1c64f7b747ae53247be494c2bb08faee16f421643a1a2e5a07c983b4ae9b80e0e5d8fce7806a271263479cc0ddeabf77d1484480057078efe2d8bef82
|
data/lib/phoebo/config.rb
CHANGED
@@ -33,6 +33,19 @@ module Phoebo
|
|
33
33
|
def dsl_eval(block)
|
34
34
|
@dsl ||= DSL.new(self)
|
35
35
|
@dsl.instance_eval(&block)
|
36
|
+
|
37
|
+
# Finish config
|
38
|
+
@tasks.each do |task|
|
39
|
+
unless task[:image]
|
40
|
+
if @images.size == 1
|
41
|
+
task[:image] = @images.first.name
|
42
|
+
else
|
43
|
+
id = task[:service] ? "service #{task[:name]}" : "task #{task[:name]}"
|
44
|
+
raise Phoebo::SyntaxError.new("You need to define image for #{id}.")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
36
49
|
self
|
37
50
|
end
|
38
51
|
|
@@ -42,22 +55,93 @@ module Phoebo
|
|
42
55
|
@config = config
|
43
56
|
end
|
44
57
|
|
45
|
-
def image(name,
|
46
|
-
@config.images << (img_instance = Image.new(name,
|
58
|
+
def image(name, options, &block)
|
59
|
+
@config.images << (img_instance = Image.new(name, options, block))
|
47
60
|
img_instance
|
48
61
|
end
|
49
62
|
|
63
|
+
def service(name, options = {})
|
64
|
+
_task_definition_check('service', name, options)
|
65
|
+
|
66
|
+
task = {
|
67
|
+
name: name.to_s,
|
68
|
+
service: true
|
69
|
+
}
|
70
|
+
|
71
|
+
_apply_task_options(task, options)
|
72
|
+
|
73
|
+
if options[:ports]
|
74
|
+
if options[:ports].is_a?(Array)
|
75
|
+
task[:ports] = options[:ports].collect do |port_def|
|
76
|
+
if port_def.is_a?(Hash) && port_def.size == 1
|
77
|
+
{ port_def.keys.first.to_sym => port_def.values.first.to_i }
|
78
|
+
else
|
79
|
+
raise Phoebo::SyntaxError.new("Expected port definition in form { tcp: 1234 } for service #{name}")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
else
|
83
|
+
raise Phoebo::SyntaxError.new("Expected Array for ports definition of service #{name}.")
|
84
|
+
end
|
85
|
+
|
86
|
+
options.delete(:ports)
|
87
|
+
end
|
88
|
+
|
89
|
+
unless options.empty?
|
90
|
+
raise Phoebo::SyntaxError.new("Unexpected parameter #{options.keys.first} for service #{name}.")
|
91
|
+
end
|
92
|
+
|
93
|
+
puts task.inspect
|
94
|
+
|
95
|
+
@config.tasks << task
|
96
|
+
task
|
97
|
+
end
|
98
|
+
|
50
99
|
def task(name, image, *args)
|
100
|
+
_task_definition_check('service', name, options)
|
101
|
+
|
51
102
|
task = {
|
52
|
-
name: name
|
53
|
-
image: image
|
103
|
+
name: name.to_s
|
54
104
|
}
|
55
105
|
|
56
|
-
task
|
106
|
+
_apply_task_options(task, options)
|
107
|
+
|
108
|
+
unless options.empty?
|
109
|
+
raise Phoebo::SyntaxError.new("Unexpected parameter #{options.keys.first} for task #{name}.")
|
110
|
+
end
|
111
|
+
|
57
112
|
@config.tasks << task
|
58
113
|
task
|
59
114
|
end
|
60
|
-
end
|
61
115
|
|
116
|
+
private
|
117
|
+
|
118
|
+
def _task_definition_check(subject, name, options)
|
119
|
+
raise Phoebo::SyntaxError.new("Name required for #{subject} definition.") if name.to_s.empty?
|
120
|
+
raise Phoebo::SyntaxError.new("Unexpected block for #{subject} #{name}.") if block_given?
|
121
|
+
raise Phoebo::SyntaxError.new("Unexpected parameters for #{subject} #{name}. Expected Hash.") unless options.is_a?(Hash)
|
122
|
+
end
|
123
|
+
|
124
|
+
def _apply_task_options(task, options)
|
125
|
+
if options[:image]
|
126
|
+
task[:image] = options[:image].to_s
|
127
|
+
options.delete(:image)
|
128
|
+
end
|
129
|
+
|
130
|
+
if options[:command]
|
131
|
+
task[:command] = options[:command].to_s
|
132
|
+
options.delete(:command)
|
133
|
+
end
|
134
|
+
|
135
|
+
if options[:arguments]
|
136
|
+
if options[:arguments].is_a?(Array)
|
137
|
+
task[:arguments] = options[:arguments].collect { |item| item.to_s }
|
138
|
+
else
|
139
|
+
task[:arguments] = [ options[:arguments].to_s ]
|
140
|
+
end
|
141
|
+
|
142
|
+
options.delete(:arguments)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
62
146
|
end
|
63
147
|
end
|
data/lib/phoebo/config/image.rb
CHANGED
@@ -3,10 +3,32 @@ module Phoebo
|
|
3
3
|
class Image
|
4
4
|
attr_accessor :actions, :name, :from
|
5
5
|
|
6
|
-
def initialize(name,
|
6
|
+
def initialize(name, options, block = nil)
|
7
7
|
@actions = []
|
8
8
|
@name = name
|
9
|
-
|
9
|
+
|
10
|
+
if options.is_a?(Hash)
|
11
|
+
|
12
|
+
# image('my-image', from: 'base-image')
|
13
|
+
if options[:from]
|
14
|
+
@from = [ :image, options[:from] ]
|
15
|
+
raise Phoebo::SyntaxError.new('You can only use from: or from_dockerfile: directive as a base for your images.') if options[:from_dockerfile]
|
16
|
+
|
17
|
+
# image('my-image', from_dockerfile: 'Dockerfile')
|
18
|
+
elsif
|
19
|
+
@from = [ :dockerfile, options[:from_dockerfile] ]
|
20
|
+
raise Phoebo::SyntaxError.new('Building from Dockerfile is not supported yet.')
|
21
|
+
end
|
22
|
+
|
23
|
+
# Support for image('my-image', 'base-image')
|
24
|
+
else
|
25
|
+
@from = [ :base_image, options ]
|
26
|
+
end
|
27
|
+
|
28
|
+
unless @from
|
29
|
+
raise Phoebo::SyntaxError.new('You need to specify base for your image (use from: or from_dockerfile:).')
|
30
|
+
end
|
31
|
+
|
10
32
|
dsl_eval(block) if block
|
11
33
|
end
|
12
34
|
|
@@ -14,11 +14,14 @@ module Phoebo
|
|
14
14
|
def build(image)
|
15
15
|
project_files = { }
|
16
16
|
dockerfile = []
|
17
|
-
dockerfile << "FROM #{image.from}"
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
if image.from.first == :base_image
|
19
|
+
dockerfile << "FROM #{image.from[1]}"
|
20
|
+
|
21
|
+
# Apply all defined actions
|
22
|
+
image.actions.each do |action|
|
23
|
+
action.call(dockerfile, project_files)
|
24
|
+
end
|
22
25
|
end
|
23
26
|
|
24
27
|
# TODO: Honor file mode
|
data/lib/phoebo/version.rb
CHANGED
data/spec/phoebo/config_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phoebo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Staněk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|