kaiser 0.0.0 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fca5130b0e2499829e856a1c50d3456620ae5d30
4
- data.tar.gz: 454dcd8b92a260abc2071dadcb82446ff3515d04
2
+ SHA256:
3
+ metadata.gz: b038487b21d1842c497c567c1b7f5bfcd15113f4099106f3de2d59fbbd1151c9
4
+ data.tar.gz: 7177b78736ccef59a0b4f4c0d2cfd0902cb4db1f5c235e9ed9eb8e6424ff6039
5
5
  SHA512:
6
- metadata.gz: 6a8015dbe99d1184d4c75aa4599e1334288c40622bb7ad3e973244e387c9c52480cc9a97d80f1398f276fc49145a94b2352b0c8026a0488dd53dec5424f43f03
7
- data.tar.gz: bafeacb6d191595108857bbc33b519e3af18e359e7dfc3df52c2c942a952892ef6cbaa8fd8a5c5261c5486b6d23bf8681c6a6e8d2e8e31c91dba911613d4c87d
6
+ metadata.gz: deeb309b718a0bc5a53c108da2e561096deaa05fbf49433c6253c38b40435283e8dc53ac6bd122fe6726176f94e2f5823476805ddc50ba37a6c1b46ef9b3d8fb
7
+ data.tar.gz: b9b5a6bd7ee1e163bbb1ff1ea00fb7112efa47bf8ddb7f5ba1a5c4f9a456cfb5b7475da68bfcbc15889774392b1b7b1c6044ca7ca6f48430b30a2dfe863e0f95
data/README.md ADDED
@@ -0,0 +1,281 @@
1
+ # Kaiser
2
+
3
+ Welcome to Kaiser! Kaiser will mind-control all your monsters and make them even more effective.
4
+
5
+ Kaiser lets you define how an application starts, so trying out a web application simply reduces to a `kaiser up`
6
+
7
+ ## Installation (Traditional)
8
+
9
+ 1. Download and setup [Docker](https://www.docker.com/get-started)
10
+
11
+ 2. Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'kaiser', git: "https://github.com/degica/kaiser"
15
+ ```
16
+
17
+ 3. Execute:
18
+
19
+ ```$ bundle```
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install specific_install
24
+ $ gem specific_install -l https://github.com/degica/kaiser
25
+
26
+ ## Installation (Docker)
27
+
28
+ You can install Kaiser as a docker image on your machine too!
29
+
30
+ Simply clone the repo and run
31
+
32
+ ```
33
+ cd kaiser
34
+ docker build -t degica/kaiser .
35
+ ```
36
+
37
+ And then add the following line to your `.bashrc` or `.bash_profile`
38
+
39
+ ```
40
+ alias kaiser='docker run --rm -ti -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kaiser:/root/.kaiser -v `pwd`:`pwd` -e CONTEXT_DIR="`pwd`" degica/kaiser'
41
+ ```
42
+
43
+ Or if you use fish
44
+
45
+ ```
46
+ function kaiser
47
+ docker run --rm -ti -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kaiser:/root/.kaiser -v (pwd):(pwd) -e CONTEXT_DIR=(pwd) degica/kaiser $argv
48
+ end
49
+ ```
50
+
51
+ ## Usage
52
+
53
+ You'll need a Dockerfile and a Kaiserfile. The Kaiserfile should be placed in the project root directory, with contents like this:
54
+
55
+ ```ruby
56
+ # Example Kaiserfile for a Rails app
57
+
58
+ dockerfile "Dockerfile.kaiser"
59
+
60
+ db "mysql:5.6",
61
+ port: 3306,
62
+ data_dir: "/var/lib/mysql",
63
+ params: "-e MYSQL_ROOT_PASSWORD=test123",
64
+ commands: ""
65
+
66
+ app_params "-e DATABASE_URL=mysql2://root:test123@<%= db_container_name %>"
67
+
68
+ expose "9000"
69
+ db_reset_command "bin/rails db:reset"
70
+ ```
71
+
72
+ ```dockerfile
73
+ FROM ruby:alpine
74
+
75
+ COPY . /app
76
+ RUN apk update && apk add build-base
77
+ RUN gem install bundler
78
+ RUN bundle install
79
+
80
+ EXPOSE "3000"
81
+
82
+ CMD ["sh", "-c", "rails -b 0.0.0.0 -p 3000"]
83
+ ```
84
+
85
+ Then go to your repo's root folder and go
86
+
87
+ ```sh
88
+ bundle exec kaiser init myapp
89
+ bundle exec kaiser up
90
+ ```
91
+
92
+ Once its done, simply
93
+
94
+ ```sh
95
+ open http://myapp.lvh.me
96
+ ```
97
+
98
+ And enjoy previewing your app!
99
+
100
+ ### Alternative Kaiserfile
101
+
102
+ If you want change your dev environment for a project, but don't want to overwrite the project's Kaiserfile/Dockerfile,
103
+ you can use an alternative Kaiserfile.
104
+
105
+ An alternative Kaiserfile is located at `~/kaiserfiles/Kaiserfile.<app name>`,
106
+ where `<app name>` is replaced with the name you provided when calling `kaiser init`.
107
+
108
+ If Kaiser detects an alternative Kaiserfile, it will use it instead of the Project root one. Some things to watch out for:
109
+
110
+ - Of course, your app may behave differently if you change your environment from the project's default.
111
+ - 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.
112
+ - If the project's Kaiserfile or Dockerfile changes, you'll have to update your custom ones manually.
113
+
114
+ ### Debugging
115
+
116
+ You can also debug by going
117
+
118
+ ```sh
119
+ bundle exec kaiser attach
120
+ ```
121
+
122
+ ### Run stuff in the container
123
+
124
+ You can also run stuff inside by going
125
+
126
+ ```sh
127
+ bundle exec kaiser login sh
128
+ ```
129
+
130
+ And you can do anything inside the container
131
+
132
+ ### Attach to the container
133
+
134
+ If you want to run with the container in the foreground simply go
135
+
136
+ ```sh
137
+ bundle exec kaiser attach
138
+ ```
139
+
140
+ 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.
141
+
142
+ ```sh
143
+ bundle exec kaiser attach nano /etc/hosts
144
+ ```
145
+
146
+ ### Save database state
147
+
148
+ ```sh
149
+ bundle exec kaiser db_save customer_setup
150
+ ```
151
+
152
+ You can also save your database state to a file in your current dir:
153
+
154
+ ```sh
155
+ bundle exec kaiser db_save ./my_setup.dbimage
156
+ ```
157
+
158
+ ### Load database state
159
+
160
+ ```sh
161
+ bundle exec kaiser db_load customer_setup
162
+ ```
163
+
164
+ You can load a previously saved database file that you have
165
+
166
+ ```sh
167
+ bundle exec kaiser db_load ./my_setup.dbimage
168
+ ```
169
+
170
+ ### Get ports
171
+
172
+ Kaiser decides what ports to use on the host. To know them simply go
173
+
174
+ ```sh
175
+ bundle exec kaiser show ports
176
+ ```
177
+
178
+ ### Curious?
179
+
180
+ You can see what Kaiser is doing under the hood with the `-v` flag:
181
+
182
+ ```sh
183
+ bundle exec kaiser -v db_reset
184
+ ```
185
+
186
+ ## Reverse proxy
187
+
188
+ Why does it magically work?
189
+
190
+ 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.
191
+
192
+ [Read more about lvh.me](https://nickjanetakis.com/blog/ngrok-lvhme-nipio-a-trilogy-for-local-development-and-testing#lvh-me)
193
+
194
+ #### HTTPS
195
+
196
+ 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!)
197
+
198
+ It is easy to do this: Simply run
199
+
200
+ ```sh
201
+ kaiser set cert-folder /home/me/my-certificate-folder
202
+ ```
203
+
204
+ As preparation you need to generate [HTTPS certificates](https://gist.github.com/dagjaneiro/dc1e26d87e745b47c4e2596f6b54022c). You should have the following files:
205
+
206
+ ```
207
+ /home/me/my-certificate-folder/lvh.me.crt
208
+ /home/me/my-certificate-folder/lvh.me.key
209
+ /home/me/my-certificate-folder/lvh.me.chain.pem
210
+ ```
211
+
212
+ Hint: you can create the `.chain.pem` file by going
213
+
214
+ ```
215
+ cat lvh.me.crt >> lvh.me.key
216
+ cat lvh.me.crt >> lvh.me.crt
217
+ ```
218
+
219
+ Remember to trust your certificates! Otherwise your browser will give you an error (if it isn't dodgy).
220
+
221
+ If you and your colleagues all want to sign using the same certificates, simply put the certificates on a webserver and go:
222
+
223
+ ```sh
224
+ kaiser set cert-url https://internal-site.com/dev-certificates
225
+ ```
226
+
227
+ and Kaiser will look for certificates at:
228
+
229
+ ```
230
+ https://internal-site.com/dev-certificates/lvh.me.crt
231
+ https://internal-site.com/dev-certificates/lvh.me.key
232
+ https://internal-site.com/dev-certificates/lvh.me.chain.pem
233
+ ```
234
+
235
+ #### HTTP/HTTPS Your own domain
236
+
237
+ 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:
238
+
239
+ ```sh
240
+ kaiser set http-suffix local.aweso.me
241
+ ```
242
+
243
+ And your apps will be all `envname.local.aweso.me`
244
+
245
+ #### If you change these settings
246
+
247
+ You will need to run
248
+
249
+ ```sh
250
+ kaiser shutdown
251
+ ```
252
+
253
+ And run
254
+
255
+ ```sh
256
+ kaiser up
257
+ ```
258
+
259
+ Again for changes to take effect.
260
+
261
+ ## Development
262
+
263
+ After checking out the repo, run `bundle install` to install dependencies. Then, run `rake spec` to run the tests.
264
+
265
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
266
+
267
+ ## Contributing
268
+
269
+ Bug reports and pull requests are welcome on GitHub at https://github.com/degica/kaiser. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
270
+
271
+ ## License
272
+
273
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
274
+
275
+ ## Code of Conduct
276
+
277
+ Everyone interacting in the Kaiser project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/degica/kaiser/blob/master/CODE_OF_CONDUCT.md).
278
+
279
+ ## Contributors
280
+
281
+ - Guga Katsiashvili (provided the rubygem)
data/exe/kaiser ADDED
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'optimist'
5
+ require 'fileutils'
6
+ require 'yaml'
7
+ require 'json'
8
+ require 'pty'
9
+ require 'erb'
10
+
11
+ require 'kaiser'
12
+
13
+ sub_command_strings = Kaiser::SUB_COMMANDS.keys.map(&:to_s)
14
+
15
+ Kaiser::SUB_COMMANDS.each { |k, v| Kaiser::Cli.register(k, v) }
16
+
17
+ # It was difficult to allow global arguments like -v and -q to be typed both before and after cmds
18
+ # and still support `kaiser -h` for full help messages and `kaiser subcmd -h` for focused messages.
19
+ # Putting the global options in an array, using an Optimist::Parser and basically everything up to
20
+ # the 'end parser hacks' comment are all hacks to marry the above two behaviours.
21
+
22
+ global_opts = [
23
+ [:verbose, "Show Kaiser's debug output", short: '-v'],
24
+ [:quiet, 'Suppress all output', short: '-q']
25
+ ]
26
+
27
+ parser = Optimist::Parser.new do
28
+ version "Kaiser v#{Kaiser::VERSION}"
29
+
30
+ banner <<~BANNER
31
+ #{version}
32
+
33
+ Kaiser is a tool to make development a lot easier by defining how an application starts using a \`Kaiserfile\` in the source code's root directory.
34
+
35
+ Prerequisites
36
+ =============
37
+
38
+ Install docker on your system and make sure the current user has all the rights required to spin up docker containers.
39
+
40
+ Usage
41
+ =====
42
+
43
+ For typical usage you'll want to do the following three commands.
44
+
45
+ \`\`\`
46
+ kaiser init ENV_NAME
47
+ kaiser up
48
+ kaiser attach
49
+ \`\`\`
50
+
51
+ This will boot up your application in docker and bind mount your local source directory so you can start doing development. Happy coding!
52
+
53
+ If any of these commands are giving you trouble, please run them with the \`-v\` flag set. They will show you what exactly is happening so you can debug.
54
+
55
+ Subcommands
56
+ ===========
57
+
58
+ - #{Kaiser::SUB_COMMANDS.keys.join("\n- ")}
59
+
60
+ Type \`SUB_COMMAND -h\` for help with specific subcommands.
61
+
62
+ Global Parameters
63
+ =================
64
+ BANNER
65
+
66
+ global_opts.each { |o| opt(*o) }
67
+ end
68
+
69
+ commands = sub_command_strings & ARGV
70
+
71
+ if commands.empty?
72
+ Optimist.with_standard_exception_handling parser do
73
+ raise Optimist::HelpNeeded
74
+ end
75
+ end
76
+
77
+ cmd = commands.first
78
+ ## end parser hacks ##
79
+
80
+ begin
81
+ Kaiser::Cli.run_command(:"#{cmd}", global_opts)
82
+ rescue Kaiser::Error => e
83
+ puts ''
84
+ puts e.message
85
+ end
86
+
87
+ puts ''
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kaiser
4
+ # Prints properly after a dotter prints
5
+ class AfterDotter
6
+ def initialize(channel: $stderr, dotter:)
7
+ @channel = channel
8
+ @dotter = dotter
9
+ end
10
+
11
+ def puts(value)
12
+ if @dotter.dotted
13
+ @dotter.dotted = false
14
+ @channel.puts ''
15
+ end
16
+ @channel.puts(value)
17
+ end
18
+
19
+ def flush
20
+ @channel.flush
21
+ end
22
+ end
23
+ end