altaire-siren 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -2
  3. data/Gemfile +0 -1
  4. data/Gemfile.lock +7 -1
  5. data/altaire-siren.gemspec +1 -0
  6. data/build-schema.rb +206 -0
  7. data/docs/docs/commands/song.md +3 -0
  8. data/fantasia-export.rb +16 -0
  9. data/lib/siren.rb +2 -0
  10. data/lib/siren/cli.rb +16 -1
  11. data/lib/siren/compose.rb +103 -0
  12. data/lib/siren/compose/service.rb +321 -0
  13. data/lib/siren/compose/types.rb +230 -0
  14. data/lib/siren/schemabuilder.rb +56 -0
  15. data/lib/siren/song.rb +78 -50
  16. data/lib/siren/stack.rb +6 -2
  17. data/lib/siren/version.rb +1 -1
  18. data/schemas/docker-compose.yaml +78 -0
  19. metadata +23 -47
  20. data/docs/site/404.html +0 -313
  21. data/docs/site/assets/fonts/font-awesome.css +0 -4
  22. data/docs/site/assets/fonts/material-icons.css +0 -13
  23. data/docs/site/assets/fonts/specimen/FontAwesome.ttf +0 -0
  24. data/docs/site/assets/fonts/specimen/FontAwesome.woff +0 -0
  25. data/docs/site/assets/fonts/specimen/FontAwesome.woff2 +0 -0
  26. data/docs/site/assets/fonts/specimen/MaterialIcons-Regular.ttf +0 -0
  27. data/docs/site/assets/fonts/specimen/MaterialIcons-Regular.woff +0 -0
  28. data/docs/site/assets/fonts/specimen/MaterialIcons-Regular.woff2 +0 -0
  29. data/docs/site/assets/images/favicon.png +0 -0
  30. data/docs/site/assets/images/icons/bitbucket.1b09e088.svg +0 -1
  31. data/docs/site/assets/images/icons/github.f0b8504a.svg +0 -1
  32. data/docs/site/assets/images/icons/gitlab.6dd19c00.svg +0 -1
  33. data/docs/site/assets/javascripts/application.c648116f.js +0 -6
  34. data/docs/site/assets/javascripts/lunr/lunr.da.js +0 -1
  35. data/docs/site/assets/javascripts/lunr/lunr.de.js +0 -1
  36. data/docs/site/assets/javascripts/lunr/lunr.du.js +0 -1
  37. data/docs/site/assets/javascripts/lunr/lunr.es.js +0 -1
  38. data/docs/site/assets/javascripts/lunr/lunr.fi.js +0 -1
  39. data/docs/site/assets/javascripts/lunr/lunr.fr.js +0 -1
  40. data/docs/site/assets/javascripts/lunr/lunr.hu.js +0 -1
  41. data/docs/site/assets/javascripts/lunr/lunr.it.js +0 -1
  42. data/docs/site/assets/javascripts/lunr/lunr.ja.js +0 -1
  43. data/docs/site/assets/javascripts/lunr/lunr.jp.js +0 -1
  44. data/docs/site/assets/javascripts/lunr/lunr.multi.js +0 -1
  45. data/docs/site/assets/javascripts/lunr/lunr.nl.js +0 -1
  46. data/docs/site/assets/javascripts/lunr/lunr.no.js +0 -1
  47. data/docs/site/assets/javascripts/lunr/lunr.pt.js +0 -1
  48. data/docs/site/assets/javascripts/lunr/lunr.ro.js +0 -1
  49. data/docs/site/assets/javascripts/lunr/lunr.ru.js +0 -1
  50. data/docs/site/assets/javascripts/lunr/lunr.stemmer.support.js +0 -1
  51. data/docs/site/assets/javascripts/lunr/lunr.sv.js +0 -1
  52. data/docs/site/assets/javascripts/lunr/lunr.th.js +0 -1
  53. data/docs/site/assets/javascripts/lunr/lunr.tr.js +0 -1
  54. data/docs/site/assets/javascripts/lunr/tinyseg.js +0 -1
  55. data/docs/site/assets/javascripts/lunr/wordcut.js +0 -1
  56. data/docs/site/assets/javascripts/modernizr.74668098.js +0 -1
  57. data/docs/site/assets/stylesheets/application-palette.a8b3c06d.css +0 -1
  58. data/docs/site/assets/stylesheets/application.30686662.css +0 -1
  59. data/docs/site/commands/crypto/index.html +0 -470
  60. data/docs/site/commands/song/index.html +0 -474
  61. data/docs/site/index.html +0 -348
  62. data/docs/site/search/search_index.json +0 -1
  63. data/docs/site/sitemap.xml +0 -18
  64. data/docs/site/sitemap.xml.gz +0 -0
