kaiser 0.5.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -296
- data/exe/kaiser +2 -2
- data/lib/kaiser/after_dotter.rb +1 -1
- data/lib/kaiser/cli.rb +32 -9
- data/lib/kaiser/cmds/db_load.rb +2 -2
- data/lib/kaiser/cmds/db_reset.rb +2 -2
- data/lib/kaiser/cmds/db_reset_hard.rb +2 -2
- data/lib/kaiser/cmds/db_save.rb +1 -1
- data/lib/kaiser/cmds/set.rb +7 -4
- data/lib/kaiser/cmds/show.rb +4 -3
- data/lib/kaiser/cmds/up.rb +3 -2
- data/lib/kaiser/config.rb +22 -7
- data/lib/kaiser/databases/postgres.rb +2 -0
- data/lib/kaiser/dotter.rb +3 -0
- data/lib/kaiser/kaiserfile.rb +5 -1
- data/lib/kaiser/plugin.rb +4 -0
- data/lib/kaiser/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10dad8745e43760fa913798075e8e758781a06fc8d61b31162182e0485dc1fad
|
4
|
+
data.tar.gz: f3105c5c67054c131bfe863253074a7ca2dd43d01df14414c6b10584b51f1354
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 516bf9535b0c3203cee6410452e132068b1825f5ed13ed856f838d127c3be93dc4eac9d065b6f420cf0d7d79d36c051c748611252e33e1f487385cf7ac39dcad
|
7
|
+
data.tar.gz: ff11e27fc65b771a3d1686ca45c7d18decaf6f0f37d8b29652818682bd9f589e2e63e00f702cf020a9583137232afd0aa9f56eec3df38955ee59fceb3f980679
|
data/README.md
CHANGED
@@ -97,308 +97,18 @@ open http://myapp.lvh.me
|
|
97
97
|
|
98
98
|
And enjoy previewing your app!
|
99
99
|
|
100
|
-
|
100
|
+
## More documentation
|
101
101
|
|
102
|
-
|
102
|
+
You can find even more documentation in https://tech.degica.com/kaiser.
|
103
103
|
|
104
|
-
|
104
|
+
If you wish to read a HTML version of this documentation you can go:
|
105
105
|
|
106
|
-
```ruby
|
107
|
-
# Example
|
108
|
-
plugin :git_submodule
|
109
|
-
```
|
110
|
-
|
111
|
-
See further below to find available plugins and their usage
|
112
|
-
|
113
|
-
- `dockerfile` - This command is always required. Takes 1 parameter: the name of the Dockerfile you want to use with this Kaiserfile. You only need to use this command once. Using it multiple times will simply cause the last command to be used. It takes relative paths and the paths are relative to where you run Kaiser.
|
114
|
-
|
115
|
-
```ruby
|
116
|
-
# Example
|
117
|
-
dockerfile 'Dockerfile'
|
118
|
-
```
|
119
|
-
|
120
|
-
- `service` - This command is optional. Use it to define additional containers that should be set up along with your environment,. You can use it multiple times to define multiple services. It takes multiple parameters, a name parameter which is required and optional parameters.
|
121
|
-
|
122
|
-
```ruby
|
123
|
-
# example that sets up a redis server for your app
|
124
|
-
service 'redis'
|
125
|
-
```
|
126
|
-
|
127
|
-
The following parameters are allowed for this command:
|
128
|
-
- image
|
129
|
-
|
130
|
-
```ruby
|
131
|
-
# example that tells it to use the redis server with the alpine tag from 'myrepo'
|
132
|
-
service 'redis', image: 'myrepo/redis:alpine'
|
133
|
-
```
|
134
|
-
|
135
|
-
- `attach_mount` - Takes 2 parameters: The first parameter is the relative path of a folder or a file outside the container and the second parameter is its absolute path inside the container. This is only used when `kaiser attach` or `kaiser up -a` is used. This will mount the file or folder inside the container and sync their contents. If the file you specified does not exist, Kaiser will create a folder where you specify it and then mount that folder inside the container. You can specify as many of these as you want.
|
136
|
-
|
137
|
-
```ruby
|
138
|
-
# Example to mount the `app` directory into the container's `/srv/files/app`
|
139
|
-
attach_mount 'app', '/srv/files/app'
|
140
|
-
```
|
141
|
-
|
142
|
-
- `expose` - Takes 1 parameter: The port of the server running inside the container. This port is not exposed on the host, so it will not occupy a port on the computer you run kaiser on. Instead, Kaiser will select a random port on the host computer to forward traffic to and from. You can only use this statement once. If you have multiple of these statements the last one will be used.
|
143
|
-
|
144
|
-
```ruby
|
145
|
-
# Example to expose the port 3636
|
146
|
-
expose 3636
|
147
|
-
```
|
148
|
-
|
149
|
-
- `app_params` - Takes 1 parameter: A string of parameters to the `docker run` command to add custom environment variables with. Please refer to the docker documentation to see what kinds of parameters you can pass to the `docker run` command. By default this is just an empty string. You can only pass one of these. Any newline characters in the string will be converted into spaces.
|
150
|
-
|
151
|
-
```ruby
|
152
|
-
# Example
|
153
|
-
app_params '-e INTERACTIVE=no'
|
154
|
-
```
|
155
|
-
|
156
|
-
- `type` - Takes 1 parameter: Right now the only parameter it can take is `:http`. If this parameter is specified, kaiser will poll the application until it receives a 200 status code before it closes when you use `kaiser up` If it doesn't it will close with a status code of 1.
|
157
|
-
|
158
|
-
```ruby
|
159
|
-
# Example
|
160
|
-
type :http
|
161
|
-
```
|
162
|
-
|
163
|
-
- `db_reset_command` - Takes 1 parameter: A command to reset the database. This command is optional. By default this parameter is `echo "no db to reset"`. You can only specify one of these. If you have multiple of these commands only the last one will be used.
|
164
|
-
|
165
|
-
```ruby
|
166
|
-
# Example if running this command drops the db and recreates it.
|
167
|
-
db_reset_command 'rake db:reset'
|
168
|
-
```
|
169
|
-
|
170
|
-
- `db` - Takes 1 parameter in the form of a hash. The default value of the hash is as follows:
|
171
|
-
|
172
|
-
(You do not have to use this strictly, see the Database Plugin below to see an easier way to include MySQL and Postgres in your environment)
|
173
|
-
|
174
|
-
```ruby
|
175
|
-
# Default settings
|
176
|
-
{
|
177
|
-
image: 'alpine',
|
178
|
-
port: 1234,
|
179
|
-
data_dir: '/tmp/data',
|
180
|
-
params: '',
|
181
|
-
commands: 'echo "no db"',
|
182
|
-
waitscript: 'echo "no dbwait"',
|
183
|
-
waitscript_params: ''
|
184
|
-
}
|
185
|
-
```
|
186
|
-
|
187
|
-
You can use this to customize the database that you wish to use with your server.
|
188
|
-
|
189
|
-
### Alternative Kaiserfile
|
190
|
-
|
191
|
-
If you want change your dev environment for a project, but don't want to overwrite the project's Kaiserfile/Dockerfile,
|
192
|
-
you can use an alternative Kaiserfile.
|
193
|
-
|
194
|
-
An alternative Kaiserfile is located at `~/kaiserfiles/Kaiserfile.<app name>`,
|
195
|
-
where `<app name>` is replaced with the name you provided when calling `kaiser init`.
|
196
|
-
|
197
|
-
If Kaiser detects an alternative Kaiserfile, it will use it instead of the Project root one. Some things to watch out for:
|
198
|
-
|
199
|
-
- Of course, your app may behave differently if you change your environment from the project's default.
|
200
|
-
- The `dockerfile` declaration is still relative to the project root. If you want to use a custom Dockerfile as well, you need to specify the its full path in the Kaiserfile.
|
201
|
-
- If the project's Kaiserfile or Dockerfile changes, you'll have to update your custom ones manually.
|
202
|
-
|
203
|
-
### Debugging
|
204
|
-
|
205
|
-
You can also debug by going
|
206
|
-
|
207
|
-
```sh
|
208
|
-
bundle exec kaiser attach
|
209
106
|
```
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
You can also run stuff inside by going
|
214
|
-
|
215
|
-
```sh
|
216
|
-
bundle exec kaiser login sh
|
217
|
-
```
|
218
|
-
|
219
|
-
And you can do anything inside the container
|
220
|
-
|
221
|
-
### Attach to the container
|
222
|
-
|
223
|
-
If you want to run with the container in the foreground simply go
|
224
|
-
|
225
|
-
```sh
|
226
|
-
bundle exec kaiser attach
|
107
|
+
cd docs
|
108
|
+
bundle install
|
109
|
+
bundle exec weaver
|
227
110
|
```
|
228
111
|
|
229
|
-
This is similar to `kaiser login` but it terminates the running container, whereas `kaiser login` will simply run you in the same container as the running container.
|
230
|
-
|
231
|
-
```sh
|
232
|
-
bundle exec kaiser attach nano /etc/hosts
|
233
|
-
```
|
234
|
-
|
235
|
-
### Save database state
|
236
|
-
|
237
|
-
```sh
|
238
|
-
bundle exec kaiser db_save customer_setup
|
239
|
-
```
|
240
|
-
|
241
|
-
You can also save your database state to a file in your current dir:
|
242
|
-
|
243
|
-
```sh
|
244
|
-
bundle exec kaiser db_save ./my_setup.dbimage
|
245
|
-
```
|
246
|
-
|
247
|
-
### Load database state
|
248
|
-
|
249
|
-
```sh
|
250
|
-
bundle exec kaiser db_load customer_setup
|
251
|
-
```
|
252
|
-
|
253
|
-
You can load a previously saved database file that you have
|
254
|
-
|
255
|
-
```sh
|
256
|
-
bundle exec kaiser db_load ./my_setup.dbimage
|
257
|
-
```
|
258
|
-
|
259
|
-
### Get ports
|
260
|
-
|
261
|
-
Kaiser decides what ports to use on the host. To know them simply go
|
262
|
-
|
263
|
-
```sh
|
264
|
-
bundle exec kaiser show ports
|
265
|
-
```
|
266
|
-
|
267
|
-
### Curious?
|
268
|
-
|
269
|
-
You can see what Kaiser is doing under the hood with the `-v` flag:
|
270
|
-
|
271
|
-
```sh
|
272
|
-
bundle exec kaiser -v db_reset
|
273
|
-
```
|
274
|
-
|
275
|
-
## Reverse proxy
|
276
|
-
|
277
|
-
Why does it magically work?
|
278
|
-
|
279
|
-
By default kaiser sets up a reverse proxy that puts all your apps on a subdomain of (lvh.me)[lvh.me]. This means all your environments can be accessed like so: `envname.lvh.me`. Easy.
|
280
|
-
|
281
|
-
[Read more about lvh.me](https://nickjanetakis.com/blog/ngrok-lvhme-nipio-a-trilogy-for-local-development-and-testing#lvh-me)
|
282
|
-
|
283
|
-
#### HTTPS
|
284
|
-
|
285
|
-
If you want to you can create a self-signed HTTPS certificate for lvh.me, trust it and use it to access your dev sites with HTTPS! (Cool! Now you can debug your websites in HTTPS!)
|
286
|
-
|
287
|
-
It is easy to do this: Simply run
|
288
|
-
|
289
|
-
```sh
|
290
|
-
kaiser set cert-folder /home/me/my-certificate-folder
|
291
|
-
```
|
292
|
-
|
293
|
-
As preparation you need to generate [HTTPS certificates](https://gist.github.com/dagjaneiro/dc1e26d87e745b47c4e2596f6b54022c). You should have the following files:
|
294
|
-
|
295
|
-
```
|
296
|
-
/home/me/my-certificate-folder/lvh.me.crt
|
297
|
-
/home/me/my-certificate-folder/lvh.me.key
|
298
|
-
/home/me/my-certificate-folder/lvh.me.chain.pem
|
299
|
-
```
|
300
|
-
|
301
|
-
Hint: you can create the `.chain.pem` file by going
|
302
|
-
|
303
|
-
```
|
304
|
-
cat lvh.me.crt >> lvh.me.key
|
305
|
-
cat lvh.me.crt >> lvh.me.crt
|
306
|
-
```
|
307
|
-
|
308
|
-
Remember to trust your certificates! Otherwise your browser will give you an error (if it isn't dodgy).
|
309
|
-
|
310
|
-
If you and your colleagues all want to sign using the same certificates, simply put the certificates on a webserver and go:
|
311
|
-
|
312
|
-
```sh
|
313
|
-
kaiser set cert-url https://internal-site.com/dev-certificates
|
314
|
-
```
|
315
|
-
|
316
|
-
and Kaiser will look for certificates at:
|
317
|
-
|
318
|
-
```
|
319
|
-
https://internal-site.com/dev-certificates/lvh.me.crt
|
320
|
-
https://internal-site.com/dev-certificates/lvh.me.key
|
321
|
-
https://internal-site.com/dev-certificates/lvh.me.chain.pem
|
322
|
-
```
|
323
|
-
|
324
|
-
#### HTTP/HTTPS Your own domain
|
325
|
-
|
326
|
-
If you have a fancy setup where you have your own localhost domain (like local.aweso.me) and you can generate your own SSL certificates (yes, very fancy) then you can set the suffix of your domain like this:
|
327
|
-
|
328
|
-
```sh
|
329
|
-
kaiser set http-suffix local.aweso.me
|
330
|
-
```
|
331
|
-
|
332
|
-
And your apps will be all `envname.local.aweso.me`
|
333
|
-
|
334
|
-
#### If you change these settings
|
335
|
-
|
336
|
-
You will need to run
|
337
|
-
|
338
|
-
```sh
|
339
|
-
kaiser shutdown
|
340
|
-
```
|
341
|
-
|
342
|
-
And run
|
343
|
-
|
344
|
-
```sh
|
345
|
-
kaiser up
|
346
|
-
```
|
347
|
-
|
348
|
-
Again for changes to take effect.
|
349
|
-
|
350
|
-
## Plugins
|
351
|
-
|
352
|
-
Kaiser has a plugin system that adds commands to the Kaiserfile to help improve your workflow. Below are a list of built-in plugins that come with Kaiser.
|
353
|
-
|
354
|
-
### Git Submodules Plugin
|
355
|
-
|
356
|
-
This plugin ensures that any submodules your repo has are checked out. If they are not, it will cause Kaiser to exit with a status code of 1.
|
357
|
-
|
358
|
-
Usage:
|
359
|
-
|
360
|
-
```ruby
|
361
|
-
plugin :git_submodule
|
362
|
-
```
|
363
|
-
|
364
|
-
That's all you need!
|
365
|
-
|
366
|
-
### Database Plugin
|
367
|
-
|
368
|
-
This plugin allows you to specify well known DBs (MySQL and PostgresSQL) with default values that work generally. You can customize your database however you want it for your own project.
|
369
|
-
|
370
|
-
Usage:
|
371
|
-
|
372
|
-
```ruby
|
373
|
-
# Simplest usage
|
374
|
-
plugin :database
|
375
|
-
|
376
|
-
def_db :mysql
|
377
|
-
```
|
378
|
-
|
379
|
-
If for example you wish to use a different root password, simply go
|
380
|
-
|
381
|
-
```ruby
|
382
|
-
plugin :database
|
383
|
-
|
384
|
-
def_db mysql: { root_password: 'extremesecret' }
|
385
|
-
```
|
386
|
-
|
387
|
-
Sometimes you want to use a specific version for testing. You can set up the version by going
|
388
|
-
|
389
|
-
```ruby
|
390
|
-
plugin :database
|
391
|
-
|
392
|
-
def_db postgres: { version: '9.4' }
|
393
|
-
```
|
394
|
-
|
395
|
-
You can also pass startup parameters to your database server:
|
396
|
-
|
397
|
-
```ruby
|
398
|
-
plugin :database
|
399
|
-
|
400
|
-
def_db mysql: { parameters: '--verbose' }
|
401
|
-
```
|
402
112
|
|
403
113
|
## Development
|
404
114
|
|
data/exe/kaiser
CHANGED
@@ -20,8 +20,8 @@ Kaiser::SUB_COMMANDS.each { |k, v| Kaiser::Cli.register(k, v) }
|
|
20
20
|
# the 'end parser hacks' comment are all hacks to marry the above two behaviours.
|
21
21
|
|
22
22
|
global_opts = [
|
23
|
-
[:verbose, "Show Kaiser's debug output", short: '-v'],
|
24
|
-
[:quiet, 'Suppress all output', short: '-q']
|
23
|
+
[:verbose, "Show Kaiser's debug output", { short: '-v' }],
|
24
|
+
[:quiet, 'Suppress all output', { short: '-q' }]
|
25
25
|
]
|
26
26
|
|
27
27
|
parser = Optimist::Parser.new do
|
data/lib/kaiser/after_dotter.rb
CHANGED
data/lib/kaiser/cli.rb
CHANGED
@@ -83,7 +83,7 @@ module Kaiser
|
|
83
83
|
@subcommands.each do |name, klass|
|
84
84
|
name_s = name.to_s
|
85
85
|
|
86
|
-
output += name_s
|
86
|
+
output += "#{name_s}\n"
|
87
87
|
output += name_s.gsub(/./, '-')
|
88
88
|
output += "\n"
|
89
89
|
output += klass.usage
|
@@ -129,6 +129,7 @@ module Kaiser
|
|
129
129
|
ensure_db_volume
|
130
130
|
start_db
|
131
131
|
return if File.exist?(default_db_image)
|
132
|
+
return unless db_present?
|
132
133
|
|
133
134
|
# Some databases keep state around, best to clean it.
|
134
135
|
stop_db
|
@@ -144,16 +145,20 @@ module Kaiser
|
|
144
145
|
#{app_params}
|
145
146
|
kaiser:#{envname}-#{current_branch} #{db_reset_command}"
|
146
147
|
|
147
|
-
save_db('
|
148
|
+
save_db('default')
|
148
149
|
end
|
149
150
|
|
150
151
|
def save_db(name)
|
152
|
+
return unless db_present?
|
153
|
+
|
151
154
|
killrm db_container_name
|
152
155
|
save_db_state_from container: db_volume_name, to_file: db_image_path(name)
|
153
156
|
start_db
|
154
157
|
end
|
155
158
|
|
156
159
|
def load_db(name)
|
160
|
+
return unless db_present?
|
161
|
+
|
157
162
|
check_db_image_exists(name)
|
158
163
|
killrm db_container_name
|
159
164
|
CommandRunner.run Config.out, "docker volume rm #{db_volume_name}"
|
@@ -186,15 +191,19 @@ module Kaiser
|
|
186
191
|
-v #{file}:#{file}
|
187
192
|
ruby:alpine
|
188
193
|
tar xvjf #{file} -C #{db_data_directory}
|
189
|
-
--strip #{db_data_directory.scan(%r{
|
194
|
+
--strip #{db_data_directory.scan(%r{/}).count}"
|
190
195
|
end
|
191
196
|
|
192
197
|
def stop_db
|
198
|
+
return unless db_present?
|
199
|
+
|
193
200
|
Config.info_out.puts 'Stopping database'
|
194
201
|
killrm db_container_name
|
195
202
|
end
|
196
203
|
|
197
204
|
def start_db
|
205
|
+
return unless db_present?
|
206
|
+
|
198
207
|
Config.info_out.puts 'Starting up database'
|
199
208
|
run_if_dead db_container_name, "docker run -d
|
200
209
|
-p #{db_port}:#{db_expose}
|
@@ -226,7 +235,7 @@ module Kaiser
|
|
226
235
|
end
|
227
236
|
|
228
237
|
def default_db_image
|
229
|
-
db_image_path('
|
238
|
+
db_image_path('default')
|
230
239
|
end
|
231
240
|
|
232
241
|
def attach_app
|
@@ -272,11 +281,11 @@ module Kaiser
|
|
272
281
|
end
|
273
282
|
|
274
283
|
def tmp_waitscript_name
|
275
|
-
"#{Config.config_dir}
|
284
|
+
"#{Config.config_dir}/#{envname}-dbwaitscript"
|
276
285
|
end
|
277
286
|
|
278
287
|
def tmp_dockerfile_name
|
279
|
-
"#{Config.config_dir}
|
288
|
+
"#{Config.config_dir}/#{envname}-dockerfile"
|
280
289
|
end
|
281
290
|
|
282
291
|
def tmp_db_waiter
|
@@ -327,7 +336,7 @@ module Kaiser
|
|
327
336
|
|
328
337
|
Config.info_out.puts 'Waiting for server to start...'
|
329
338
|
|
330
|
-
http_code_extractor = "curl -s -o /dev/null -I -w \"
|
339
|
+
http_code_extractor = "curl -s -o /dev/null -I -w \"\%<http_code>s\" http://#{app_container_name}:#{app_expose}"
|
331
340
|
unreachable_test = "#{http_code_extractor} | grep -q 000"
|
332
341
|
|
333
342
|
# This waitscript runs until curl returns a non-unreachable status code
|
@@ -354,13 +363,19 @@ module Kaiser
|
|
354
363
|
# If curl returns an error status the script will cut out and
|
355
364
|
# the app container died error will be displayed.
|
356
365
|
raise Kaiser::Error, "Failed with HTTP status: #{line}" if line =~ /^[0-9]{3}$/ && line != '200'
|
357
|
-
|
366
|
+
|
367
|
+
if line != '!' && container_dead?(app_container_name)
|
368
|
+
raise Kaiser::Error,
|
369
|
+
'App container died. Run `kaiser logs` to see why.'
|
370
|
+
end
|
358
371
|
end
|
359
372
|
|
360
373
|
Config.info_out.puts 'Started successfully!'
|
361
374
|
end
|
362
375
|
|
363
376
|
def wait_for_db
|
377
|
+
return unless db_present?
|
378
|
+
|
364
379
|
Config.info_out.puts 'Waiting for database to start...'
|
365
380
|
run_blocking_script(db_image, db_waitscript_params, db_waitscript)
|
366
381
|
Config.info_out.puts 'Started.'
|
@@ -387,7 +402,15 @@ module Kaiser
|
|
387
402
|
end
|
388
403
|
|
389
404
|
def db_image
|
390
|
-
|
405
|
+
platform = ''
|
406
|
+
platform = "--platform #{Config.kaiserfile.database[:platform]}" if Config.kaiserfile.database[:platform]&.length
|
407
|
+
|
408
|
+
image = Config.kaiserfile.database[:image]
|
409
|
+
"#{platform} #{image}"
|
410
|
+
end
|
411
|
+
|
412
|
+
def db_present?
|
413
|
+
db_image != 'none'
|
391
414
|
end
|
392
415
|
|
393
416
|
def db_commands
|
data/lib/kaiser/cmds/db_load.rb
CHANGED
@@ -11,7 +11,7 @@ module Kaiser
|
|
11
11
|
|
12
12
|
Alternatively you can also load it from your current directory.
|
13
13
|
|
14
|
-
If no database name was provided, the default database stored at \`~/.kaiser/<ENV_NAME>/<current_github_branch_name
|
14
|
+
If no database name was provided, the default database stored at \`~/.kaiser/<ENV_NAME>/<current_github_branch_name>/default.tar.bz\` will be used.
|
15
15
|
|
16
16
|
USAGE: kaiser db_load
|
17
17
|
kaiser db_load DB_BACKUP_FILENAME
|
@@ -21,7 +21,7 @@ module Kaiser
|
|
21
21
|
|
22
22
|
def execute(_opts)
|
23
23
|
ensure_setup
|
24
|
-
name = ARGV.shift || '
|
24
|
+
name = ARGV.shift || 'default'
|
25
25
|
load_db(name)
|
26
26
|
end
|
27
27
|
end
|
data/lib/kaiser/cmds/db_reset.rb
CHANGED
@@ -5,7 +5,7 @@ module Kaiser
|
|
5
5
|
class DbReset < Cli
|
6
6
|
def usage
|
7
7
|
<<~EOS
|
8
|
-
Shuts down the database docker container, *replaces* the database with the default database image stored at \`~/.kaiser/<ENV_NAME>/<current_github_branch_name
|
8
|
+
Shuts down the database docker container, *replaces* the database with the default database image stored at \`~/.kaiser/<ENV_NAME>/<current_github_branch_name>/default.tar.bz\` and brings the container up again.
|
9
9
|
|
10
10
|
This is the same as running \`kaiser db_load\` with no arguments.
|
11
11
|
|
@@ -15,7 +15,7 @@ module Kaiser
|
|
15
15
|
|
16
16
|
def execute(_opts)
|
17
17
|
ensure_setup
|
18
|
-
load_db('
|
18
|
+
load_db('default')
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -5,7 +5,7 @@ module Kaiser
|
|
5
5
|
class DbResetHard < Cli
|
6
6
|
def usage
|
7
7
|
<<~EOS
|
8
|
-
Shuts down the database docker container, deletes the docker volume on which the db was stored, deletes the default database image stored at \`~/.kaiser/<ENV_NAME>/<current_github_branch_name
|
8
|
+
Shuts down the database docker container, deletes the docker volume on which the db was stored, deletes the default database image stored at \`~/.kaiser/<ENV_NAME>/<current_github_branch_name>/default.tar.bz\`, rebuilds the docker volume and the default database image from scratch and then brings the container up again.
|
9
9
|
|
10
10
|
USAGE: kaiser db_reset_hard
|
11
11
|
EOS
|
@@ -13,7 +13,7 @@ module Kaiser
|
|
13
13
|
|
14
14
|
def execute(_opts)
|
15
15
|
ensure_setup
|
16
|
-
FileUtils.rm db_image_path('
|
16
|
+
FileUtils.rm db_image_path('default') if File.exist?(db_image_path('default'))
|
17
17
|
setup_db
|
18
18
|
end
|
19
19
|
end
|
data/lib/kaiser/cmds/db_save.rb
CHANGED
data/lib/kaiser/cmds/set.rb
CHANGED
@@ -23,17 +23,19 @@ module Kaiser
|
|
23
23
|
|
24
24
|
def execute(_opts)
|
25
25
|
cmd = ARGV.shift
|
26
|
-
|
26
|
+
|
27
|
+
case cmd
|
28
|
+
when 'cert-url'
|
27
29
|
Config.config[:cert_source] = {
|
28
30
|
url: ARGV.shift
|
29
31
|
}
|
30
|
-
|
32
|
+
when 'cert-folder'
|
31
33
|
Config.config[:cert_source] = {
|
32
34
|
folder: ARGV.shift
|
33
35
|
}
|
34
|
-
|
36
|
+
when 'http-suffix'
|
35
37
|
Config.config[:http_suffix] = ARGV.shift
|
36
|
-
|
38
|
+
when 'help-https'
|
37
39
|
puts <<~SET_HELP
|
38
40
|
Notes on HTTPS:
|
39
41
|
|
@@ -63,6 +65,7 @@ module Kaiser
|
|
63
65
|
else
|
64
66
|
Optimist.die "Unknown subcommand: '#{cmd}'"
|
65
67
|
end
|
68
|
+
|
66
69
|
save_config
|
67
70
|
end
|
68
71
|
end
|
data/lib/kaiser/cmds/show.rb
CHANGED
@@ -19,10 +19,11 @@ module Kaiser
|
|
19
19
|
valid_cmds = 'ports cert-source http-suffix'
|
20
20
|
return Optimist.die "Available things to show: #{valid_cmds}" unless cmd
|
21
21
|
|
22
|
-
|
22
|
+
case cmd
|
23
|
+
when 'ports'
|
23
24
|
Config.info_out.puts "app: #{app_port}"
|
24
25
|
Config.info_out.puts "db: #{db_port}"
|
25
|
-
|
26
|
+
when 'cert-source'
|
26
27
|
unless Config.config[:cert_source]
|
27
28
|
Optimist.die 'No certificate source set.
|
28
29
|
see kaiser set help'
|
@@ -30,7 +31,7 @@ module Kaiser
|
|
30
31
|
|
31
32
|
source = Config.config[:cert_source][:url] || Config.config[:cert_source][:folder]
|
32
33
|
Config.info_out.puts source
|
33
|
-
|
34
|
+
when 'http-suffix'
|
34
35
|
Config.info_out.puts http_suffix
|
35
36
|
end
|
36
37
|
end
|
data/lib/kaiser/cmds/up.rb
CHANGED
@@ -3,13 +3,14 @@
|
|
3
3
|
module Kaiser
|
4
4
|
module Cmds
|
5
5
|
class Up < Cli
|
6
|
-
option :attach,
|
6
|
+
option :attach,
|
7
|
+
"Bind mount the current source code directory in the app container (as the \`kaiser attach\` command would)", short: '-a'
|
7
8
|
|
8
9
|
def usage
|
9
10
|
<<~EOS
|
10
11
|
Boots up the application in docker as defined in the \`Kaiserfile\` in its source code. Usually this will create two docker containers \`<ENV_NAME>-db\` and \`<ENV_NAME>-app\` running your database and application respectively.
|
11
12
|
|
12
|
-
A backup of the default database is created and saved to \`~/.kaiser/<ENV_NAME>/<current_github_branch_name
|
13
|
+
A backup of the default database is created and saved to \`~/.kaiser/<ENV_NAME>/<current_github_branch_name>/default.tar.bz\`. This can be restored at any time using the \`db_reset\` command.
|
13
14
|
|
14
15
|
USAGE: kaiser up
|
15
16
|
EOS
|
data/lib/kaiser/config.rb
CHANGED
@@ -3,23 +3,23 @@
|
|
3
3
|
module Kaiser
|
4
4
|
class Config
|
5
5
|
class << self
|
6
|
+
attr_accessor :out,
|
7
|
+
:info_out
|
8
|
+
|
6
9
|
attr_reader :work_dir,
|
7
10
|
:config_dir,
|
8
11
|
:config_file,
|
9
12
|
:kaiserfile,
|
10
|
-
:config
|
11
|
-
:out,
|
12
|
-
:info_out
|
13
|
-
|
14
|
-
attr_writer :out,
|
15
|
-
:info_out
|
13
|
+
:config
|
16
14
|
|
17
15
|
def load(work_dir)
|
18
16
|
@work_dir = work_dir
|
19
17
|
@config_dir = "#{ENV['HOME']}/.kaiser"
|
20
18
|
|
19
|
+
migrate_dotted_config_files
|
20
|
+
|
21
21
|
FileUtils.mkdir_p @config_dir
|
22
|
-
@config_file = "#{@config_dir}
|
22
|
+
@config_file = "#{@config_dir}/config.yml"
|
23
23
|
@kaiserfile = Kaiserfile.new("#{@work_dir}/Kaiserfile")
|
24
24
|
|
25
25
|
@config = {
|
@@ -49,6 +49,21 @@ module Kaiser
|
|
49
49
|
@config[:always_verbose]
|
50
50
|
end
|
51
51
|
|
52
|
+
# Up until version 0.5.1, kaiser used dotfiles for all of it configuration.
|
53
|
+
# It makes sense of hide the configuration directory itself but hiding the files
|
54
|
+
# inside of it just causes confusion.
|
55
|
+
#
|
56
|
+
# Kaiser 0.5.2 started using non-dotted files instead. This method renames the old
|
57
|
+
# files in case you have just upgraded from an older version.
|
58
|
+
def migrate_dotted_config_files
|
59
|
+
return unless File.exist?("#{@config_dir}/.config.yml")
|
60
|
+
|
61
|
+
Dir["#{@config_dir}/**/.*"].each do |x|
|
62
|
+
dest = x.sub(%r{/\.([a-z.]+)$}, '/\1')
|
63
|
+
FileUtils.mv x, dest
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
52
67
|
def load_config
|
53
68
|
loaded = YAML.load_file(@config_file) if File.exist?(@config_file)
|
54
69
|
|
@@ -11,12 +11,14 @@ module Kaiser
|
|
11
11
|
testpass = @options[:root_password] || 'testpassword'
|
12
12
|
parameters = @options[:parameters] || ''
|
13
13
|
port = @options[:port] || 3306
|
14
|
+
platform = @options[:platform] || 'linux/amd64'
|
14
15
|
|
15
16
|
{
|
16
17
|
port: port,
|
17
18
|
data_dir: '/var/lib/postgresql/data',
|
18
19
|
params: "-e POSTGRES_PASSWORD=#{testpass}",
|
19
20
|
commands: parameters,
|
21
|
+
platform: platform,
|
20
22
|
waitscript_params: "
|
21
23
|
-e PG_HOST=<%= db_container_name %>
|
22
24
|
-e PG_USER=postgres
|
data/lib/kaiser/dotter.rb
CHANGED
@@ -11,8 +11,11 @@ module Kaiser
|
|
11
11
|
super unless @dotted
|
12
12
|
end
|
13
13
|
|
14
|
+
# rubocop:disable Lint/UselessMethodDefinition
|
15
|
+
# If we remove this method rubocop complains about it not existing instead.
|
14
16
|
def respond_to_missing?(name)
|
15
17
|
super
|
16
18
|
end
|
19
|
+
# rubocop:enable Lint/UselessMethodDefinition
|
17
20
|
end
|
18
21
|
end
|
data/lib/kaiser/kaiserfile.rb
CHANGED
@@ -6,6 +6,7 @@ module Kaiser
|
|
6
6
|
attr_accessor :docker_file_contents,
|
7
7
|
:docker_build_args,
|
8
8
|
:database,
|
9
|
+
:platform,
|
9
10
|
:port,
|
10
11
|
:database_reset_command,
|
11
12
|
:attach_mounts,
|
@@ -16,7 +17,8 @@ module Kaiser
|
|
16
17
|
Optimist.die 'No Kaiserfile in current directory' unless File.exist? filename
|
17
18
|
|
18
19
|
@database = {
|
19
|
-
image: '
|
20
|
+
image: 'none',
|
21
|
+
platform: '',
|
20
22
|
port: 1234,
|
21
23
|
data_dir: '/tmp/data',
|
22
24
|
params: '',
|
@@ -57,12 +59,14 @@ module Kaiser
|
|
57
59
|
def db(image,
|
58
60
|
data_dir:,
|
59
61
|
port:,
|
62
|
+
platform: '',
|
60
63
|
params: '',
|
61
64
|
commands: '',
|
62
65
|
waitscript: nil,
|
63
66
|
waitscript_params: '')
|
64
67
|
@database = {
|
65
68
|
image: image,
|
69
|
+
platform: platform,
|
66
70
|
port: port,
|
67
71
|
data_dir: data_dir,
|
68
72
|
params: params,
|
data/lib/kaiser/plugin.rb
CHANGED
data/lib/kaiser/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kaiser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Siaw
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -183,7 +183,7 @@ licenses:
|
|
183
183
|
- MIT
|
184
184
|
metadata:
|
185
185
|
allowed_push_host: https://rubygems.org
|
186
|
-
post_install_message:
|
186
|
+
post_install_message:
|
187
187
|
rdoc_options: []
|
188
188
|
require_paths:
|
189
189
|
- lib
|
@@ -191,7 +191,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
191
191
|
requirements:
|
192
192
|
- - ">="
|
193
193
|
- !ruby/object:Gem::Version
|
194
|
-
version:
|
194
|
+
version: 2.5.8
|
195
195
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
196
196
|
requirements:
|
197
197
|
- - ">="
|
@@ -199,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
199
|
version: '0'
|
200
200
|
requirements: []
|
201
201
|
rubygems_version: 3.1.2
|
202
|
-
signing_key:
|
202
|
+
signing_key:
|
203
203
|
specification_version: 4
|
204
204
|
summary: Manage your monsters
|
205
205
|
test_files: []
|