pfab 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/.document +5 -0
- data/.ruby-version +1 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +97 -0
- data/LICENSE.txt +20 -0
- data/README.markdown +44 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/bin/pfab +4 -0
- data/lib/pfab.rb +8 -0
- data/lib/pfab/cli.rb +227 -0
- data/lib/pfab/templates/base.rb +55 -0
- data/lib/pfab/templates/job.rb +44 -0
- data/lib/pfab/templates/web.rb +160 -0
- data/lib/pfab/yamls.rb +34 -0
- data/pfab.gemspec +80 -0
- data/test/helper.rb +33 -0
- data/test/test_pfab.rb +7 -0
- metadata +176 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 020566f5a29a27655585829e834c929969ced19c361af2b91119470c0d5706e6
|
4
|
+
data.tar.gz: 9419ea85463bfe69e9cb9cdf70369fcdcbf4ec4e88345205dc419f6ddfdf9362
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ab39f588be10628f48f340372ca1b6d7d8716a8f279a7c81934ded99ecc87a62df550c591b864b9be6f9f0f697933ad6c7ce0a608ae6708b16451066d635afe7
|
7
|
+
data.tar.gz: b82ff0f204ff69030468bab2d70ed293bbedd86f6f23d0d3d665241fbf134d428237e3105d043bae689219556257f1ba598df177f3179192625b579aa8594033
|
data/.document
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.3
|
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem "commander"
|
7
|
+
|
8
|
+
gem "activesupport"
|
9
|
+
gem "pry-byebug"
|
10
|
+
# Add dependencies to develop your gem here.
|
11
|
+
# Include everything needed to run rake, tests, features, etc.
|
12
|
+
group :development do
|
13
|
+
gem "rdoc", "~> 3.12"
|
14
|
+
gem "bundler", "~> 1.0"
|
15
|
+
gem "juwelier", "~> 2.1.0"
|
16
|
+
gem "simplecov", ">= 0"
|
17
|
+
gem "test-unit", ">= 0"
|
18
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (5.2.2)
|
5
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
6
|
+
i18n (>= 0.7, < 2)
|
7
|
+
minitest (~> 5.1)
|
8
|
+
tzinfo (~> 1.1)
|
9
|
+
addressable (2.5.2)
|
10
|
+
public_suffix (>= 2.0.2, < 4.0)
|
11
|
+
builder (3.2.3)
|
12
|
+
byebug (10.0.2)
|
13
|
+
coderay (1.1.2)
|
14
|
+
commander (4.4.6)
|
15
|
+
highline (~> 1.7.2)
|
16
|
+
concurrent-ruby (1.1.4)
|
17
|
+
descendants_tracker (0.0.4)
|
18
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
19
|
+
docile (1.3.1)
|
20
|
+
faraday (0.12.2)
|
21
|
+
multipart-post (>= 1.2, < 3)
|
22
|
+
git (1.3.0)
|
23
|
+
github_api (0.18.2)
|
24
|
+
addressable (~> 2.4)
|
25
|
+
descendants_tracker (~> 0.0.4)
|
26
|
+
faraday (~> 0.8)
|
27
|
+
hashie (~> 3.5, >= 3.5.2)
|
28
|
+
oauth2 (~> 1.0)
|
29
|
+
hashie (3.5.7)
|
30
|
+
highline (1.7.10)
|
31
|
+
i18n (1.2.0)
|
32
|
+
concurrent-ruby (~> 1.0)
|
33
|
+
json (1.8.6)
|
34
|
+
juwelier (2.1.3)
|
35
|
+
builder
|
36
|
+
bundler (>= 1.13)
|
37
|
+
git (>= 1.2.5)
|
38
|
+
github_api
|
39
|
+
highline (>= 1.6.15)
|
40
|
+
nokogiri (>= 1.5.10)
|
41
|
+
rake
|
42
|
+
rdoc
|
43
|
+
semver
|
44
|
+
jwt (1.5.6)
|
45
|
+
method_source (0.9.2)
|
46
|
+
mini_portile2 (2.3.0)
|
47
|
+
minitest (5.11.3)
|
48
|
+
multi_json (1.13.1)
|
49
|
+
multi_xml (0.6.0)
|
50
|
+
multipart-post (2.0.0)
|
51
|
+
nokogiri (1.8.4)
|
52
|
+
mini_portile2 (~> 2.3.0)
|
53
|
+
oauth2 (1.4.0)
|
54
|
+
faraday (>= 0.8, < 0.13)
|
55
|
+
jwt (~> 1.0)
|
56
|
+
multi_json (~> 1.3)
|
57
|
+
multi_xml (~> 0.5)
|
58
|
+
rack (>= 1.2, < 3)
|
59
|
+
power_assert (1.1.3)
|
60
|
+
pry (0.12.2)
|
61
|
+
coderay (~> 1.1.0)
|
62
|
+
method_source (~> 0.9.0)
|
63
|
+
pry-byebug (3.6.0)
|
64
|
+
byebug (~> 10.0)
|
65
|
+
pry (~> 0.10)
|
66
|
+
public_suffix (3.0.2)
|
67
|
+
rack (2.0.5)
|
68
|
+
rake (12.3.1)
|
69
|
+
rdoc (3.12.2)
|
70
|
+
json (~> 1.4)
|
71
|
+
semver (1.0.1)
|
72
|
+
simplecov (0.16.1)
|
73
|
+
docile (~> 1.1)
|
74
|
+
json (>= 1.8, < 3)
|
75
|
+
simplecov-html (~> 0.10.0)
|
76
|
+
simplecov-html (0.10.2)
|
77
|
+
test-unit (3.2.9)
|
78
|
+
power_assert
|
79
|
+
thread_safe (0.3.6)
|
80
|
+
tzinfo (1.2.5)
|
81
|
+
thread_safe (~> 0.1)
|
82
|
+
|
83
|
+
PLATFORMS
|
84
|
+
ruby
|
85
|
+
|
86
|
+
DEPENDENCIES
|
87
|
+
activesupport
|
88
|
+
bundler (~> 1.0)
|
89
|
+
commander
|
90
|
+
juwelier (~> 2.1.0)
|
91
|
+
pry-byebug
|
92
|
+
rdoc (~> 3.12)
|
93
|
+
simplecov
|
94
|
+
test-unit
|
95
|
+
|
96
|
+
BUNDLED WITH
|
97
|
+
1.16.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2018 Jeff Dwyer
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
pfab
|
2
|
+
===================
|
3
|
+
|
4
|
+
nothing to see here
|
5
|
+
|
6
|
+
|
7
|
+
set ~/.pfab.yaml
|
8
|
+
```
|
9
|
+
container.repository: "gcr.io/$$$$$$$"
|
10
|
+
envs:
|
11
|
+
staging:
|
12
|
+
context: "k8s-staging-context"
|
13
|
+
production:
|
14
|
+
context: "k8s-production-context"
|
15
|
+
```
|
16
|
+
|
17
|
+
Then
|
18
|
+
```
|
19
|
+
pfab shipit
|
20
|
+
pfab status
|
21
|
+
```
|
22
|
+
|
23
|
+
Contributing to pfab
|
24
|
+
------------------------------------------
|
25
|
+
|
26
|
+
- Check out the latest master to make sure the feature hasn't been
|
27
|
+
implemented or the bug hasn't been fixed yet.
|
28
|
+
- Check out the issue tracker to make sure someone already hasn't
|
29
|
+
requested it and/or contributed it.
|
30
|
+
- Fork the project.
|
31
|
+
- Start a feature/bugfix branch.
|
32
|
+
- Commit and push until you are happy with your contribution.
|
33
|
+
- Make sure to add tests for it. This is important so I don't break it
|
34
|
+
in a future version unintentionally.
|
35
|
+
- Please try not to mess with the Rakefile, version, or history. If
|
36
|
+
you want to have your own version, or is otherwise necessary, that
|
37
|
+
is fine, but please isolate to its own commit so I can cherry-pick
|
38
|
+
around it.
|
39
|
+
|
40
|
+
Copyright
|
41
|
+
---------
|
42
|
+
|
43
|
+
Copyright (c) 2018 Jeff Dwyer. See
|
44
|
+
LICENSE.txt for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
require 'juwelier'
|
14
|
+
Juwelier::Tasks.new do |gem|
|
15
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
16
|
+
gem.name = "pfab"
|
17
|
+
gem.homepage = "http://github.com/prefab-cloud/pfab"
|
18
|
+
gem.license = "MIT"
|
19
|
+
gem.summary = %Q{helper gem}
|
20
|
+
gem.description = %Q{k8s helper}
|
21
|
+
gem.email = "jdwyer@prefab.cloud"
|
22
|
+
gem.authors = ["Jeff Dwyer"]
|
23
|
+
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Juwelier::RubygemsDotOrgTasks.new
|
27
|
+
require 'rake/testtask'
|
28
|
+
Rake::TestTask.new(:test) do |test|
|
29
|
+
test.libs << 'lib' << 'test'
|
30
|
+
test.pattern = 'test/**/test_*.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Code coverage detail"
|
35
|
+
task :simplecov do
|
36
|
+
ENV['COVERAGE'] = "true"
|
37
|
+
Rake::Task['test'].execute
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :test
|
41
|
+
|
42
|
+
require 'rdoc/task'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "pfab #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/pfab
ADDED
data/lib/pfab.rb
ADDED
data/lib/pfab/cli.rb
ADDED
@@ -0,0 +1,227 @@
|
|
1
|
+
require "commander"
|
2
|
+
require "net/http"
|
3
|
+
require "yaml"
|
4
|
+
require "json"
|
5
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
6
|
+
|
7
|
+
module Pfab
|
8
|
+
class CLI
|
9
|
+
include Commander::Methods
|
10
|
+
|
11
|
+
def run
|
12
|
+
program :name, "pfab"
|
13
|
+
program :version, "0.0.0"
|
14
|
+
program :description, "k8s helper"
|
15
|
+
|
16
|
+
if File.exist? "application.yaml"
|
17
|
+
@application_yaml = YAML.load(File.read("application.yaml")).with_indifferent_access
|
18
|
+
else
|
19
|
+
raise "I need to be run in a directory with a application.yaml"
|
20
|
+
end
|
21
|
+
|
22
|
+
global_option("--verbose") { $verbose = true }
|
23
|
+
$env = :staging
|
24
|
+
global_option("-p") { $env = :production }
|
25
|
+
global_option("-a", "--application_name APP_NAME", "run without prompting for app") do |app_name|
|
26
|
+
$app_name = app_name
|
27
|
+
end
|
28
|
+
|
29
|
+
@apps = apps
|
30
|
+
|
31
|
+
command :build do |c|
|
32
|
+
c.syntax = "pfab build"
|
33
|
+
c.summary = "build image"
|
34
|
+
c.option "--force", "force build and push"
|
35
|
+
c.action do |_args, options|
|
36
|
+
cmd_build(force: options.force)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
command :generate_yaml do |c|
|
41
|
+
c.syntax = "pfab generate_yaml"
|
42
|
+
c.summary = "build k8s yaml"
|
43
|
+
c.action do
|
44
|
+
cmd_generate_yaml
|
45
|
+
end
|
46
|
+
end
|
47
|
+
command :apply do |c|
|
48
|
+
c.syntax = "pfab apply"
|
49
|
+
c.summary = "kubectl apply"
|
50
|
+
c.action do
|
51
|
+
cmd_apply
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
command :shipit do |c|
|
56
|
+
c.syntax = "pfab shipit"
|
57
|
+
c.summary = "build, generate, apply"
|
58
|
+
c.action do
|
59
|
+
cmd_build
|
60
|
+
cmd_generate_yaml
|
61
|
+
cmd_apply
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
command :logs do |c|
|
66
|
+
c.syntax = "pfab logs"
|
67
|
+
c.summary = "tail logs"
|
68
|
+
c.description = "show me my logs`"
|
69
|
+
c.example "tail logs of the first pod in staging",
|
70
|
+
"pfab logs"
|
71
|
+
c.example "tail logs of the first pod in production",
|
72
|
+
"pfab -p logs"
|
73
|
+
c.action do
|
74
|
+
set_kube_context
|
75
|
+
app_name = get_app_name
|
76
|
+
|
77
|
+
first_pod = get_first_pod(app_name)
|
78
|
+
|
79
|
+
puts_and_system("kubectl logs -f #{first_pod}")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
command :status do |c|
|
84
|
+
c.syntax = "pfab status"
|
85
|
+
c.summary = "status of an app"
|
86
|
+
c.description = "what's happening"
|
87
|
+
c.example "what's happening in my app?",
|
88
|
+
"pfab status"
|
89
|
+
c.example "what's happening in production",
|
90
|
+
"pfab status -p status"
|
91
|
+
c.example "pick a single app",
|
92
|
+
"pfab status --pick "
|
93
|
+
c.example "verbose mode",
|
94
|
+
"pfab status --verbose "
|
95
|
+
c.example "watch deploy",
|
96
|
+
"pfab status --watch "
|
97
|
+
c.option "--watch", "Watch"
|
98
|
+
c.action do |_args, options|
|
99
|
+
set_kube_context
|
100
|
+
|
101
|
+
selector = "application=#{@application_yaml['name']}"
|
102
|
+
|
103
|
+
if options.watch
|
104
|
+
puts_and_system "kubectl get pods -l #{selector} -w"
|
105
|
+
elsif $verbose
|
106
|
+
puts_and_system "kubectl describe pods -l #{selector}"
|
107
|
+
else
|
108
|
+
puts_and_system "kubectl get ingresses,jobs,services,cronjobs,deployments,pods --include-uninitialized=true -l #{selector}"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
default_command :help
|
114
|
+
|
115
|
+
run!
|
116
|
+
end
|
117
|
+
|
118
|
+
def cmd_apply
|
119
|
+
set_kube_context
|
120
|
+
app_name = get_app_name
|
121
|
+
puts_and_system("kubectl apply -f .application-k8s-#{$env}-#{app_name}.yaml")
|
122
|
+
end
|
123
|
+
|
124
|
+
def cmd_build(force: false)
|
125
|
+
|
126
|
+
rev = get_current_sha
|
127
|
+
say "This repo is at rev: #{rev}"
|
128
|
+
|
129
|
+
full_image_name = "#{container_repository}/#{image_name}:#{rev}"
|
130
|
+
|
131
|
+
cmd = "docker images -q #{full_image_name}"
|
132
|
+
say "Looking for images with #{cmd}"
|
133
|
+
existing = `#{cmd}`
|
134
|
+
|
135
|
+
if !existing.to_s.empty? && !force
|
136
|
+
say "Found image #{full_image_name} already, skipping build & push"
|
137
|
+
return
|
138
|
+
end
|
139
|
+
|
140
|
+
say "No image #{full_image_name} present, building"
|
141
|
+
|
142
|
+
puts_and_system "docker build -t #{image_name} ."
|
143
|
+
|
144
|
+
puts_and_system "docker tag #{image_name}:latest #{image_name}:#{rev}"
|
145
|
+
puts_and_system "docker tag #{image_name}:#{rev} #{full_image_name}"
|
146
|
+
|
147
|
+
puts_and_system "docker push #{container_repository}/#{image_name}:#{rev}"
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
def cmd_generate_yaml
|
152
|
+
wrote = Pfab::Yamls.generate_for(apps: @apps,
|
153
|
+
application_yaml: @application_yaml,
|
154
|
+
env: $env,
|
155
|
+
sha: get_current_sha,
|
156
|
+
image_name: image_name,
|
157
|
+
container_repository: container_repository
|
158
|
+
)
|
159
|
+
puts "Generated #{wrote}"
|
160
|
+
end
|
161
|
+
|
162
|
+
def get_current_sha
|
163
|
+
`git rev-parse --short --verify HEAD`.chomp
|
164
|
+
end
|
165
|
+
|
166
|
+
def set_kube_context
|
167
|
+
str = "kubectl config use-context #{config["envs"][$env.to_s]["context"]}"
|
168
|
+
puts_and_system str
|
169
|
+
end
|
170
|
+
|
171
|
+
def image_name
|
172
|
+
@application_yaml["name"]
|
173
|
+
end
|
174
|
+
|
175
|
+
def container_repository
|
176
|
+
@_container_repository ||= @config["container.repository"]
|
177
|
+
end
|
178
|
+
|
179
|
+
def config
|
180
|
+
@config ||= YAML.load(File.read(File.join(Dir.home, ".pfab.yaml")))
|
181
|
+
end
|
182
|
+
|
183
|
+
def puts_and_system cmd
|
184
|
+
puts cmd
|
185
|
+
system cmd
|
186
|
+
end
|
187
|
+
|
188
|
+
def apps
|
189
|
+
@_apps ||= calculate_apps
|
190
|
+
end
|
191
|
+
|
192
|
+
def calculate_apps
|
193
|
+
application = @application_yaml["name"]
|
194
|
+
apps = {}
|
195
|
+
@application_yaml["deployables"].each do |deployable, dep|
|
196
|
+
deployable_type = dep["type"]
|
197
|
+
app_name = [application, deployable_type, deployable].join("-")
|
198
|
+
apps[app_name] = {
|
199
|
+
application: application,
|
200
|
+
deployable: deployable,
|
201
|
+
deployable_type: deployable_type,
|
202
|
+
command: dep["command"],
|
203
|
+
}
|
204
|
+
end
|
205
|
+
apps
|
206
|
+
end
|
207
|
+
|
208
|
+
def get_first_pod(app)
|
209
|
+
if get_pods(app)["items"].empty?
|
210
|
+
raise "There are no running pods for #{app}"
|
211
|
+
end
|
212
|
+
get_pods(app)["items"][0]["metadata"]["name"]
|
213
|
+
end
|
214
|
+
|
215
|
+
def get_pods(app)
|
216
|
+
get_pods_str = "kubectl get pods -o json -l deployed-name=#{app}"
|
217
|
+
puts get_pods_str
|
218
|
+
pods_str = `#{get_pods_str}`
|
219
|
+
JSON.parse(pods_str)
|
220
|
+
end
|
221
|
+
|
222
|
+
def get_app_name
|
223
|
+
return $app_name unless $app_name.nil?
|
224
|
+
choose("which app?", *@apps.keys)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Pfab
|
2
|
+
module Templates
|
3
|
+
class Base
|
4
|
+
def initialize(data)
|
5
|
+
@data = data
|
6
|
+
end
|
7
|
+
|
8
|
+
def image_name
|
9
|
+
"#{@data['container_repository']}/#{@data['image_name']}:#{@data['sha']}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def app_vars
|
13
|
+
@data["application_yaml"]["deployables"][@data["props"][:deployable]]
|
14
|
+
end
|
15
|
+
|
16
|
+
def get(key)
|
17
|
+
app_vars[@data["env"]][key] || app_vars[key]
|
18
|
+
end
|
19
|
+
|
20
|
+
def env_vars
|
21
|
+
|
22
|
+
env_vars = [
|
23
|
+
{ name: "DEPLOYED_NAME", value: @data['deployed_name'] }
|
24
|
+
]
|
25
|
+
|
26
|
+
load_env_vars(env_vars, @data["application_yaml"][:environment])
|
27
|
+
load_env_vars(env_vars, @data["application_yaml"][@data["env"]][:environment])
|
28
|
+
|
29
|
+
load_secrets(env_vars, @data["application_yaml"][:env_secrets])
|
30
|
+
load_secrets(env_vars, @data["application_yaml"][@data["env"]][:env_secrets])
|
31
|
+
|
32
|
+
env_vars
|
33
|
+
end
|
34
|
+
|
35
|
+
def load_env_vars(env_vars, hash)
|
36
|
+
(hash || {}).each do |env_var_name, v|
|
37
|
+
env_vars << { name: env_var_name, value: v }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def load_secrets(env_vars, hash)
|
42
|
+
(hash || {}).each do |env_var_name, v|
|
43
|
+
(ref, key) = v.split("/")
|
44
|
+
env_vars << { name: env_var_name,
|
45
|
+
valueFrom: {
|
46
|
+
secretKeyRef: {
|
47
|
+
name: ref,
|
48
|
+
key: key
|
49
|
+
}
|
50
|
+
} }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Pfab
|
2
|
+
module Templates
|
3
|
+
class Job < Base
|
4
|
+
def write_to(f)
|
5
|
+
f << YAML.dump(job.deep_stringify_keys)
|
6
|
+
end
|
7
|
+
|
8
|
+
def job
|
9
|
+
{
|
10
|
+
kind: "Pod",
|
11
|
+
apiVersion: "v1",
|
12
|
+
metadata: {
|
13
|
+
name: "#{@data['deployed_name']}-#{@data['sha']}",
|
14
|
+
namespace: @data['env'],
|
15
|
+
labels: {
|
16
|
+
application: @data['application'],
|
17
|
+
"deployed-name" => @data['deployed_name'],
|
18
|
+
}
|
19
|
+
},
|
20
|
+
spec: {
|
21
|
+
containers: [
|
22
|
+
{
|
23
|
+
image: image_name,
|
24
|
+
name: @data['deployed_name'],
|
25
|
+
command: app_vars["command"].split(" "),
|
26
|
+
env: env_vars,
|
27
|
+
resources: {
|
28
|
+
requests: {
|
29
|
+
cpu: @data["cpu"] || "50m",
|
30
|
+
memory: @data["memory"] || "256Mi",
|
31
|
+
},
|
32
|
+
limits: {
|
33
|
+
cpu: @data["cpu"] || "250m",
|
34
|
+
memory: @data["memory"] || "256Mi",
|
35
|
+
},
|
36
|
+
},
|
37
|
+
}
|
38
|
+
]
|
39
|
+
}
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
module Pfab
|
2
|
+
module Templates
|
3
|
+
class Web < Base
|
4
|
+
def write_to(f)
|
5
|
+
f << YAML.dump(service.deep_stringify_keys)
|
6
|
+
f << YAML.dump(ingress.deep_stringify_keys)
|
7
|
+
f << YAML.dump(deployment.deep_stringify_keys)
|
8
|
+
end
|
9
|
+
|
10
|
+
def service
|
11
|
+
{
|
12
|
+
apiVersion: "v1",
|
13
|
+
kind: "Service",
|
14
|
+
metadata: {
|
15
|
+
name: @data['deployed_name'],
|
16
|
+
namespace: @data['env'],
|
17
|
+
labels: {
|
18
|
+
application: @data['application'],
|
19
|
+
"deployed-name" => @data['deployed_name'],
|
20
|
+
}
|
21
|
+
},
|
22
|
+
spec: {
|
23
|
+
selector: {
|
24
|
+
"deployed-name" => @data['deployed_name'],
|
25
|
+
},
|
26
|
+
ports: [
|
27
|
+
{
|
28
|
+
name: "http",
|
29
|
+
port: 80,
|
30
|
+
targetPort: 3000,
|
31
|
+
}
|
32
|
+
]
|
33
|
+
}
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def ingress
|
38
|
+
{
|
39
|
+
apiVersion: "extensions/v1beta1",
|
40
|
+
kind: "Ingress",
|
41
|
+
metadata: {
|
42
|
+
name: "ingress-#{@data['deployed_name']}",
|
43
|
+
namespace: @data['env'],
|
44
|
+
labels: {
|
45
|
+
application: @data['application'],
|
46
|
+
"deployed-name" => @data['deployed_name'],
|
47
|
+
},
|
48
|
+
annotations: ingress_annotations,
|
49
|
+
},
|
50
|
+
spec: {
|
51
|
+
rules: [
|
52
|
+
{
|
53
|
+
host: get("host"),
|
54
|
+
http: {
|
55
|
+
paths: [
|
56
|
+
{
|
57
|
+
path: "/",
|
58
|
+
backend: {
|
59
|
+
serviceName: @data['deployed_name'],
|
60
|
+
servicePort: "http",
|
61
|
+
},
|
62
|
+
},
|
63
|
+
],
|
64
|
+
},
|
65
|
+
},
|
66
|
+
],
|
67
|
+
},
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
def ingress_annotations
|
72
|
+
{
|
73
|
+
"kubernetes.io/ingress.class" => "traefik",
|
74
|
+
"traefik.frontend.passHostHeader" => "false",
|
75
|
+
"traefik.frontend.priority" => "1",
|
76
|
+
"traefik.frontend.entryPoints" => "https",
|
77
|
+
"traefik.protocol" => "http",
|
78
|
+
"traefik.frontend.headers.SSLRedirect" => "true",
|
79
|
+
"traefik.docker.network" => "traefik",
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
def deployment
|
84
|
+
{
|
85
|
+
kind: "Deployment",
|
86
|
+
apiVersion: "extensions/v1beta1",
|
87
|
+
metadata: {
|
88
|
+
name: @data['deployed_name'],
|
89
|
+
namespace: @data['env'],
|
90
|
+
labels: {
|
91
|
+
application: @data['application'],
|
92
|
+
"deployed-name" => @data['deployed_name'],
|
93
|
+
"application-type" => "web",
|
94
|
+
}
|
95
|
+
},
|
96
|
+
spec: {
|
97
|
+
replicas: get("replicas") || 1,
|
98
|
+
selector: {
|
99
|
+
matchLabels: {
|
100
|
+
"deployed-name" => @data['deployed_name'],
|
101
|
+
},
|
102
|
+
},
|
103
|
+
strategy: {
|
104
|
+
type: "RollingUpdate",
|
105
|
+
rollingUpdate: {
|
106
|
+
maxSurge: 1,
|
107
|
+
maxUnavailable: 0,
|
108
|
+
}
|
109
|
+
},
|
110
|
+
revisionHistoryLimit: 5,
|
111
|
+
progressDeadlineSeconds: 120,
|
112
|
+
template: {
|
113
|
+
metadata: {
|
114
|
+
labels: {
|
115
|
+
application: @data['application'],
|
116
|
+
"deployed-name" => @data['deployed_name'],
|
117
|
+
"application-type" => "web",
|
118
|
+
},
|
119
|
+
},
|
120
|
+
spec: {
|
121
|
+
containers: [
|
122
|
+
{
|
123
|
+
image: image_name,
|
124
|
+
name: @data['deployed_name'],
|
125
|
+
command: get("command").split(" "),
|
126
|
+
env: env_vars,
|
127
|
+
resources: {
|
128
|
+
requests: {
|
129
|
+
cpu: @data["cpu"] || "50m",
|
130
|
+
memory: @data["memory"] || "256Mi",
|
131
|
+
},
|
132
|
+
limits: {
|
133
|
+
cpu: @data["cpu"] || "250m",
|
134
|
+
memory: @data["memory"] || "256Mi",
|
135
|
+
},
|
136
|
+
},
|
137
|
+
livenessProbe: {
|
138
|
+
httpGet: {
|
139
|
+
path: get("health_check_path") || "/",
|
140
|
+
port: get("port"),
|
141
|
+
},
|
142
|
+
initialDelaySeconds: 5,
|
143
|
+
},
|
144
|
+
readinessProbe: {
|
145
|
+
httpGet: {
|
146
|
+
path: get("health_check_path") || "/",
|
147
|
+
port: get("port"),
|
148
|
+
},
|
149
|
+
initialDelaySeconds: 5,
|
150
|
+
},
|
151
|
+
}
|
152
|
+
]
|
153
|
+
},
|
154
|
+
},
|
155
|
+
},
|
156
|
+
}
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
data/lib/pfab/yamls.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'pry'
|
2
|
+
module Pfab
|
3
|
+
class Yamls
|
4
|
+
def self.generate_for(apps:, application_yaml:, image_name:, env:, sha:, container_repository:)
|
5
|
+
|
6
|
+
apps.each do |app, props|
|
7
|
+
puts app
|
8
|
+
|
9
|
+
data = {
|
10
|
+
"env" => env.to_s,
|
11
|
+
'image_name' => image_name,
|
12
|
+
'sha' => sha,
|
13
|
+
'container_repository' => container_repository,
|
14
|
+
'props' => props,
|
15
|
+
'deployed_name' => app,
|
16
|
+
'application' => application_yaml["name"],
|
17
|
+
'application_yaml' => application_yaml
|
18
|
+
}
|
19
|
+
|
20
|
+
File.open(".application-k8s-#{env}-#{app}.yaml", "w") do |f|
|
21
|
+
case props[:deployable_type]
|
22
|
+
when "web" then
|
23
|
+
processed = Pfab::Templates::Web.new(data).write_to(f)
|
24
|
+
when "job" then
|
25
|
+
processed = Pfab::Templates::Job.new(data).write_to(f)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
data/pfab.gemspec
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Generated by juwelier
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: pfab 0.1.0 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "pfab".freeze
|
9
|
+
s.version = "0.1.0"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib".freeze]
|
13
|
+
s.authors = ["Jeff Dwyer".freeze]
|
14
|
+
s.date = "2018-12-29"
|
15
|
+
s.description = "k8s helper".freeze
|
16
|
+
s.email = "jdwyer@prefab.cloud".freeze
|
17
|
+
s.executables = ["pfab".freeze]
|
18
|
+
s.extra_rdoc_files = [
|
19
|
+
"LICENSE.txt",
|
20
|
+
"README.markdown"
|
21
|
+
]
|
22
|
+
s.files = [
|
23
|
+
".document",
|
24
|
+
".ruby-version",
|
25
|
+
"Gemfile",
|
26
|
+
"Gemfile.lock",
|
27
|
+
"LICENSE.txt",
|
28
|
+
"README.markdown",
|
29
|
+
"Rakefile",
|
30
|
+
"VERSION",
|
31
|
+
"bin/pfab",
|
32
|
+
"lib/pfab.rb",
|
33
|
+
"lib/pfab/cli.rb",
|
34
|
+
"lib/pfab/templates/base.rb",
|
35
|
+
"lib/pfab/templates/job.rb",
|
36
|
+
"lib/pfab/templates/web.rb",
|
37
|
+
"lib/pfab/yamls.rb",
|
38
|
+
"pfab.gemspec",
|
39
|
+
"test/helper.rb",
|
40
|
+
"test/test_pfab.rb"
|
41
|
+
]
|
42
|
+
s.homepage = "http://github.com/prefab-cloud/pfab".freeze
|
43
|
+
s.licenses = ["MIT".freeze]
|
44
|
+
s.rubygems_version = "2.7.8".freeze
|
45
|
+
s.summary = "helper gem".freeze
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
s.specification_version = 4
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_runtime_dependency(%q<commander>.freeze, [">= 0"])
|
52
|
+
s.add_runtime_dependency(%q<activesupport>.freeze, [">= 0"])
|
53
|
+
s.add_runtime_dependency(%q<pry-byebug>.freeze, [">= 0"])
|
54
|
+
s.add_development_dependency(%q<rdoc>.freeze, ["~> 3.12"])
|
55
|
+
s.add_development_dependency(%q<bundler>.freeze, ["~> 1.0"])
|
56
|
+
s.add_development_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
|
57
|
+
s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<test-unit>.freeze, [">= 0"])
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<commander>.freeze, [">= 0"])
|
61
|
+
s.add_dependency(%q<activesupport>.freeze, [">= 0"])
|
62
|
+
s.add_dependency(%q<pry-byebug>.freeze, [">= 0"])
|
63
|
+
s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
|
64
|
+
s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
|
65
|
+
s.add_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
|
66
|
+
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
|
67
|
+
s.add_dependency(%q<test-unit>.freeze, [">= 0"])
|
68
|
+
end
|
69
|
+
else
|
70
|
+
s.add_dependency(%q<commander>.freeze, [">= 0"])
|
71
|
+
s.add_dependency(%q<activesupport>.freeze, [">= 0"])
|
72
|
+
s.add_dependency(%q<pry-byebug>.freeze, [">= 0"])
|
73
|
+
s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
|
74
|
+
s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
|
75
|
+
s.add_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
|
76
|
+
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
|
77
|
+
s.add_dependency(%q<test-unit>.freeze, [">= 0"])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
module SimpleCov::Configuration
|
4
|
+
def clean_filters
|
5
|
+
@filters = []
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
SimpleCov.configure do
|
10
|
+
clean_filters
|
11
|
+
load_adapter 'test_frameworks'
|
12
|
+
end
|
13
|
+
|
14
|
+
ENV["COVERAGE"] && SimpleCov.start do
|
15
|
+
add_filter "/.rvm/"
|
16
|
+
end
|
17
|
+
require 'rubygems'
|
18
|
+
require 'bundler'
|
19
|
+
begin
|
20
|
+
Bundler.setup(:default, :development)
|
21
|
+
rescue Bundler::BundlerError => e
|
22
|
+
$stderr.puts e.message
|
23
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
24
|
+
exit e.status_code
|
25
|
+
end
|
26
|
+
require 'test/unit'
|
27
|
+
|
28
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
29
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
30
|
+
require 'pfab'
|
31
|
+
|
32
|
+
class Test::Unit::TestCase
|
33
|
+
end
|
data/test/test_pfab.rb
ADDED
metadata
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pfab
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeff Dwyer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-12-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: commander
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry-byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rdoc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.12'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.12'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: juwelier
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.1.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.1.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: test-unit
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: k8s helper
|
126
|
+
email: jdwyer@prefab.cloud
|
127
|
+
executables:
|
128
|
+
- pfab
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files:
|
131
|
+
- LICENSE.txt
|
132
|
+
- README.markdown
|
133
|
+
files:
|
134
|
+
- ".document"
|
135
|
+
- ".ruby-version"
|
136
|
+
- Gemfile
|
137
|
+
- Gemfile.lock
|
138
|
+
- LICENSE.txt
|
139
|
+
- README.markdown
|
140
|
+
- Rakefile
|
141
|
+
- VERSION
|
142
|
+
- bin/pfab
|
143
|
+
- lib/pfab.rb
|
144
|
+
- lib/pfab/cli.rb
|
145
|
+
- lib/pfab/templates/base.rb
|
146
|
+
- lib/pfab/templates/job.rb
|
147
|
+
- lib/pfab/templates/web.rb
|
148
|
+
- lib/pfab/yamls.rb
|
149
|
+
- pfab.gemspec
|
150
|
+
- test/helper.rb
|
151
|
+
- test/test_pfab.rb
|
152
|
+
homepage: http://github.com/prefab-cloud/pfab
|
153
|
+
licenses:
|
154
|
+
- MIT
|
155
|
+
metadata: {}
|
156
|
+
post_install_message:
|
157
|
+
rdoc_options: []
|
158
|
+
require_paths:
|
159
|
+
- lib
|
160
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
requirements: []
|
171
|
+
rubyforge_project:
|
172
|
+
rubygems_version: 2.7.8
|
173
|
+
signing_key:
|
174
|
+
specification_version: 4
|
175
|
+
summary: helper gem
|
176
|
+
test_files: []
|