@@ -0,0 +1,56 @@
1
+
2
+ module Siren
3
+ module JSONSchema
4
+ class SchemaBuilder
5
+
6
+ def initialize (&block)
7
+ # @context = { type: "object", additionalProperties: false, properties: {} }
8
+ singleton_class.class_exec(&block)
9
+ schema = build()
10
+ puts JSON.parse(schema.to_json).to_yaml
11
+ end
12
+
13
+ def number (min: nil, max: nil, excl: nil, mul: nil)
14
+ { type: "number", minimum: min, maximum: max, exclusiveMaximum: excl, multipleOf: mul }.compact
15
+ end
16
+
17
+ def integer (min: nil, max: nil, excl: nil, mul: nil)
18
+ { type: "integer", minimum: min, maximum: max, exclusiveMaximum: excl, multipleOf: mul }.compact
19
+ end
20
+
21
+ def bool ()
22
+ { type: "boolean" }
23
+ end
24
+
25
+ alias boolean bool
26
+
27
+ def null ()
28
+ { type: "null" }
29
+ end
30
+
31
+ def string (pattern = nil, min: nil, max: nil)
32
+ pattern = Regexp.escape(pattern) if pattern.is_a?(String)
33
+ pattern = Regexp.new(pattern.map{|p|Regexp.escape(p)}.join("|")) if pattern.is_a?(Array)
34
+ pattern = pattern.inspect[1..-2] if pattern.is_a?(Regexp)
35
+ { type: "string", minLength: min, maxLength: max, pattern: pattern }.compact
36
+ end
37
+
38
+ def array (itemType, min: nil, max: nil, uniq: nil, extra: nil)
39
+ { type: "array", items: itemType, minItems: min, maxItems: max, uniqueItems: uniq, additionalItems: extra}.compact
40
+ end
41
+
42
+ def hash (propType)
43
+ { type: "object", additionalProperties: propType }.compact
44
+ end
45
+
46
+ def object (props, extra: false, required: nil)
47
+ { type: "object", additionalProperties: extra, required: required, properties: props }.compact
48
+ end
49
+
50
+ def any (*options)
51
+ { anyOf: options }
52
+ end
53
+
54
+ end
55
+ end
56
+ end
data/lib/siren/song.rb CHANGED
@@ -12,7 +12,7 @@ module Siren
12
12
 
13
13
  def initialize (data)
14
14
  @name = data["metadata"]["name"]
15
- @ns = data["metadata"]["namespace"]
15
+ @ns = data["metadata"]["namespace"] || @name
16
16
  @spec = data["spec"]
17
17
  process()
18
18
  end
@@ -20,13 +20,18 @@ module Siren
20
20
  def get (what, key)
21
21
  return [] unless what.has_key?(key)
22
22
  val = what[key]
23
- return val if val.is_a?(Array)
23
+ if val.is_a?(Array)
24
+ if val.count{|v|v.is_a?(Hash) && !(v.has_key?(:name) || v.has_key?("name") || v.has_key?(:fullName) || v.has_key?("fullName"))} > 1
25
+ raise "`#{key}`: only one can be anonymous"
26
+ end
27
+ return val
28
+ end
24
29
  return [val]
25
30
  end
26
31
 
27
32
  def process ()
28
33
  @env = {}
29
- @env.merge! process_env(@spec["env"])
34
+ @env.merge! process_env(@spec["env"] || {})
30
35
  @services = get(@spec, "service").map do |svc|
31
36
  svc
32
37
  end
@@ -44,23 +49,6 @@ module Siren
44
49
  return hash
45
50
  end
46
51
 
47
- def to_yaml
48
- data = {
49
- "apiVersion" => "altaire.com/v1alpha1",
50
- "kind" => "Song",
51
- "metadata" => { "name" => @name, "namespace" => @ns }.compact,
52
- "spec" => {
53
- "services" => @services,
54
- "env" => @env,
55
- }
56
- }
57
- JSON.parse(data.to_json).to_yaml
58
- end
59
-
60
- def makename (*parts)
61
- parts.compact.join("-")
62
- end
63
-
64
52
  def env_to_k8s (hash)
