ev_job_gen 0.1.2 → 0.2.1

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
  SHA256:
3
- metadata.gz: '085cb7ea8fc4dfe21cb99b4554be51ba8792748fbb431fe72932d86e6358fdff'
4
- data.tar.gz: 68a29a3f53fb69dcd85a248cad860c3a53e60656596b6f8f7781b6074afc0a6d
3
+ metadata.gz: 911c2e6a913212af70db4fc8c75426db37895ee916b8e1b0e82b1dd3c8ce6e2f
4
+ data.tar.gz: 29519dd22e5f9069d4c64644cb97bc14f74969fa83793d3cf23727942f812def
5
5
  SHA512:
6
- metadata.gz: 28df46930e6a1346de9ccf168cd77fc15a11b74e183d12f97fd59bed79cd142ca77c26b929fd2e76f5cedf9cc0b73df3b2d62f525e6d744b295448b2563ed784
7
- data.tar.gz: 1fdc9edc312ba226e98f0e7ab21acca3729e0a5c60d078ca54560d2f8d309d3edd92961fd55f5c864db824e0b282936eac6a727c3bf2fefb8b4f071c7452dfb4
6
+ metadata.gz: 570463b577ccbc222de9409d4380fe550d8b5641e2d2c2da720fa0ea141e34fffad3665fd3f513b47b1357c2a0e7b0e66c6490bd9016f02699eac7b02b0da500
7
+ data.tar.gz: 81070a6e5e947949f222fca3492d4a58879edfcf92866399e0e662c9fec5055528f228b56f4f7eab7f770f50e99bf402e48cf772be3337fa8bed1a8d1635aac6
data/.travis.yml CHANGED
@@ -3,3 +3,4 @@ language: ruby
3
3
  rvm:
4
4
  - 2.5.1
5
5
  before_install: gem install bundler -v 1.16.2
