seira 0.1.5 → 0.1.6

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
  SHA1:
3
- metadata.gz: 137cf8ac1506f10dac88ef667c49c5f6a30b515b
4
- data.tar.gz: f55493c0ddfc6615f0954d9672d78a2399e41bdb
3
+ metadata.gz: 2139b5d967293724e307e500bd87c3a77998f563
4
+ data.tar.gz: 5eb1767a8f7c23a6dad5357823fd651d5089e21d
5
5
  SHA512:
6
- metadata.gz: 9d179c9b561dafcf2ecc0162e4c493b488a28e18e62195d8913c2aa2d211f5af805301cc5f8d6dd9f2ec59feae023d36409ce7d0e51b71a7852d140afe636a31
7
- data.tar.gz: c31974b1f7b50272779f76f1628ed5aade976fe5c36035314b7774d4e3e3092ad1ba38b750ab8ebb6f1e83ecca6c86eec6f066927770c29e7371f5fbc2a16244
6
+ metadata.gz: 38121663c35640ef9a8f6c2180965197f088b46ed609a0ea122b301907653b69ae93c7e13d164868f1d4c21ac71964e4f281323a916352f34a3186e63950c63b
7
+ data.tar.gz: d167aa0f6e90e6130e42721b0240867ed03d9cdcbaa13c245eb86ca29a45e4baf3dc7845e076152a178238b43e5d4e74cc408ad8674c506f51685f61040c720b
data/README.md CHANGED
@@ -33,7 +33,7 @@ The `gem install seira` option may be preferred for shorter typing, or generatin
33
33
 
34
34
  ## Usage
35
35
 
36
- This library only currently works with `gcloud` and `kubectl`, meaning Google Container Engine and Kubernetes.
36
+ This library only currently works with `gcloud` and `kubectl`, meaning Google Cloud Platform and Kubernetes.
37
37
 
38
38
  All commands follow a pattern:
39
39
 
@@ -79,7 +79,7 @@ This specification is read in and used to determine what `gcloud` context to use
79
79
 
80
80
  ### Manifest Files
81
81
 
82
- Seira expects your Kubernetes manifests to exist in the "kubernetes/<cluster>/<app>" directory. When a deploy is run on `foo` app in `staging` cluster, it looks to `kubernetes/staging/foo` directory for the manifest files.
82
+ Seira expects your Kubernetes manifests to exist in the "kubernetes/cluster-name/app-name" directory. When a deploy is run on `foo` app in `staging` cluster, it looks to `kubernetes/staging/foo` directory for the manifest files.
83
83
 
84
84
  ### Assumptions
85
85
 
@@ -91,7 +91,46 @@ Seira expects your Kubernetes manifests to exist in the "kubernetes/<cluster>/<a
91
91
 
92
92
  In order to use Seira, an initial setup is needed. Use the `seira setup` command to set up each of your clusters in your configuration file.
93
93
 
94
- ## Example functionality
94
+ ## Current Functionality
95
+
96
+ All functionality is targeted to be a platform on top of Kubernetes that has a Heroku-like experience.
97
+
98
+ ### App
99
+
100
+ * Bootstrap new applications
101
+ * Apply new configurations to an application
102
+ * Scale app tiers
103
+ * Restart an application
104
+
105
+ ### Database (Postgres)
106
+
107
+ * List postgres instances
108
+ * Create new primary and automatically set the right secrets with configurability such as HA, CPU, Memory.
109
+ * Create a new replica on the primary
110
+ * Pgbouncer yaml generation for all new instances
111
+ * Delete an instance
112
+
113
+ ### Memcached
114
+
115
+ * List, delete memcached instances
116
+ * Create new memcached instances with configurable CPU and Memory using Helm.
117
+
118
+ ### Redis
119
+
120
+ * List, delete Redis instances
121
+ * Create new Redis instances with configurable CPU and Memory using Helm.
122
+
123
+ ### Pods
124
+
125
+ * List pods for a given app
126
+ * Connect to a running pod to run commands
127
+ * Run a one-off command such as `rails db:migrate`
128
+
129
+ ### Secrets
130
+
131
+ * List, set, unset secrets
132
+
133
+ ## Example Usage
95
134
 
96
135
  ### Running Proxy UI
97
136
 
data/lib/seira/app.rb CHANGED
@@ -52,6 +52,9 @@ module Seira
52
52
  private
53
53
 
54
54
  def run_bootstrap
55
+ # TODO: Verify that 00-namespace exists
56
+ # TODO: Do conformance test on the yaml files before running anything, including that 00-namespace.yaml exists and has right name
57
+ system("kubectl apply -f kubernetes/#{context[:cluster]}/#{app}/00-namespace.yaml") # Create namespace before anything else
55
58
  bootstrap_main_secret
56
59
  bootstrap_cloudsql_secret
57
60
  bootstrap_gcr_secret
@@ -71,7 +74,10 @@ module Seira
71
74
  revision = current_revision
72
75
  end
73
76
 
74
- replacement_hash = { 'REVISION' => revision }
77
+ replacement_hash = {
78
+ 'REVISION' => revision,
79
+ 'RESTARTED_AT_VALUE' => "Initial Deploy for #{revision}"
80
+ }
75
81
 
76
82
  if restart
77
83
  replacement_hash['RESTARTED_AT_VALUE'] = Time.now.to_s
data/lib/seira/pods.rb CHANGED
@@ -75,6 +75,8 @@ module Seira
75
75
  # Set defaults
76
76
  tier = 'web'
77
77
  clear_commands = false
78
+ detached = false
79
+ container_name = app
78
80
 
79
81
  # Loop through args and process any that aren't just the command to run
80
82
  loop do
@@ -86,8 +88,12 @@ module Seira
86
88
  break unless arg.start_with? '--'
87
89
  if arg.start_with? '--tier='
88
90
  tier = arg.split('=')[1]
89
- elsif arg.start_with? '--clear-commands='
90
- clear_commands = %w[true yes t y].include? arg.split('=')[1]
91
+ elsif arg == '--clear-commands'
92
+ clear_commands = true
93
+ elsif arg == '--detached'
94
+ detached = true
95
+ elsif arg.start_with? '--container='
96
+ container_name = arg.split('=')[1]
91
97
  else
92
98
  puts "Warning: Unrecognized argument #{arg}"
93
99
  end
@@ -122,28 +128,39 @@ module Seira
122
128
  end
123
129
  end
124
130
 
131
+ if detached
132
+ target_container = spec['containers'].find { |container| container['name'] == container_name }
133
+ if target_container.nil?
134
+ puts "Could not find container '#{container_name}' to run command in"
135
+ exit(1)
136
+ end
137
+ target_container['command'] = ['bash', '-c', command]
138
+ end
139
+
125
140
  puts "Creating temporary pod #{temp_name}"
126
141
  unless system("kubectl --namespace=#{app} create -f - <<JSON\n#{temp_pod.to_json}\nJSON")
127
142
  puts 'Failed to create pod'
128
143
  exit(1)
129
144
  end
130
145
 
131
- # Check pod status until it's ready to connect to
132
- print 'Waiting for pod to start...'
133
- loop do
134
- pod = JSON.parse(`kubectl --namespace=#{app} get pods/#{temp_name} -o json`)
135
- break if pod['status']['phase'] == 'Running'
136
- print '.'
137
- sleep 1
138
- end
139
- print "\n"
146
+ unless detached
147
+ # Check pod status until it's ready to connect to
148
+ print 'Waiting for pod to start...'
149
+ loop do
150
+ pod = JSON.parse(`kubectl --namespace=#{app} get pods/#{temp_name} -o json`)
151
+ break if pod['status']['phase'] == 'Running'
152
+ print '.'
153
+ sleep 1
154
+ end
155
+ print "\n"
140
156
 
141
- # Connect to the pod, running the specified command
142
- connect_to_pod(temp_name, command)
157
+ # Connect to the pod, running the specified command
158
+ connect_to_pod(temp_name, command)
143
159
 
144
- # Clean up
145
- unless system("kubectl --namespace=#{app} delete pod #{temp_name}")
146
- puts "Warning: failed to clean up pod #{temp_name}"
160
+ # Clean up
161
+ unless system("kubectl --namespace=#{app} delete pod #{temp_name}")
162
+ puts "Warning: failed to clean up pod #{temp_name}"
163
+ end
147
164
  end
148
165
  end
149
166
 
data/lib/seira/secrets.rb CHANGED
@@ -8,7 +8,7 @@ require 'base64'
8
8
  # TODO: Can we avoid writing to disk completely and instead pipe in raw json?
9
9
  module Seira
10
10
  class Secrets
11
- VALID_ACTIONS = %w[help get set unset list list-decoded create-pgbouncer-secret].freeze
11
+ VALID_ACTIONS = %w[help get set unset list list-decoded].freeze
12
12
  PGBOUNCER_SECRETS_NAME = 'pgbouncer-secrets'.freeze
13
13
  SUMMARY = "Manage your application's secrets and environment variables.".freeze
14
14
 
@@ -65,7 +65,8 @@ module Seira
65
65
 
66
66
  def get(key)
67
67
  secrets = fetch_current_secrets
68
- Base64.decode64(secrets['data'][key])
68
+ encoded_value = secrets.dig('data', key)
69
+ encoded_value.nil? ? nil : Base64.decode64(encoded_value)
69
70
  end
70
71
 
71
72
  private
@@ -73,7 +74,14 @@ module Seira
73
74
  def run_help
74
75
  puts SUMMARY
75
76
  puts "\n\n"
76
- puts "TODO"
77
+ puts "Possible actions:\n\n"
78
+ puts "get: fetch the value of a secret: `secrets get PASSWORD`"
79
+ puts "set: set one or more secret values: `secrets set USERNAME=admin PASSWORD=asdf`"
80
+ puts " to specify a value with spaces: `secrets set LIPSUM=\"Lorem ipsum\"`"
81
+ puts " to specify a value with newlines: `secrets set RSA_KEY=\"$(cat key.pem)\"`"
82
+ puts "unset: remove a secret: `secrets unset PASSWORD`"
83
+ puts "list: list all secret keys and values"
84
+ puts "list: list all secret keys and values, and decode from base64"
77
85
  end
78
86
 
79
87
  def validate_single_key
@@ -91,7 +99,12 @@ module Seira
91
99
  end
92
100
 
93
101
  def run_get
94
- puts "#{key}: #{get(key)}"
102
+ value = get(key)
103
+ if value.nil?
104
+ puts "Secret '#{key}' not found"
105
+ else
106
+ puts "#{key}: #{value}"
107
+ end
95
108
  end
96
109
 
97
110
  def run_set
data/lib/seira/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Seira
2
- VERSION = "0.1.5".freeze
2
+ VERSION = "0.1.6".freeze
3
3
  end
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.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Ringwelski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-27 00:00:00.000000000 Z
11
+ date: 2018-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline