pfab 0.5.0 → 0.6.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: b9979c3fb7ac0f07322332db1eb53e54b510b3f28adca771c7a2a51f27696c14
4
- data.tar.gz: e468d799e0c4547835dcfe7b261515f890728c5f1b00f2023522bd5871a5bd38
3
+ metadata.gz: d731b1aced5361202684f5f3f782ff6846816818499c0d8ce4892cbcb728661d
4
+ data.tar.gz: 147ae1a483a6a980b138070ffe858ddea9b0bcca8bd86fc311c63d7693bc39a3
5
5
  SHA512:
6
- metadata.gz: afb107189bd11eaac4f8c11cf127c21b163e3c97bb397692375b4bcfee69071b6b476312a49309c079bfd2fee1dda69fe061a8d835b6e23526f31d732022506f
7
- data.tar.gz: fadaf09dd358eeb636b6e1ba12cca060933b98f7c32b3a8ab697b7f62ae1c27382a2454a21881bb51882205bdc958710f2dd2593bd3604a7debfdfe0dde84207
6
+ metadata.gz: c520165411f2fe9023385c896677032c3decd4552209b9e5fab5af6c852b82bac357bb3fe07bd34bb9a02c05990de193b2101e45f2379b7c32dcd3d7dfa8953c
7
+ data.tar.gz: f963ee37ca9fcaac8f57b6be715b6d06fbe4ebed20ce06ba6fc768d338cf8f231c7f39f13ddbfc242345f169171aa94786e7eec1b42ac038019e96cf313c1e23
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.6.0
data/lib/pfab.rb CHANGED
@@ -4,6 +4,7 @@ require "pfab/templates/base"
4
4
  require "pfab/templates/job"
5
5
  require "pfab/templates/daemon"
6
6
  require "pfab/templates/web"
7
+ require "pfab/templates/cron"
7
8
 
8
9
  module Pfab
9
10
  end
data/lib/pfab/cli.rb CHANGED
@@ -18,8 +18,9 @@ module Pfab
18
18
  else
19
19
  raise "I need to be run in a directory with a application.yaml"
20
20
  end
21
-
22
21
  global_option("--verbose") { $verbose = true }
22
+ $dryrun = false
23
+ global_option("--dryrun") { $dryrun = true }
23
24
  $env = :staging
24
25
  global_option("-p") { $env = :production }
25
26
  global_option("-a", "--application_name APP_NAME", "run without prompting for app") do |app_name|
@@ -56,6 +57,8 @@ module Pfab
56
57
  c.syntax = "pfab shipit"
57
58
  c.summary = "build, generate, apply"
58
59
  c.action do
60
+ app_name = get_app_name(all: true)
61
+ puts "Shipping #{app_name}"
59
62
  success = cmd_build
60
63
  if success
61
64
  cmd_generate_yaml
@@ -82,6 +85,24 @@ module Pfab
82
85
  end
83
86
  end
84
87
 
88
+ command :exec do |c|
89
+ c.syntax = "pfab exec"
90
+ c.summary = "kubectl exec into a pod"
91
+ c.description = "CLI to the Cloud"
92
+ c.example "exec into the first pod in staging",
93
+ "pfab exec"
94
+ c.example "exec into the first pod in production",
95
+ "ezp -p exec"
96
+ c.action do
97
+ set_kube_context
98
+ app_name = get_app_name
99
+
100
+ first_pod = get_first_pod app_name
101
+
102
+ puts_and_system "kubectl exec -it #{first_pod} -- /bin/bash"
103
+ end
104
+ end
105
+
85
106
  command :status do |c|
86
107
  c.syntax = "pfab status"
87
108
  c.summary = "status of an app"
@@ -119,9 +140,10 @@ module Pfab
119
140
 
120
141
  def cmd_apply
121
142
  set_kube_context
122
- app_name = get_app_name
123
- puts_and_system("kubectl apply -f .application-k8s-#{$env}-#{app_name}.yaml")
124
- puts_and_system("git tag release-#{$env}-#{app_name}-#{Time.now.strftime("%Y-%m-%d")} HEAD")
143
+ get_apps.each do |app_name|
144
+ puts_and_system("kubectl apply -f .application-k8s-#{$env}-#{app_name}.yaml")
145
+ puts_and_system("git tag release-#{$env}-#{app_name}-#{Time.now.strftime("%Y-%m-%d-%H-%M-%S")} HEAD")
146
+ end
125
147
  end
126
148
 
127
149
  def cmd_build(force: false)
@@ -151,7 +173,7 @@ module Pfab
151
173
 
152
174
  say "No image #{full_image_name} present, building"
153
175
 
154
- prebuild = @application_yaml["prebuild"]
176
+ prebuild = @application_yaml["prebuild"] || ""
155
177
  if prebuild.empty?
156
178
  say "No prebuild task"
157
179
  else
@@ -208,7 +230,11 @@ module Pfab
208
230
 
209
231
  def puts_and_system cmd
210
232
  puts cmd
211
- system cmd
233
+ if $dryrun
234
+ puts "dry run, didn't run that"
235
+ else
236
+ system cmd
237
+ end
212
238
  end
