kaiser 0.7.0 → 0.8.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: 92b3034ab17814ed926d2b9168806132dc548783becdd3b9037b2fefa55b1c9d
4
- data.tar.gz: 001e9c5e10b094b349d0a65527da079d483219081e7e8a6e0f2ae0731a2b1d96
3
+ metadata.gz: 54e276a77032f484d216acc213a7c9157c8d5afd3c241c95c81c68845cd94dd7
4
+ data.tar.gz: cd24e7b599320b2c6e6ef94bc2c0fcb27f02f82fa6bbe6fda7919af2de5ce862
5
5
  SHA512:
6
- metadata.gz: e4e79a8b16f93a34587106cf800d098bbd88a0f26e3a0725fefc01232e2d135a8010c7f728629bf378702070a95c11a437ec7a4486f7c1e881ffc029158a7a61
7
- data.tar.gz: 5d4bf821446f25df5f3d6dbb1a30ba0682bcdc7620b60b9acc03c19afd95f919f99da242b6afa873087928d5c7a45522c400125b0407696485e9bcbe6fcaf7c9
6
+ metadata.gz: d24d16515b2832b274adeeda21ecec02295394ad7b093874832cf7af154693fb5a8d0a7975e053fe7ecc0b24b380b8ff4864af1cd0acd95b8cf6343b273e29eb
7
+ data.tar.gz: e0aa642762fc2b3af586fbb1967c829d959854c645a282e73869713b3385279a2b891baade25f474b547c6d302052cf16450b9ddc08366722d740bf1530db5db
data/README.md CHANGED
@@ -38,14 +38,14 @@ docker build -t degica/kaiser .
38
38
  And then add the following line to your `.bashrc` or `.bash_profile`
39
39
 
40
40
  ```
41
- 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
+ alias kaiser='docker run --pull=always --rm -ti -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kaiser:/root/.kaiser -v `pwd`:`pwd` -e CONTEXT_DIR="`pwd`" degicadev/kaiser'
42
42
  ```
43
43
 
44
44
  Or if you use fish
45
45
 
46
46
  ```
47
47
  function kaiser
48
- 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
+ docker run --pull=always --rm -ti -v /var/run/docker.sock:/var/run/docker.sock -v $HOME/.kaiser:/root/.kaiser -v (pwd):(pwd) -e CONTEXT_DIR=(pwd) degicadev/kaiser $argv
49
49
  end
50
50
  ```
51
51
 
data/exe/kaiser CHANGED
@@ -5,7 +5,6 @@ require 'optimist'
5
5
  require 'fileutils'
6
6
  require 'yaml'
7
7
  require 'json'
8
- require 'pty'
9
8
  require 'erb'
10
9
 
11
10
  require 'kaiser'
data/lib/kaiser/cli.rb CHANGED
@@ -110,11 +110,7 @@ module Kaiser
110
110
  services.each do |service|
111
111
  Config.info_out.puts "Starting service: #{service.name}"
112
112
  run_if_dead(
113
- service.shared_name,
114
- "docker run -d
115
- --name #{service.shared_name}
116
- --network #{Config.config[:networkname]}
117
- #{service.image}"
113
+ service.shared_name, service.start_docker_command
118
114
  )
119
115
  end
120
116
  end
@@ -246,6 +242,10 @@ module Kaiser
246
242
  end
247
243
 
248
244
  def attach_app
245
+ start_services
246
+
247
+ puts 'Attaching to app...'
248
+
249
249
  cmd = (ARGV || []).join(' ')
250
250
  killrm app_container_name
251
251
 
@@ -265,6 +265,8 @@ module Kaiser
265
265
  #{app_params}
266
266
  kaiser:#{envname}-#{current_branch} #{cmd}".tr("\n", ' ')
267
267
 
268
+ stop_services
269
+
268
270
  Config.out.puts 'Cleaning up...'
269
271
  end
270
272
 
@@ -45,7 +45,10 @@ module Kaiser
45
45
  Config.info_out.puts 'Setting up application'
46
46
  File.write(tmp_dockerfile_name, docker_file_contents)
47
47
 
48
- CommandRunner.run! Config.out, build_cmd.join("\n\t")
48
+ CommandRunner.run! Config.out, build_cmd.join("\n\t"), env_vars: {
49
+ 'DOCKER_BUILDKIT' => '1',
50
+ 'BUILDKIT_PROGRESS' => 'plain'
51
+ }
49
52
  FileUtils.rm(tmp_dockerfile_name)
50
53
  end
51
54
  end
@@ -1,24 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'pty'
3
4
  require 'English'
4
5
 
5
- # This is the command runner
6
6
  module Kaiser
7
- # Make running easy
7
+ # This is the command runner
8
+ # it abstracts away the complicated syntax required to deal with
9
+ # PTY and to pass the lines programmatically to the host application
10
+ # as well as to capture the return code at the end.
8
11
  class CommandRunner
9
- def self.run(out, cmd, &block)
12
+ def self.run(out, cmd, env_vars: {}, &block)
10
13
  out.puts "> #{cmd}"
11
- CommandRunner.new(out, cmd).run_command(&block)
14
+ CommandRunner.new(out, cmd, env_vars).run_command(&block)
12
15
  end
13
16
 
14
- def self.run!(out, cmd, &block)
15
- status = run(out, cmd, &block)
17
+ def self.run!(out, cmd, env_vars: {}, &block)
18
+ status = run(out, cmd, env_vars: env_vars, &block)
16
19
  raise Kaiser::CmdError.new(cmd, status) if status.to_s != '0'
17
20
  end
18
21
 
19
- def initialize(out, cmd)
22
+ def initialize(out, cmd, env_vars)
20
23
  @out = out
21
24
  @cmd = cmd.tr "\n", ' '
25
+ @env_vars = env_vars
22
26
  end
23
27
 
24
28
  def print_and_return_status(status = 0)
@@ -38,7 +42,7 @@ module Kaiser
38
42
  end
39
43
 
40
44
  def run_command(&block)
41
- PTY.spawn("#{@cmd} 2>&1") do |stdout, _stdin, pid|
45
+ PTY.spawn(@env_vars, "#{@cmd} 2>&1") do |stdout, _stdin, pid|
42
46
  print_lines(stdout, &block)
43
47
  Process.wait(pid)
44
48
  end
@@ -102,10 +102,20 @@ module Kaiser
102
102
  @server_type = value
103
103
  end
104
104
 
105
- def service(name, image: name)
105
+ def service(name,
106
+ image: name,
107
+ command: nil,
108
+ binds: {},
109
+ env: {})
110
+
106
111
  raise "duplicate service #{name.inspect}" if @services.key?(name)
107
112
 
108
- @services[name] = { image: image }
113
+ @services[name] = {
114
+ image: image,
115
+ command: command,
116
+ binds: binds,
117
+ env: env
118
+ }
109
119
  end
110
120
  end
111
121
  end
@@ -18,5 +18,43 @@ module Kaiser
18
18
  def image
19
19
  @service_info[:image]
20
20
  end
21
+
22
+ def command
23
+ @service_info[:command].to_s
24
+ end
25
+
26
+ def binds
27
+ @service_info[:binds] || {}
28
+ end
29
+
30
+ def env
31
+ @service_info[:env] || {}
32
+ end
33
+
34
+ def start_docker_command
35
+ envstring = env.map do |k, v|
36
+ "-e #{k}=#{v}"
37
+ end.join(' ')
38
+
39
+ bindstring = binds.map do |k, v|
40
+ "-v #{k}:#{v}"
41
+ end.join(' ')
42
+
43
+ commandstring = command
44
+
45
+ cmd_array = [
46
+ 'docker run -d',
47
+ "--name #{shared_name}",
48
+ "--network #{Config.config[:networkname]}",
49
+ envstring,
50
+ bindstring,
51
+ image,
52
+ commandstring
53
+ ]
54
+
55
+ cmd_array.filter! { |x| !x.empty? }
56
+
57
+ cmd_array.join(' ')
58
+ end
21
59
  end
22
60
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kaiser
4
- VERSION = '0.7.0'
4
+ VERSION = '0.8.0'
5
5
  end
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.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Siaw
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-08 00:00:00.000000000 Z
11
+ date: 2024-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport