pfab 0.2.0 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1db6c13d2a16691762f10d9a2fc0c835d9d0283019cd04ebba830c02e08f4c09
4
- data.tar.gz: eaeec7721e636ddd56aff43dcdcb63c551265a949e8752cfbe65f8900a6fa314
3
+ metadata.gz: 36192c1d9882ed963296259ea22a27a4ffe2a91383cf655aa1392e301034513e
4
+ data.tar.gz: 7c5a42aea011a6a4e0ce8b18c50a01a7b309921c7186ee47449c336fe077a99e
5
5
  SHA512:
6
- metadata.gz: 74223dfa577bdfd69b2ae01e3b5319b60a2f0305f080a23ae112f2eb3a63315b5249174834c8b519549cd9a8806dc06bc5ae947548e7c6d9046eebc5cb092bae
7
- data.tar.gz: 827157bcaf656877fa2788704bc55e0a057baaf762831af1ec6bf9b61e396d6ca4ce815b7bb271784eec8e94cc462ec8ab6c1f0f005ef252e3c86d49dc098575
6
+ metadata.gz: 878bcbc12941d77f2d7cad35a2568afc194171c33239c6b3565abf2c506754a896fcffc3043e78a90cf3e4cfadf000ee22138ddb88c0069db81e1d5ea30152eb
7
+ data.tar.gz: 6d7465ce4a0b3854cd814ad1069e834a1487d5399d6d2b0a6cae50747c27a24fe0904cae581240863ee9c981bb63ff98e2397557fa0a175d29ef0707f95f790a
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -2,6 +2,7 @@ require "pfab/cli"
2
2
  require "pfab/yamls"
3
3
  require "pfab/templates/base"
4
4
  require "pfab/templates/job"
5
+ require "pfab/templates/daemon"
5
6
  require "pfab/templates/web"
6
7
 
7
8
  module Pfab
@@ -122,9 +122,27 @@ module Pfab
122
122
  end
123
123
 
124
124
  def cmd_build(force: false)
125
-
126
125
  rev = get_current_sha
127
126
  say "This repo is at rev: #{rev}"
127
+ uncommitted_changes = `git diff-index HEAD --`.empty?
128
+ if uncommitted_changes
129
+ say "FYI! There are uncommitted changes."
130
+ say "carrying on and pushing local code to #{rev}"
131
+ end
132
+
133
+ prebuild = @application_yaml["prebuild"]
134
+ if prebuild.empty?
135
+ say "No prebuild task"
136
+ else
137
+ say "Prebuild, running system(#{prebuild})"
138
+ result = system(prebuild)
139
+ if result
140
+ notify_ok 'Pfab prebuild success'
141
+ else
142
+ say "Pfab prebuild did not return success. Exiting"
143
+ return false
144
+ end
145
+ end
128
146
 
129
147
  full_image_name = "#{container_repository}/#{image_name}:#{rev}"
130
148
 
@@ -154,7 +172,7 @@ module Pfab
154
172
  env: $env,
155
173
  sha: get_current_sha,
156
174
  image_name: image_name,
157
- container_repository: container_repository
175
+ config: config
158
176
  )
159
177
  puts "Generated #{wrote}"
160
178
  end
@@ -14,7 +14,33 @@ module Pfab
14
14
  end
15
15
 
16
16
  def get(key)
17
- app_vars[@data["env"]][key] || app_vars[key]
17
+ app_vars.dig(@data["env"], key) || app_vars[key]
18
+ end
19
+
20
+
21
+ def cpu(req_type)
22
+ default_cpu_string = @data["config"]["default_cpu_string"] || "50m/250m"
23
+ (request, limit) = (get("cpu") || default_cpu_string).split("/")
24
+ req_type == :limit ? limit : request
25
+ end
26
+
27
+ def memory(req_type)
28
+ default_memory_string = @data["config"]["default_memory_string"] || "256Mi/500Mi"
29
+ (request, limit) = (get("memory") || default_memory_string).split("/")
30
+ req_type == :limit ? limit : request
31
+ end
32
+
33
+ def resources
34
+ {
35
+ requests: {
36
+ cpu: cpu(:request),
37
+ memory: memory(:request),
38
+ },
39
+ limits: {
40
+ cpu: cpu(:limit),
41
+ memory: memory(:limit),
42
+ }
43
+ }
18
44
  end
19
45
 
20
46
  def env_vars
