ev_job_gen 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/ISSUE_TEMPLATE.md +6 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +6 -0
- data/.gitignore +8 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +48 -0
- data/LICENSE.txt +21 -0
- data/README.md +115 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ev_job_gen.gemspec +32 -0
- data/exe/ev-job-gen +6 -0
- data/kubernetes/jobs/.gitkeeep +0 -0
- data/kubernetes/tmpl/cron_job_template.yml.erb +33 -0
- data/kubernetes/tmpl/oneshot_job_template.yml.erb +19 -0
- data/kubernetes/tmpl/spec_template.yml.erb +26 -0
- data/lib/ev_job_gen.rb +19 -0
- data/lib/ev_job_gen/cli.rb +25 -0
- data/lib/ev_job_gen/cli/option.rb +36 -0
- data/lib/ev_job_gen/config.rb +39 -0
- data/lib/ev_job_gen/job.rb +40 -0
- data/lib/ev_job_gen/manifest_gen.rb +35 -0
- data/lib/ev_job_gen/version.rb +3 -0
- data/lib/ev_job_gen/yml_renderer.rb +38 -0
- metadata +154 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ef051014a01fbf1e28657f8816672a3d1f7c8ec85896df9f1055f06637ecb7a7
|
4
|
+
data.tar.gz: 9a820a963bfda3d53cf9db78382609c888c45661ba641b5935a9e24fcd50510d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6018b587a63bf310ffdceeb5e026a688c288cf8c9d684e5b0404dcc6b95888b754195edbe7be9b22e8384e8c79afa8fdf8b6a38534d367de124591ef7f19dc4f
|
7
|
+
data.tar.gz: 3ad0324796be638b7c0d33e3db34058d65ee1268c75b22d988aab846285b3860934e1462056b86def1196d349263502c0fb6dcf67eadcefb65ecdd776470e4ce
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ev_job_gen (0.1.0)
|
5
|
+
dotenv (~> 2.5.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
coderay (1.1.2)
|
11
|
+
diff-lcs (1.3)
|
12
|
+
dotenv (2.5.0)
|
13
|
+
method_source (0.9.0)
|
14
|
+
pry (0.11.3)
|
15
|
+
coderay (~> 1.1.0)
|
16
|
+
method_source (~> 0.9.0)
|
17
|
+
pry-doc (0.13.4)
|
18
|
+
pry (~> 0.11)
|
19
|
+
yard (~> 0.9.11)
|
20
|
+
rake (10.5.0)
|
21
|
+
rspec (3.7.0)
|
22
|
+
rspec-core (~> 3.7.0)
|
23
|
+
rspec-expectations (~> 3.7.0)
|
24
|
+
rspec-mocks (~> 3.7.0)
|
25
|
+
rspec-core (3.7.1)
|
26
|
+
rspec-support (~> 3.7.0)
|
27
|
+
rspec-expectations (3.7.0)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.7.0)
|
30
|
+
rspec-mocks (3.7.0)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.7.0)
|
33
|
+
rspec-support (3.7.1)
|
34
|
+
yard (0.9.15)
|
35
|
+
|
36
|
+
PLATFORMS
|
37
|
+
ruby
|
38
|
+
|
39
|
+
DEPENDENCIES
|
40
|
+
bundler (~> 1.16)
|
41
|
+
ev_job_gen!
|
42
|
+
pry
|
43
|
+
pry-doc
|
44
|
+
rake (~> 10.0)
|
45
|
+
rspec (~> 3.7)
|
46
|
+
|
47
|
+
BUNDLED WITH
|
48
|
+
1.16.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Nao Minami
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
# EvJobGen
|
2
|
+
Generator of kubernetes manifest file for evaluation job.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'ev_job_gen'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install ev_job_gen
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Place a yml file in jobs directory
|
23
|
+
|
24
|
+
```yml
|
25
|
+
# Ex. ml-project-1.yml
|
26
|
+
namespace: ml-project-1
|
27
|
+
image: some-docker-registory/ml-project-1:latest
|
28
|
+
command: >
|
29
|
+
script/evaluate | tee /tmp/out.txt;
|
30
|
+
out: /tmp/out.txt
|
31
|
+
metrics: /tmp/metrics.json
|
32
|
+
commithash: ${COMMITHASH}
|
33
|
+
```
|
34
|
+
|
35
|
+
Then execute `ev-job-gen` command.
|
36
|
+
|
37
|
+
```console
|
38
|
+
$ ev-job-gen --jobfile jobs/ml-project-1.yml
|
39
|
+
```
|
40
|
+
|
41
|
+
It generates manifest file for cron job which executes evaluation.
|
42
|
+
|
43
|
+
```yml
|
44
|
+
apiVersion: batch/v1beta1
|
45
|
+
kind: CronJob
|
46
|
+
metadata:
|
47
|
+
name: ev-job
|
48
|
+
namespace: ml-project-1
|
49
|
+
labels:
|
50
|
+
name: ev-job
|
51
|
+
namespace: ml-project-1
|
52
|
+
app: ev-job
|
53
|
+
role: job
|
54
|
+
spec:
|
55
|
+
schedule: "5 17 * * *"
|
56
|
+
concurrencyPolicy: "Replace"
|
57
|
+
suspend: false
|
58
|
+
successfulJobsHistoryLimit: 10
|
59
|
+
failedJobsHistoryLimit: 3
|
60
|
+
jobTemplate:
|
61
|
+
metadata:
|
62
|
+
name: ev-job
|
63
|
+
labels:
|
64
|
+
name: ev-job
|
65
|
+
app: ev-job
|
66
|
+
role: job
|
67
|
+
spec:
|
68
|
+
backoffLimit: 1
|
69
|
+
template:
|
70
|
+
metadata:
|
71
|
+
name: ev-job
|
72
|
+
labels:
|
73
|
+
name: ev-job
|
74
|
+
app: ev-job
|
75
|
+
role: job
|
76
|
+
spec:
|
77
|
+
restartPolicy: Never
|
78
|
+
containers:
|
79
|
+
- name: ev-job
|
80
|
+
image: some-docker-registory/wantedly/ml-project-1:latest
|
81
|
+
imagePullPolicy: Always
|
82
|
+
command:
|
83
|
+
- "/bin/bash"
|
84
|
+
- "-c"
|
85
|
+
- >
|
86
|
+
script/evaluate | tee /tmp/out.txt;
|
87
|
+
|
88
|
+
export AWS_ACCESS_KEY_ID=xxx;
|
89
|
+
export AWS_SECRET_ACCESS_KEY=xxx;
|
90
|
+
export AWS_REGION=xxx;
|
91
|
+
|
92
|
+
wget https://github.com/wantedly/ev-cli/releases/download/v1.2.3/ev-v1.2.3-linux-amd64.tar.gz;
|
93
|
+
tar xvzf ev-v1.2.3-linux-amd64.tar.gz;
|
94
|
+
cp linux-amd64/ev ev;
|
95
|
+
|
96
|
+
./ev upload --branch master \
|
97
|
+
--commit ${COMMITHASH} \
|
98
|
+
--out /tmp/out.txt \
|
99
|
+
--metrics /tmp/metrics.json \
|
100
|
+
--namespace ml-project-1;
|
101
|
+
```
|
102
|
+
|
103
|
+
## Development
|
104
|
+
|
105
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake true` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
106
|
+
|
107
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
108
|
+
|
109
|
+
## Contributing
|
110
|
+
|
111
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/south37/ev-job-gen.
|
112
|
+
|
113
|
+
## License
|
114
|
+
|
115
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ev_job_gen"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/ev_job_gen.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "ev_job_gen/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ev_job_gen"
|
8
|
+
spec.version = EvJobGen::VERSION
|
9
|
+
spec.authors = ["Nao Minami"]
|
10
|
+
spec.email = ["south37777@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Generator of kubernetes manifest file for evaluation job.}
|
13
|
+
spec.description = %q{Generator of kubernetes manifest file for evaluation job.}
|
14
|
+
spec.homepage = "https://github.com/south37/ev-job-gen"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_dependency "dotenv", "~> 2.5.0"
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.7"
|
30
|
+
spec.add_development_dependency "pry"
|
31
|
+
spec.add_development_dependency "pry-doc"
|
32
|
+
end
|
data/exe/ev-job-gen
ADDED
File without changes
|
@@ -0,0 +1,33 @@
|
|
1
|
+
apiVersion: batch/v1beta1
|
2
|
+
kind: CronJob
|
3
|
+
metadata:
|
4
|
+
name: ev-job
|
5
|
+
namespace: <%= job.namespace %>
|
6
|
+
labels:
|
7
|
+
name: ev-job
|
8
|
+
namespace: <%= job.namespace %>
|
9
|
+
app: ev-job
|
10
|
+
role: job
|
11
|
+
spec:
|
12
|
+
schedule: "5 17 * * *"
|
13
|
+
concurrencyPolicy: "Replace"
|
14
|
+
suspend: false
|
15
|
+
successfulJobsHistoryLimit: 10
|
16
|
+
failedJobsHistoryLimit: 3
|
17
|
+
jobTemplate:
|
18
|
+
metadata:
|
19
|
+
name: ev-job
|
20
|
+
labels:
|
21
|
+
name: ev-job
|
22
|
+
app: ev-job
|
23
|
+
role: job
|
24
|
+
spec:
|
25
|
+
backoffLimit: 1
|
26
|
+
template:
|
27
|
+
metadata:
|
28
|
+
name: ev-job
|
29
|
+
labels:
|
30
|
+
name: ev-job
|
31
|
+
app: ev-job
|
32
|
+
role: job
|
33
|
+
spec: <%= spec %>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
apiVersion: batch/v1
|
2
|
+
kind: Job
|
3
|
+
metadata:
|
4
|
+
name: ev-job-<%= job.suffix %>
|
5
|
+
namespace: <%= job.namespace %>
|
6
|
+
labels:
|
7
|
+
name: ev-job-<%= job.suffix %>
|
8
|
+
namespace: <%= job.namespace %>
|
9
|
+
app: ev-job
|
10
|
+
role: job
|
11
|
+
spec:
|
12
|
+
template:
|
13
|
+
metadata:
|
14
|
+
name: ev-job-<%= job.suffix %>
|
15
|
+
labels:
|
16
|
+
name: ev-job-<%= job.suffix %>
|
17
|
+
app: ev-job
|
18
|
+
role: job
|
19
|
+
spec: <%= spec %>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<%= config.imagePullSecrets %>
|
2
|
+
restartPolicy: Never
|
3
|
+
containers:
|
4
|
+
- name: ev-job
|
5
|
+
image: <%= job.image %>
|
6
|
+
imagePullPolicy: Always
|
7
|
+
command:
|
8
|
+
- "/bin/bash"
|
9
|
+
- "-c"
|
10
|
+
- >
|
11
|
+
<%= job.command.strip %>
|
12
|
+
|
13
|
+
export AWS_ACCESS_KEY_ID=<%= ENV['AWS_ACCESS_KEY_ID'] %>;
|
14
|
+
export AWS_SECRET_ACCESS_KEY=<%= ENV['AWS_SECRET_ACCESS_KEY'] %>;
|
15
|
+
export AWS_REGION=<%= ENV['AWS_REGION'] %>;
|
16
|
+
|
17
|
+
wget https://github.com/wantedly/ev-cli/releases/download/v1.2.3/ev-v1.2.3-linux-amd64.tar.gz;
|
18
|
+
tar xvzf ev-v1.2.3-linux-amd64.tar.gz;
|
19
|
+
cp linux-amd64/ev ev;
|
20
|
+
|
21
|
+
./ev upload --branch master \
|
22
|
+
--commit <%= job.commithash %> \
|
23
|
+
--out <%= job.out %> \
|
24
|
+
--metrics <%= job.metrics %> \
|
25
|
+
--namespace <%= job.namespace %>;
|
26
|
+
<%= config.containers_envFrom(offset: 2) %>
|
data/lib/ev_job_gen.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'dotenv/load'
|
2
|
+
|
3
|
+
require 'ev_job_gen/cli'
|
4
|
+
require 'ev_job_gen/config'
|
5
|
+
require 'ev_job_gen/job'
|
6
|
+
require 'ev_job_gen/yml_renderer'
|
7
|
+
require 'ev_job_gen/manifest_gen'
|
8
|
+
|
9
|
+
module EvJobGen
|
10
|
+
class << self
|
11
|
+
def root
|
12
|
+
File.expand_path(File.join('..', '..'), __FILE__)
|
13
|
+
end
|
14
|
+
|
15
|
+
def tmpl_dir
|
16
|
+
File.expand_path(File.join('kubernetes', 'tmpl'), self.root)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'ev_job_gen/cli/option'
|
2
|
+
|
3
|
+
module EvJobGen
|
4
|
+
class CLI
|
5
|
+
class << self
|
6
|
+
def run!(argv)
|
7
|
+
CLI.new(argv).run!
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(argv)
|
12
|
+
@option = Option.new
|
13
|
+
@option.parse!(argv)
|
14
|
+
end
|
15
|
+
|
16
|
+
def run!
|
17
|
+
yml = ManifestGen.gen(
|
18
|
+
jobfile: @option.jobfile,
|
19
|
+
target: @option.target,
|
20
|
+
configfile: @option.config,
|
21
|
+
)
|
22
|
+
print yml
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module EvJobGen
|
4
|
+
class CLI
|
5
|
+
class Option
|
6
|
+
attr_reader :jobfile, :target, :config
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@jobfile = nil
|
10
|
+
@target = "cronjob"
|
11
|
+
@config = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def parse!(argv)
|
15
|
+
opt = OptionParser.new
|
16
|
+
opt.on('--jobfile jobfile') { |v| @jobfile = v }
|
17
|
+
opt.on('--target [target]') { |v| @target = v }
|
18
|
+
opt.on('--config [config]') { |v| @config = v }
|
19
|
+
opt.parse!(argv)
|
20
|
+
validate!
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def validate!
|
26
|
+
if !@jobfile
|
27
|
+
raise "<jobfile> is required!"
|
28
|
+
end
|
29
|
+
|
30
|
+
if !["cronjob", "job"].include?(@target)
|
31
|
+
raise '<target> must be "cronjob" or "job"'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module EvJobGen
|
4
|
+
class Config
|
5
|
+
def initialize(configfile)
|
6
|
+
if configfile
|
7
|
+
@yml = YAML.load_file(configfile)
|
8
|
+
else
|
9
|
+
@yml = nil
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def imagePullSecrets
|
14
|
+
v = fetch("imagePullSecrets")
|
15
|
+
return nil if !v
|
16
|
+
dump({ "imagePullSecrets" => v })
|
17
|
+
end
|
18
|
+
|
19
|
+
def containers_envFrom(offset:)
|
20
|
+
v = fetch("containers.envFrom")
|
21
|
+
return nil if !v
|
22
|
+
|
23
|
+
s = dump({ "envFrom" => v })
|
24
|
+
s.split("\n").map { |l| "#{' ' * offset}#{l}\n" }.join
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def fetch(key)
|
30
|
+
return nil if !@yml
|
31
|
+
@yml[key]
|
32
|
+
end
|
33
|
+
|
34
|
+
def dump(h)
|
35
|
+
# NOTE: yml has "---" in first line, so trim it.
|
36
|
+
YAML.dump(h).gsub(/^---\n/, '').strip
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module EvJobGen
|
4
|
+
class Job
|
5
|
+
CHARS = [*'a'..'z'] + [*'0'..'9']
|
6
|
+
|
7
|
+
def initialize(yml_file)
|
8
|
+
h = YAML.load_file(yml_file)
|
9
|
+
validate!(h)
|
10
|
+
@namespace = h["namespace"]
|
11
|
+
@image = h["image"]
|
12
|
+
@command = h["command"]
|
13
|
+
@out = h["out"]
|
14
|
+
@metrics = h["metrics"]
|
15
|
+
@commithash = h["commithash"]
|
16
|
+
|
17
|
+
# NOTE: suffix is used only for oneshot job
|
18
|
+
@suffix = 5.times.map { CHARS.sample }.join
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_reader :namespace, :image, :command, :out, :metrics, :commithash, :suffix
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def validate!(h)
|
26
|
+
validate_column!(h, "namespace")
|
27
|
+
validate_column!(h, "image")
|
28
|
+
validate_column!(h, "command")
|
29
|
+
validate_column!(h, "out")
|
30
|
+
validate_column!(h, "metrics")
|
31
|
+
validate_column!(h, "commithash")
|
32
|
+
end
|
33
|
+
|
34
|
+
def validate_column!(h, column)
|
35
|
+
if !h[column]
|
36
|
+
raise "#{column} must be specified, but got #{h[column]}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module EvJobGen
|
2
|
+
class ManifestGen
|
3
|
+
class << self
|
4
|
+
def gen(jobfile:, target:, configfile:)
|
5
|
+
self.new(jobfile: jobfile, target: target, configfile: configfile).gen
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
CRONJOB_TEMPLATE_FILE = "cron_job_template.yml.erb"
|
10
|
+
ONESHOTJOB_TEMPLATE_FILE = "oneshot_job_template.yml.erb"
|
11
|
+
|
12
|
+
def initialize(jobfile:, target:, configfile:)
|
13
|
+
case target
|
14
|
+
when "cronjob"
|
15
|
+
template = File.join(EvJobGen.tmpl_dir, CRONJOB_TEMPLATE_FILE)
|
16
|
+
specoffset = 8
|
17
|
+
when "job"
|
18
|
+
template = File.join(EvJobGen.tmpl_dir, ONESHOTJOB_TEMPLATE_FILE)
|
19
|
+
specoffset = 4
|
20
|
+
else
|
21
|
+
raise "invalid target: #{target}"
|
22
|
+
end
|
23
|
+
@renderer = YmlRenderer.new(
|
24
|
+
template: template,
|
25
|
+
specoffset: specoffset,
|
26
|
+
jobfile: jobfile,
|
27
|
+
configfile: configfile,
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
def gen
|
32
|
+
@renderer.render
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,38 @@
|
|
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
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ev_job_gen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nao Minami
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dotenv
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.5.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.5.0
|
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.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
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
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-doc
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Generator of kubernetes manifest file for evaluation job.
|
98
|
+
email:
|
99
|
+
- south37777@gmail.com
|
100
|
+
executables:
|
101
|
+
- ev-job-gen
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".github/ISSUE_TEMPLATE.md"
|
106
|
+
- ".github/PULL_REQUEST_TEMPLATE.md"
|
107
|
+
- ".gitignore"
|
108
|
+
- ".travis.yml"
|
109
|
+
- Gemfile
|
110
|
+
- Gemfile.lock
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- bin/console
|
115
|
+
- bin/setup
|
116
|
+
- ev_job_gen.gemspec
|
117
|
+
- exe/ev-job-gen
|
118
|
+
- kubernetes/jobs/.gitkeeep
|
119
|
+
- kubernetes/tmpl/cron_job_template.yml.erb
|
120
|
+
- kubernetes/tmpl/oneshot_job_template.yml.erb
|
121
|
+
- kubernetes/tmpl/spec_template.yml.erb
|
122
|
+
- lib/ev_job_gen.rb
|
123
|
+
- lib/ev_job_gen/cli.rb
|
124
|
+
- lib/ev_job_gen/cli/option.rb
|
125
|
+
- lib/ev_job_gen/config.rb
|
126
|
+
- lib/ev_job_gen/job.rb
|
127
|
+
- lib/ev_job_gen/manifest_gen.rb
|
128
|
+
- lib/ev_job_gen/version.rb
|
129
|
+
- lib/ev_job_gen/yml_renderer.rb
|
130
|
+
homepage: https://github.com/south37/ev-job-gen
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata: {}
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 2.7.6
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: Generator of kubernetes manifest file for evaluation job.
|
154
|
+
test_files: []
|