213
239
 
214
240
  def apps
@@ -245,9 +271,16 @@ module Pfab
245
271
  JSON.parse(pods_str)
246
272
  end
247
273
 
248
- def get_app_name
274
+ def get_app_name(all: false)
249
275
  return $app_name unless $app_name.nil?
250
- choose("which app?", *@apps.keys)
276
+ apps = @apps.keys
277
+ apps << "all" if all
278
+ $app_name = choose("which app?", *apps)
279
+ end
280
+
281
+ def get_apps
282
+ name = get_app_name(all: true)
283
+ (name == "all") ? @apps.keys : [name]
251
284
  end
252
285
  end
253
286
  end
@@ -47,13 +47,8 @@ module Pfab
47
47
 
48
48
  env_vars = [
49
49
  { name: "DEPLOYED_NAME", value: @data['deployed_name'] },
50
- { name: "DOGSTATSD_HOST_IP",
51
- valueFrom: {
52
- fieldRef: { fieldPath: "status.hostIP" }
53
- }
54
- },
55
50
  ]
56
-
51
+
57
52
  load_env_vars(env_vars, @data["application_yaml"][:environment])
58
53
  load_env_vars(env_vars, @data["application_yaml"][@data["env"]][:environment])
59
54
 
@@ -65,7 +60,15 @@ module Pfab
65
60
 
66
61
  def load_env_vars(env_vars, hash)
67
62
  (hash || {}).each do |env_var_name, v|
68
- env_vars << { name: env_var_name, value: v }
63
+ if v.start_with? "field/"
64
+ (_, field_name) = v.split("/")
65
+ env_vars << { name: env_var_name, valueFrom: {
66
+ fieldRef: { fieldPath: field_name }
67
+ } }
68
+ else
69
+ env_vars << { name: env_var_name, value: v }
70
+ end
71
+
69
72
  end
70
73
  end
71
74
 
@@ -0,0 +1,64 @@
1
+ module Pfab
2
+ module Templates
3
+ class Cron < Base
4
+ def write_to(f)
5
+ f << YAML.dump(job.deep_stringify_keys)
6
+ end
7
+
8
+ def job
9
+ {
10
+ apiVersion: "batch/v1beta1",
11
+ kind: "CronJob",
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
+ "application-type" => "job",
19
+ }
20
+ },
21
+ spec: {
22
+ schedule: get("schedule"),
23
+ jobTemplate: {
24
+ metadata: {
25
+ name: "#{@data['deployed_name']}-#{@data['sha']}",
26
+ namespace: @data['env'],
27
+ labels: {
28
+ application: @data['application'],
29
+ "deployed-name" => @data['deployed_name'],
30
+ "application-type" => "cron",
31
+ },
32
+ },
33
+ spec: {
34
+ template: {
35
+ metadata: {
36
+ labels: {
37
+ application: @data['application'],
38
+ "deployed-name" => @data['deployed_name'],
39
+ "application-type" => "cron",
40
+ },
41
+ },
42
+ spec: {
43
+
44
+ containers: [
45
+ {
46
+ image: image_name,
47
+ name: @data['deployed_name'],
48
+ command: app_vars["command"].split(" "),
49
+ env: env_vars,
50
+ resources: resources,
51
+ },
52
+ ],
53
+ restartPolicy: "Never",
54
+ },
55
+ },
56
+ backoffLimit: 2,
57
+ },
58
+ },
59
+ },
60
+ }
61
+ end
62
+ end
63
+ end
64
+ end
@@ -88,7 +88,7 @@ module Pfab
88
88
  path: get("health_check_path") || "/",
89
89
  port: get("port"),
90
90
  },
91
- initialDelaySeconds: 5,
91
+ initialDelaySeconds: 15,
92
92
  }
93
93
  end
94
94
 
data/lib/pfab/yamls.rb CHANGED
@@ -27,6 +27,8 @@ module Pfab
27
27
  processed = Pfab::Templates::Job.new(data).write_to(f)
28
28
  when "daemon" then
29
29
  processed = Pfab::Templates::Daemon.new(data).write_to(f)
30
+ when "cron" then
31
+ processed = Pfab::Templates::Cron.new(data).write_to(f)
30
32
  end
31
33
  end
32
34
  filename
data/pfab.gemspec CHANGED
@@ -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.5.0 ruby lib
5
+ # stub: pfab 0.6.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "pfab".freeze
9
- s.version = "0.5.0"
9
+ s.version = "0.6.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 = "2019-01-03"
14
+ s.date = "2019-01-08"
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/cron.rb",
35
36
  "lib/pfab/templates/daemon.rb",
36
37
  "lib/pfab/templates/job.rb",
37
38
  "lib/pfab/templates/web.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.5.0
4
+ version: 0.6.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: 2019-01-03 00:00:00.000000000 Z
11
+ date: 2019-01-08 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/cron.rb
146
147
  - lib/pfab/templates/daemon.rb
147
148
  - lib/pfab/templates/job.rb
148
149
  - lib/pfab/templates/web.rb