@@ -0,0 +1,57 @@
1
+ module Pfab
2
+ module Templates
3
+ class Daemon < Base
4
+ def write_to(f)
5
+ f << YAML.dump(deployment.deep_stringify_keys)
6
+ end
7
+
8
+ def deployment
9
+ {
10
+ kind: "Deployment",
11
+ apiVersion: "extensions/v1beta1",
12
+ metadata: {
13
+ name: @data['deployed_name'],
14
+ namespace: @data['env'],
15
+ labels: {
16
+ application: @data['application'],
17
+ "deployed-name" => @data['deployed_name'],
18
+ "application-type" => "daemon",
19
+ }
20
+ },
21
+ spec: {
22
+ replicas: get("replicas") || 1,
23
+ selector: {
24
+ matchLabels: {
25
+ "deployed-name" => @data['deployed_name'],
26
+ },
27
+ },
28
+ strategy: {
29
+ type: "Recreate"
30
+ },
31
+ revisionHistoryLimit: 5,
32
+ template: {
33
+ metadata: {
34
+ labels: {
35
+ application: @data['application'],
36
+ "deployed-name" => @data['deployed_name'],
37
+ "application-type" => "daemon",
38
+ },
39
+ },
40
+ spec: {
41
+ containers: [
42
+ {
43
+ image: image_name,
44
+ name: @data['deployed_name'],
45
+ command: get("command").split(" "),
46
+ env: env_vars,
47
+ resources: resources,
48
+ }
49
+ ]
50
+ },
51
+ },
52
+ },
53
+ }
54
+ end
55
+ end
56
+ end
57
+ end
@@ -36,16 +36,7 @@ module Pfab
36
36
  name: @data['deployed_name'],
37
37
  command: app_vars["command"].split(" "),
38
38
  env: env_vars,
39
- resources: {
40
- requests: {
41
- cpu: @data["cpu"] || "50m",
42
- memory: @data["memory"] || "256Mi",
43
- },
44
- limits: {
45
- cpu: @data["cpu"] || "250m",
46
- memory: @data["memory"] || "256Mi",
47
- },
48
- },
39
+ resources: resources,
49
40
  },
50
41
  ],
51
42
  restartPolicy: "Never",
@@ -57,7 +57,7 @@ module Pfab
57
57
  path: "/",
58
58
  backend: {
59
59
  serviceName: @data['deployed_name'],
60
- servicePort: "http",
60
+ servicePort: get("service_port") || "http",
61
61
  },
62
62
  },
63
63
  ],
@@ -124,16 +124,7 @@ module Pfab
124
124
  name: @data['deployed_name'],
125
125
  command: get("command").split(" "),
126
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
- },
127
+ resources: resources,
137
128
  livenessProbe: {
138
129
  httpGet: {
139
130
  path: get("health_check_path") || "/",
@@ -1,7 +1,7 @@
1
1
  require 'pry'
2
2
  module Pfab
3
3
  class Yamls
4
- def self.generate_for(apps:, application_yaml:, image_name:, env:, sha:, container_repository:)
4
+ def self.generate_for(apps:, application_yaml:, image_name:, env:, sha:, config:)
5
5
 
6
6
  apps.each do |app, props|
7
7
  puts app
@@ -10,7 +10,8 @@ module Pfab
10
10
  "env" => env.to_s,
11
11
  'image_name' => image_name,
12
12
  'sha' => sha,
13
- 'container_repository' => container_repository,
13
+ 'container_repository' => config["container.repository"],
14
+ 'config' => config,
14
15
  'props' => props,
15
16
  'deployed_name' => app,
16
17
  'application' => application_yaml["name"],
@@ -23,6 +24,8 @@ module Pfab
23
24
  processed = Pfab::Templates::Web.new(data).write_to(f)
24
25
  when "job" then
25
26
  processed = Pfab::Templates::Job.new(data).write_to(f)
27
+ when "daemon" then
28
+ processed = Pfab::Templates::Daemon.new(data).write_to(f)
26
29
  end
27
30
  end
28
31
  end
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: pfab 0.2.0 ruby lib
5
+ # stub: pfab 0.3.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "pfab".freeze
9
- s.version = "0.2.0"
9
+ s.version = "0.3.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Jeff Dwyer".freeze]
14
- s.date = "2018-12-29"
14
+ s.date = "2018-12-31"
15
15
  s.description = "k8s helper".freeze
16
16
  s.email = "jdwyer@prefab.cloud".freeze
17
17
  s.executables = ["pfab".freeze]
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
32
32
  "lib/pfab.rb",
33
33
  "lib/pfab/cli.rb",
34
34
  "lib/pfab/templates/base.rb",
35
+ "lib/pfab/templates/daemon.rb",
35
36
  "lib/pfab/templates/job.rb",
36
37
  "lib/pfab/templates/web.rb",
37
38
  "lib/pfab/yamls.rb",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pfab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Dwyer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-29 00:00:00.000000000 Z
11
+ date: 2018-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -143,6 +143,7 @@ files:
143
143
  - lib/pfab.rb
144
144
  - lib/pfab/cli.rb
145
145
  - lib/pfab/templates/base.rb
146
+ - lib/pfab/templates/daemon.rb
146
147
  - lib/pfab/templates/job.rb
147
148
  - lib/pfab/templates/web.rb
148
149
  - lib/pfab/yamls.rb