65
53
  res = []
66
54
  hash.each do |name, value|
@@ -69,12 +57,28 @@ module Siren
69
57
  res
70
58
  end
71
59
 
60
+ def annotations
61
+ {
62
+ "siren.altaire.xyz/song": @name,
63
+ }
64
+ end
65
+
66
+ def makename (base, obj, name = "name", fullName = "fullName", suffix = nil)
67
+
68
+ return obj[fullName] if obj[fullName]
69
+ [base, name ? obj[name] : nil, suffix].compact.join("-")
70
+ end
71
+
72
72
  def to_deployment (svc)
73
- name = makename(@name, svc["name"])
73
+ name = makename(@name, svc)
74
74
  @stack.things << {
75
75
  apiVersion: "apps/v1",
76
76
  kind: "Deployment",
77
- metadata: { name: name, "namespace" => @ns }.compact,
77
+ metadata: {
78
+ annotations: annotations,
79
+ name: name,
80
+ namespace: @ns,
81
+ }.compact,
78
82
  spec: {
79
83
  selector: {
80
84
  matchLabels: {
@@ -83,13 +87,13 @@ module Siren
83
87
  },
84
88
  template: {
85
89
  metadata: {
90
+ annotations: annotations,
86
91
  labels: {
87
92
  service: name
88
93
  }
89
94
  },
90
95
  spec: {
91
96
  containers: [
92
- name: name,
93
97
  image: svc["image"],
94
98
  env: env_to_k8s(env.merge(svc["env"] || {})),
95
99
  ],
@@ -101,35 +105,47 @@ module Siren
101
105
  end
102
106
 
103
107
  def to_service (svc)
104
- name = makename(@name, svc["name"])
105
- @stack.things << {
106
- apiVersion: "v1",
107
- kind: "Service",
108
- metadata: { name: name, "namespace" => @ns }.compact,
109
- spec: {
110
- selector: {
111
- service: name
112
- },
113
- ports: get(svc, "publish").map do |publish|
114
- {
115
- targetPort: publish["port"],
116
- port: publish["externalPort"] || 80,
117
- }
118
- end
119
- },
120
- }
108
+ svcname = makename(@name, svc)
109
+ get(svc, "publish").group_by{|x|x["loadBalancer"]}.each do |loadbalancer, publish|
110
+ name = makename(svcname, publish[0], "loadBalancer")
111
+ @stack.things << {
112
+ apiVersion: "v1",
113
+ kind: "Service",
114
+ metadata: {
115
+ annotations: annotations,
116
+ name: name,
117
+ namespace: @ns,
118
+ }.compact,
119
+ spec: {
120
+ selector: {
121
+ service: svcname,
122
+ },
123
+ ports: publish.map do |publish|
124
+ {
125
+ targetPort: publish["port"] || 80,
126
+ port: publish["externalPort"] || publish["port"] || 80,
127
+ }
128
+ end,
129
+ type: loadbalancer ? "LoadBalancer" : nil
130
+ }.compact,
131
+ }
132
+ end
121
133
  end
122
134
 
123
135
  def to_certificate (svc)
124
- name = makename(@name, svc["name"])
136
+ name = makename(@name, svc)
125
137
  get(svc, "publish").map do |publish|
126
138
  get(publish, "domain").map do |domain|
127
139
  @stack.things << {
128
140
  apiVersion: "cert-manager.io/v1alpha2",
129
141
  kind: "Certificate",
130
- metadata: { name: name, "namespace" => @ns }.compact,
142
+ metadata: {
143
+ annotations: annotations,
144
+ name: name,
145
+ namespace: @ns,
146
+ }.compact,
131
147
  spec: {
132
- secretName: makename(name, domain, "tls"),
148
+ secretName: [name, get(publish, "domain").length > 1 ? domain : nil, "tls"].compact.join("-"),
133
149
  duration: "2160h",
134
150
  renewBefore: "360h",
135
151
  commonName: domain,
@@ -142,16 +158,20 @@ module Siren
142
158
  end
143
159
 
144
160
  def to_domain (svc)
145
- name = makename(@name, svc["name"])
161
+ name = makename(@name, svc)
146
162
  get(svc, "publish").map do |publish|
147
163
  get(publish, "domain").map do |domain|
148
164
  @stack.things << {
149
165
  apiVersion: "altaire.com/v1alpha1",
150
166
  kind: "Domain",
151
- metadata: { name: makename(name, domain), "namespace" => @ns }.compact,
167
+ metadata: {
168
+ annotations: annotations,
169
+ name: [name, get(publish, "domain").length > 1 ? domain : nil].compact.join("-"),
170
+ namespace: @ns,
171
+ }.compact,
152
172
  spec: {
153
173
  domain: domain,
154
- service: "traefik",
174
+ service: publish["loadBalancer"] ? makename(name, publish["loadBalancer"]) : "traefik",
155
175
  }
156
176
  }
157
177
  end
@@ -159,15 +179,20 @@ module Siren
159
179
  end
160
180
 
161
181
  def to_ingress_route (svc)
162
- name = makename(@name, svc["name"])
182
+ name = makename(@name, svc)
163
183
  get(svc, "publish").map do |publish|
184
+ next if publish["loadBalancer"]
164
185
  get(publish, "domain").map do |domain|
165
186
  @stack.things << {
166
187
  apiVersion: "traefik.containo.us/v1alpha1",
167
188
  kind: "IngressRoute",
168
- metadata: { name: makename(name, domain), "namespace" => @ns }.compact,
189
+ metadata: {
190
+ annotations: annotations,
191
+ name: [name, get(publish, "domain").length > 1 ? domain : nil].compact.join("-"),
192
+ namespace: @ns,
193
+ }.compact,
169
194
  spec: {
170
- tls: { secretName: makename(name, domain, "tls") },
195
+ tls: { secretName: [name, get(publish, "domain").length > 1 ? domain : nil, "tls"].compact.join("-") },
171
196
  routes: [
172
197
  {
173
198
  match: "Host(`#{domain}`)",
@@ -192,7 +217,10 @@ module Siren
192
217
  @stack.things << {
193
218
  apiVersion: "v1",
194
219
  kind: "Namespace",
195
- metadata: { name: @ns },
220
+ metadata: {
221
+ annotations: annotations,
222
+ name: @ns,
223
+ }.compact,
196
224
  }
197
225
  end
198
226
 
data/lib/siren/stack.rb CHANGED
@@ -14,9 +14,13 @@ module Siren
14
14
  @things = []
15
15
  end
16
16
 
17
+ def << (thing)
18
+ @things << thing
19
+ end
20
+
17
21
  def to_yaml ()
18
- @things.map do |thing|
19
- JSON.parse(thing.to_json).to_yaml
22
+ @things.uniq.map do |thing|
23
+ JSON.parse(thing.deep_compact.to_json).to_yaml
20
24
  end.join
21
25
  end
22
26
 
data/lib/siren/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Siren
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -0,0 +1,78 @@
1
+ ---
2
+ type: object
3
+ additionalProperties: false
4
+ properties:
5
+ version:
6
+ type: string
7
+ services:
8
+ type: object
9
+ additionalProperties:
10
+ type: object
11
+ additionalProperties: false
12
+ properties:
13
+ image:
14
+ type: string
15
+ build:
16
+ type: string
17
+ ports:
18
+ type: array
19
+ items:
20
+ type: string
21
+ volumes:
22
+ type: array
23
+ items:
24
+ type: string
25
+ environment:
26
+ anyOf:
27
+ - type: array
28
+ items:
29
+ type: string
30
+ - type: object
31
+ additionalProperties:
32
+ type: string
33
+ deploy:
34
+ type: object
35
+ additionalProperties: false
36
+ properties:
37
+ replicas:
38
+ type: integer
39
+ command:
40
+ anyOf:
41
+ - type: string
42
+ - type: array
43
+ items:
44
+ type: string
45
+ x-domains:
46
+ type: array
47
+ items:
48
+ type: object
49
+ additionalProperties: false
50
+ properties:
51
+ name:
52
+ type: string
53
+ path:
54
+ type: string
55
+ service:
56
+ type: string
57
+ port:
58
+ type: string
59
+ auth:
60
+ type: string
61
+ x-ports:
62
+ type: array
63
+ items:
64
+ type: object
65
+ additionalProperties: false
66
+ properties:
67
+ service:
68
+ type: string
69
+ inside:
70
+ type: string
71
+ outside:
72
+ type: string
73
+ protocol:
74
+ type: string
75
+ x-env:
76
+ type: object
77
+ additionalProperties:
78
+ type: string
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: altaire-siren
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Baum
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-28 00:00:00.000000000 Z
11
+ date: 2019-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jose
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.3.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: json-schema
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 2.8.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 2.8.1
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -125,64 +139,26 @@ files:
125
139
  - altaire-siren.gemspec
126
140
  - bin/console
127
141
  - bin/setup
142
+ - build-schema.rb
128
143
  - docs/docs/commands/crypto.md
129
144
  - docs/docs/commands/song.md
130
145
  - docs/docs/index.md
131
146
  - docs/mkdocs.yml
132
147
  - docs/serve.sh
133
- - docs/site/404.html
134
- - docs/site/assets/fonts/font-awesome.css
135
- - docs/site/assets/fonts/material-icons.css
136
- - docs/site/assets/fonts/specimen/FontAwesome.ttf
137
- - docs/site/assets/fonts/specimen/FontAwesome.woff
138
- - docs/site/assets/fonts/specimen/FontAwesome.woff2
139
- - docs/site/assets/fonts/specimen/MaterialIcons-Regular.ttf
140
- - docs/site/assets/fonts/specimen/MaterialIcons-Regular.woff
141
- - docs/site/assets/fonts/specimen/MaterialIcons-Regular.woff2
142
- - docs/site/assets/images/favicon.png
143
- - docs/site/assets/images/icons/bitbucket.1b09e088.svg
144
- - docs/site/assets/images/icons/github.f0b8504a.svg
145
- - docs/site/assets/images/icons/gitlab.6dd19c00.svg
146
- - docs/site/assets/javascripts/application.c648116f.js
147
- - docs/site/assets/javascripts/lunr/lunr.da.js
148
- - docs/site/assets/javascripts/lunr/lunr.de.js
149
- - docs/site/assets/javascripts/lunr/lunr.du.js
150
- - docs/site/assets/javascripts/lunr/lunr.es.js
151
- - docs/site/assets/javascripts/lunr/lunr.fi.js
152
- - docs/site/assets/javascripts/lunr/lunr.fr.js
153
- - docs/site/assets/javascripts/lunr/lunr.hu.js
154
- - docs/site/assets/javascripts/lunr/lunr.it.js
155
- - docs/site/assets/javascripts/lunr/lunr.ja.js
156
- - docs/site/assets/javascripts/lunr/lunr.jp.js
157
- - docs/site/assets/javascripts/lunr/lunr.multi.js
158
- - docs/site/assets/javascripts/lunr/lunr.nl.js
159
- - docs/site/assets/javascripts/lunr/lunr.no.js
160
- - docs/site/assets/javascripts/lunr/lunr.pt.js
161
- - docs/site/assets/javascripts/lunr/lunr.ro.js
162
- - docs/site/assets/javascripts/lunr/lunr.ru.js
163
- - docs/site/assets/javascripts/lunr/lunr.stemmer.support.js
164
- - docs/site/assets/javascripts/lunr/lunr.sv.js
165
- - docs/site/assets/javascripts/lunr/lunr.th.js
166
- - docs/site/assets/javascripts/lunr/lunr.tr.js
167
- - docs/site/assets/javascripts/lunr/tinyseg.js
168
- - docs/site/assets/javascripts/lunr/wordcut.js
169
- - docs/site/assets/javascripts/modernizr.74668098.js
170
- - docs/site/assets/stylesheets/application-palette.a8b3c06d.css
171
- - docs/site/assets/stylesheets/application.30686662.css
172
- - docs/site/commands/crypto/index.html
173
- - docs/site/commands/song/index.html
174
- - docs/site/index.html
175
- - docs/site/search/search_index.json
176
- - docs/site/sitemap.xml
177
- - docs/site/sitemap.xml.gz
178
148
  - exe/siren
149
+ - fantasia-export.rb
179
150
  - lib/siren.rb
180
151
  - lib/siren/cli.rb
152
+ - lib/siren/compose.rb
153
+ - lib/siren/compose/service.rb
154
+ - lib/siren/compose/types.rb
181
155
  - lib/siren/crypto.rb
156
+ - lib/siren/schemabuilder.rb
182
157
  - lib/siren/song.rb
183
158
  - lib/siren/stack.rb
184
159
  - lib/siren/version.rb
185
160
  - public.jwk
161
+ - schemas/docker-compose.yaml
186
162
  homepage: http://docs.altaire.xyz/siren
187
163
  licenses:
188
164
  - MIT