seira 0.7.3 → 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +24 -0
- data/README.md +11 -2
- data/lib/helpers.rb +9 -0
- data/lib/seira/db.rb +7 -10
- data/lib/seira/jobs.rb +21 -6
- data/lib/seira/pods.rb +0 -2
- data/lib/seira/random.rb +0 -3
- data/lib/seira/version.rb +1 -1
- metadata +6 -6
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06e2e516ae84d1bcdc4f3320eeb13c83dc6cd162bfbe5e249b53e2b3af74885c
|
4
|
+
data.tar.gz: 027a214ded3ab47b25fe29b9e8943bd268fe908ff9aa87993ffa07e9c395e350
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6cc9ea8137d0ae4578a5fbdbeac88f8e8d01916dd8e64f8dc83d4ac30517fda718ae06d0d02b5c354e9d80e3ee3ab3f75df433dda45ac85b60e512cc878b058
|
7
|
+
data.tar.gz: 828524836a6abc488bc29a3333733887e57b39351f9d54b8ecb9986c49520abd6e8564b97425f702fed90b2256f68c558303c76ee6be49fc58362a3898fc4f32
|
@@ -0,0 +1,24 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: push
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
|
8
|
+
runs-on: ubuntu-20.04
|
9
|
+
|
10
|
+
strategy:
|
11
|
+
matrix:
|
12
|
+
ruby-version: ['2.6.3', '2.7.2']
|
13
|
+
|
14
|
+
steps:
|
15
|
+
# Pin to this commit: v2
|
16
|
+
- uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
|
17
|
+
- name: Set up Ruby
|
18
|
+
# Pin to this commit, v1.82.0
|
19
|
+
uses: ruby/setup-ruby@5e4f0a10bfc39c97cd5358121291e27e5d97e09b
|
20
|
+
with:
|
21
|
+
ruby-version: ${{ matrix.ruby-version }}
|
22
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
23
|
+
- name: Run tests
|
24
|
+
run: bundle exec rake
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Seira
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/seira.svg)](https://badge.fury.io/rb/seira)
|
4
|
-
[![Build Status](https://
|
4
|
+
[![Build Status](https://github.com/joinhandshake/seira/actions/workflows/ruby.yml/badge.svg)](https://github.com/joinhandshake/seira/actions)
|
5
5
|
|
6
6
|
An opinionated library for building applications on Kubernetes.
|
7
7
|
|
@@ -83,6 +83,15 @@ seira:
|
|
83
83
|
|
84
84
|
This specification is read in and used to determine what `gcloud` context to use and what `kubectl` cluster to use when operating commands. For example, `seira internal` will connect to `org-internal` gcloud configuration and `gke_org-internal_us-central1-a_internal` kubectl cluster. For shorthand, `seira i` shorthand is specified as an alias.
|
85
85
|
|
86
|
+
### Application Configuration Files
|
87
|
+
|
88
|
+
Each app can also define configuration files. These files specify details that allow seira to execute commands with minimal user input, and declare aspects of the application. This file lives in the app folder with the name `.seira.app.yaml`. An example configuration file:
|
89
|
+
|
90
|
+
```
|
91
|
+
# The name of the sql instance as it shows in GCP Cloud SQL UI
|
92
|
+
primary_sql_instance: app-database-name
|
93
|
+
```
|
94
|
+
|
86
95
|
### Regions and Zones
|
87
96
|
|
88
97
|
All clusters should have a `region` option specified. For zonal clusters (clusters that are NOT regional) should also specify their `zone`.
|
@@ -156,7 +165,7 @@ Pods can be listed and also exec'd into.
|
|
156
165
|
|
157
166
|
`seira staging app-name pods list`
|
158
167
|
|
159
|
-
`seira staging app-name pods
|
168
|
+
`seira staging app-name pods connect --pod=<POD-NAME>`
|
160
169
|
|
161
170
|
## Development
|
162
171
|
|
data/lib/helpers.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
1
3
|
module Seira
|
2
4
|
class Helpers
|
3
5
|
include Seira::Commands
|
@@ -37,6 +39,13 @@ module Seira
|
|
37
39
|
Secrets.new(app: context[:app], action: 'get', args: [], context: context).get(key)
|
38
40
|
end
|
39
41
|
|
42
|
+
def get_seira_app_config(context:)
|
43
|
+
yaml_file_path = "kubernetes/#{context[:cluster]}/#{context[:app]}/.seira.app.yaml"
|
44
|
+
YAML.load_file(yaml_file_path)
|
45
|
+
rescue
|
46
|
+
fail "Failed to load the configuration file at #{yaml_file_path}. Please add configuration file and retry."
|
47
|
+
end
|
48
|
+
|
40
49
|
def get_current_replicas(deployment:, context:)
|
41
50
|
output = Seira::Commands.kubectl("get deployment #{deployment} -o json", context: context, return_output: true)
|
42
51
|
JSON.parse(output)['spec']['replicas']
|
data/lib/seira/db.rb
CHANGED
@@ -75,16 +75,8 @@ module Seira
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
-
# NOTE: Relies on the pgbouncer instance being named based on the db name, as is done in create command
|
79
78
|
def primary_instance
|
80
|
-
|
81
|
-
return nil unless database_url
|
82
|
-
|
83
|
-
primary_uri = URI.parse(database_url)
|
84
|
-
host = primary_uri.host
|
85
|
-
|
86
|
-
# Convert handshake-onyx-burmese-pgbouncer-service to handshake-onyx-burmese
|
87
|
-
host.gsub('-pgbouncer-service', '')
|
79
|
+
Seira::Helpers.get_seira_app_config(context: context)['primary_sql_instance']
|
88
80
|
end
|
89
81
|
|
90
82
|
private
|
@@ -331,10 +323,13 @@ module Seira
|
|
331
323
|
|
332
324
|
def run_psql
|
333
325
|
as_admin = false
|
326
|
+
instance_name = nil
|
334
327
|
|
335
328
|
args.each do |arg|
|
336
329
|
if arg == '--as-root-user'
|
337
330
|
as_admin = true
|
331
|
+
elsif arg.start_with? '--instance='
|
332
|
+
instance_name = arg.split('=')[1]
|
338
333
|
else
|
339
334
|
puts "Warning: Unrecognized argument '#{arg}'"
|
340
335
|
end
|
@@ -344,7 +339,7 @@ module Seira
|
|
344
339
|
puts "!! Warning !!! You are running as root PSQL user `postgres`. This super user account has full admin priveleges. Use with extreme care."
|
345
340
|
end
|
346
341
|
|
347
|
-
execute_db_command(nil, interactive: true, as_admin: as_admin)
|
342
|
+
execute_db_command(nil, interactive: true, instance_name: instance_name, as_admin: as_admin)
|
348
343
|
end
|
349
344
|
|
350
345
|
def run_table_sizes
|
@@ -488,6 +483,8 @@ module Seira
|
|
488
483
|
# TODO(josh): move pgbouncer naming logic here and in Create to a common location
|
489
484
|
instance_name ||= primary_instance
|
490
485
|
private_ip = Helpers.sql_ips(instance_name, context: context)[:private]
|
486
|
+
|
487
|
+
# NOTE: Relies on the pgbouncer instance being named based on the db name, as is done in create command
|
491
488
|
pgbouncer_tier ||= instance_name.gsub("#{app}-", '')
|
492
489
|
matching_pods = Helpers.fetch_pods(context: context, filters: { tier: pgbouncer_tier })
|
493
490
|
if matching_pods.empty?
|
data/lib/seira/jobs.rb
CHANGED
@@ -57,7 +57,19 @@ module Seira
|
|
57
57
|
def run_help
|
58
58
|
puts SUMMARY
|
59
59
|
puts "\n\n"
|
60
|
-
puts
|
60
|
+
puts <<~HELPTEXT
|
61
|
+
help: Display the help page.
|
62
|
+
list: List the currently running jobs in the given application namespace.
|
63
|
+
delete: Delete a stuck migration job via Kubernetes job 'seira cluster app delete job-name'.
|
64
|
+
run: Execute a given command to issue a schema migration.
|
65
|
+
|
66
|
+
options:
|
67
|
+
--template-file: Provide a job template file to use. (--template-file=template.yaml.erb)
|
68
|
+
--async: Wait for the job to finish before exiting.
|
69
|
+
--no_delete: Do not delete the Kubernetes job after it is finished.
|
70
|
+
--size: Use a predetermined resource sizing template for this job. (Default size: 1)
|
71
|
+
|
72
|
+
HELPTEXT
|
61
73
|
end
|
62
74
|
|
63
75
|
def run_list
|
@@ -75,6 +87,7 @@ module Seira
|
|
75
87
|
async = false # Wait for job to finish before continuing.
|
76
88
|
no_delete = false # Delete at end
|
77
89
|
resource_hash = RESOURCE_SIZES['1']
|
90
|
+
template_file = "template.yaml"
|
78
91
|
|
79
92
|
# Loop through args and process any that aren't just the command to run
|
80
93
|
loop do
|
@@ -94,6 +107,8 @@ module Seira
|
|
94
107
|
elsif arg.start_with?('--size=')
|
95
108
|
size = arg.split('=')[1]
|
96
109
|
resource_hash = RESOURCE_SIZES[size]
|
110
|
+
elsif arg.start_with?('--template-file=')
|
111
|
+
template_file = arg.split('=')[1]
|
97
112
|
else
|
98
113
|
puts "Warning: Unrecognized argument #{arg}"
|
99
114
|
end
|
@@ -113,7 +128,7 @@ module Seira
|
|
113
128
|
|
114
129
|
source = "kubernetes/#{context[:cluster]}/#{app}" # TODO: Move to method in app.rb
|
115
130
|
Dir.mktmpdir do |destination|
|
116
|
-
file_name = discover_job_template_file_name(source)
|
131
|
+
file_name = discover_job_template_file_name(source, template_file)
|
117
132
|
|
118
133
|
FileUtils.mkdir_p destination # Create the nested directory
|
119
134
|
FileUtils.copy_file "#{source}/jobs/#{file_name}", "#{destination}/#{file_name}"
|
@@ -174,11 +189,11 @@ module Seira
|
|
174
189
|
end
|
175
190
|
end
|
176
191
|
|
177
|
-
def discover_job_template_file_name(source)
|
178
|
-
if File.exist?("#{source}/jobs
|
179
|
-
"
|
192
|
+
def discover_job_template_file_name(source, template_file)
|
193
|
+
if File.exist?("#{source}/jobs/#{template_file}.erb")
|
194
|
+
"#{template_file}.erb"
|
180
195
|
else
|
181
|
-
|
196
|
+
template_file
|
182
197
|
end
|
183
198
|
end
|
184
199
|
end
|
data/lib/seira/pods.rb
CHANGED
data/lib/seira/random.rb
CHANGED
@@ -70,7 +70,6 @@ module Seira
|
|
70
70
|
bombay
|
71
71
|
bongo
|
72
72
|
bonobo
|
73
|
-
booby
|
74
73
|
budgerigar
|
75
74
|
buffalo
|
76
75
|
bulldog
|
@@ -120,7 +119,6 @@ module Seira
|
|
120
119
|
dachshund
|
121
120
|
dalmatian
|
122
121
|
deer
|
123
|
-
dhole
|
124
122
|
dingo
|
125
123
|
dinosaur
|
126
124
|
discus
|
@@ -193,7 +191,6 @@ module Seira
|
|
193
191
|
hippopotamus
|
194
192
|
hornet
|
195
193
|
horse
|
196
|
-
human
|
197
194
|
hummingbird
|
198
195
|
hyena
|
199
196
|
ibis
|
data/lib/seira/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seira
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Ringwelski
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|
@@ -103,12 +103,12 @@ extensions: []
|
|
103
103
|
extra_rdoc_files: []
|
104
104
|
files:
|
105
105
|
- ".default-rubocop.yml"
|
106
|
+
- ".github/workflows/ruby.yml"
|
106
107
|
- ".gitignore"
|
107
108
|
- ".hound.yml"
|
108
109
|
- ".rspec"
|
109
110
|
- ".rubocop.yml"
|
110
111
|
- ".ruby-version"
|
111
|
-
- ".travis.yml"
|
112
112
|
- Gemfile
|
113
113
|
- LICENSE
|
114
114
|
- README.md
|
@@ -143,7 +143,7 @@ homepage: https://github.com/joinhandshake/seira
|
|
143
143
|
licenses:
|
144
144
|
- MIT
|
145
145
|
metadata: {}
|
146
|
-
post_install_message:
|
146
|
+
post_install_message:
|
147
147
|
rdoc_options: []
|
148
148
|
require_paths:
|
149
149
|
- lib
|
@@ -159,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
159
|
version: '0'
|
160
160
|
requirements: []
|
161
161
|
rubygems_version: 3.0.3
|
162
|
-
signing_key:
|
162
|
+
signing_key:
|
163
163
|
specification_version: 4
|
164
164
|
summary: An opinionated library for building applications on Kubernetes.
|
165
165
|
test_files: []
|