6
+ script: bundle exec rspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ev_job_gen (0.1.2)
4
+ ev_job_gen (0.2.1)
5
5
  dotenv (~> 2.5.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -52,6 +52,7 @@ metadata:
52
52
  app: ev-job
53
53
  role: job
54
54
  spec:
55
+ backoffLimit: 0
55
56
  schedule: "5 17 * * *"
56
57
  concurrencyPolicy: "Replace"
57
58
  suspend: false
@@ -74,10 +75,11 @@ spec:
74
75
  app: ev-job
75
76
  role: job
76
77
  spec:
78
+
77
79
  restartPolicy: Never
78
80
  containers:
79
81
  - name: ev-job
80
- image: some-docker-registory/wantedly/ml-project-1:latest
82
+ image: some-docker-registory/ml-project-1:latest
81
83
  imagePullPolicy: Always
82
84
  command:
83
85
  - "/bin/bash"
@@ -89,6 +91,7 @@ spec:
89
91
  export AWS_SECRET_ACCESS_KEY=xxx;
90
92
  export AWS_REGION=xxx;
91
93
 
94
+ apt install -y wget;
92
95
  wget https://github.com/wantedly/ev-cli/releases/download/v1.2.3/ev-v1.2.3-linux-amd64.tar.gz;
93
96
  tar xvzf ev-v1.2.3-linux-amd64.tar.gz;
94
97
  cp linux-amd64/ev ev;
@@ -9,6 +9,7 @@ metadata:
9
9
  app: ev-job
10
10
  role: job
11
11
  spec:
12
+ backoffLimit: 0
12
13
  template:
13
14
  metadata:
14
15
  name: ev-job-<%= job.suffix %>
@@ -20,7 +20,7 @@ module EvJobGen
20
20
  else
21
21
  raise "invalid target: #{target}"
22
22
  end
23
- @renderer = YmlRenderer.new(
23
+ @renderer = Renderer.new(
24
24
  template: template,
25
25
  specoffset: specoffset,
26
26
  jobfile: jobfile,
@@ -0,0 +1,18 @@
1
+ require 'erb'
2
+
3
+ module EvJobGen
4
+ class Renderer
5
+ class ManifestRenderer
6
+ def initialize(template:, job:, spec:)
7
+ @renderer = ERB.new(File.read(template))
8
+ @job = job
9
+ @spec = spec
10
+ end
11
+ attr_reader :job, :spec
12
+
13
+ def render
14
+ @renderer.result(binding) # Only use `job` and `spec`
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ require 'erb'
2
+
3
+ module EvJobGen
4
+ class Renderer
5
+ class SpecRenderer
6
+ class << self
7
+ def spec_template_path
8
+ File.expand_path(
9
+ File.join('kubernetes', 'tmpl', 'spec_template.yml.erb'),
10
+ EvJobGen.root,
11
+ )
12
+ end
13
+ end
14
+
15
+ def initialize(job:, config:)
16
+ @job = job
17
+ @config = config
18
+ @renderer = ERB.new(File.read(SpecRenderer.spec_template_path))
19
+ end
20
+ attr_reader :job, :config
21
+
22
+ def render
23
+ @renderer.result(binding) # Only use `job` and `config`
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,38 @@
1
+ require 'ev_job_gen/renderer/manifest_renderer'
2
+ require 'ev_job_gen/renderer/spec_renderer'
3
+
4
+ module EvJobGen
5
+ class Renderer
6
+ def initialize(template:, specoffset:, jobfile:, configfile:)
7
+ @template = template
8
+ @specoffset = specoffset
9
+ @job = EvJobGen::Job.new(jobfile)
10
+ @config = EvJobGen::Config.new(configfile)
11
+ end
12
+
13
+ def render
14
+ spec = SpecRenderer.new(
15
+ job: @job,
16
+ config: @config,
17
+ ).render
18
+
19
+ r = ManifestRenderer.new(
20
+ template: @template,
21
+ job: @job,
22
+ spec: offset(spec, off: @specoffset + 2)
23
+ ).render
24
+
25
+ normalize(r)
26
+ end
27
+
28
+ private
29
+
30
+ def normalize(text)
31
+ text.split("\n").map { |l| l.rstrip }.map { |l| "#{l}\n" }.join
32
+ end
33
+
34
+ def offset(text, off:)
35
+ "\n" + text.split("\n").map { |l| "#{' ' * off}#{l}\n" }.join
36
+ end
37
+ end
38
+ end
@@ -1,3 +1,3 @@
1
1
  module EvJobGen
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/ev_job_gen.rb CHANGED
@@ -3,8 +3,8 @@ require 'dotenv/load'
3
3
  require 'ev_job_gen/cli'
4
4
  require 'ev_job_gen/config'
5
5
  require 'ev_job_gen/job'
6
- require 'ev_job_gen/yml_renderer'
7
6
  require 'ev_job_gen/manifest_gen'
7
+ require 'ev_job_gen/renderer'
8
8
 
9
9
  module EvJobGen
10
10
  class << self
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ev_job_gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nao Minami
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-06 00:00:00.000000000 Z
11
+ date: 2018-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -125,8 +125,10 @@ files:
125
125
  - lib/ev_job_gen/config.rb
126
126
  - lib/ev_job_gen/job.rb
127
127
  - lib/ev_job_gen/manifest_gen.rb
128
+ - lib/ev_job_gen/renderer.rb
129
+ - lib/ev_job_gen/renderer/manifest_renderer.rb
130
+ - lib/ev_job_gen/renderer/spec_renderer.rb
128
131
  - lib/ev_job_gen/version.rb
129
- - lib/ev_job_gen/yml_renderer.rb
130
132
  homepage: https://github.com/wantedly/ev-job-gen
131
133
  licenses:
132
134
  - MIT
@@ -1,38 +0,0 @@
1
- require 'erb'
2
- require 'fileutils'
3
-
4
- module EvJobGen
5
- class YmlRenderer
6
- class << self
7
- def spec_template_path
8
- File.expand_path(
9
- File.join('kubernetes', 'tmpl', 'spec_template.yml.erb'),
10
- EvJobGen.root,
11
- )
12
- end
13
- end
14
-
15
- def initialize(template:, specoffset:, jobfile:, configfile:)
16
- @spec_renderer = ERB.new(File.read(YmlRenderer.spec_template_path))
17
- @specoffset = specoffset
18
- @renderer = ERB.new(File.read(template))
19
- @job = EvJobGen::Job.new(jobfile)
20
- @config = EvJobGen::Config.new(configfile)
21
- end
22
-
23
- attr_reader :job, :config
24
-
25
- def render
26
- spec = render_spec
27
- @renderer.result(binding)
28
- end
29
-
30
- private
31
-
32
- def render_spec
33
- r = @spec_renderer.result(binding)
34
- offset = @specoffset + 2
35
- "\n" + r.split("\n").map { |l| "#{' ' * offset}#{l}\n" }.join
36
- end
37
- end
38
- end