devkitkat 0.1.26 → 0.1.29

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
2
  SHA256:
3
- metadata.gz: bc1ec65b940b53a2d04d473ed109dbd6b97256f09ac270f2b59edb607201b310
4
- data.tar.gz: c14fa3b11c1fe1fd4e33e92fece3bfa9e5eaf3ad233cb34cf0e5b8dfe2783a10
3
+ metadata.gz: f91fde9edf9ce28487edc62750fa05a2b28eb47b873f210d604253228c54cdf8
4
+ data.tar.gz: 723f2f178357b49750fc8b16e04f648caf345a151ca8e0b393ae574237a78c12
5
5
  SHA512:
6
- metadata.gz: b331ae89d8c5cf523fe51b0b4cc36bad069b7f5750e7b8413ec4f41896ebcded43f680e42dfff6aa44bf4755aabf9d459e1f0c4c1e1243b80977baf787c06750
7
- data.tar.gz: 78dcc4f8d93ddb3727c6f9ff254b9a4dd2ef406f7c95f07ae7bd6a216f622dc08b748811f3be5eec5d8822c2570375762d1f99063be2199589682cdc5ace505f
6
+ metadata.gz: '0679b7c01e774727548d8628b34ac3263c398e32d7b1457d1cfdc43f7d045391afa1d936e97b61aaccd606c0e3b9f5786bbddaad3901eb6c80b1756b2fff1502'
7
+ data.tar.gz: b74a7d2df3304e3fbc5eb825c054590ee61e53b217e9a30da7df4da0073a8d9b95fd77affb808e70989e605f4ffa06935c9f7834b241275593036eab8c860ed8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- devkitkat (0.1.25)
4
+ devkitkat (0.1.28)
5
5
  activesupport (~> 6.0.0)
6
6
  colorize (~> 0.8.1)
7
7
  docker-api (~> 1.34.2)
data/README.md CHANGED
@@ -46,6 +46,20 @@ download/prepare services. These are available keys.
46
46
 
47
47
  There are pre-occupied special keys, please do not use these keys in your config file: `services:system`, `services:self`
48
48
 
49
+ ### `machine:` key
50
+
51
+ |Key |Type |Required|Default|Description|
52
+ |--- |--- |--- |---|---|
53
+ |`machine:` |Hash |No |-|The machine to run the application|
54
+ |`machine:driver` |String |No |-|The driver name, one of `none` or `docker`. Default is `none`.|
55
+ |`machine:location` |String |No |-|The machine location, one of `local` or `remote`. Default is `local`.|
56
+ |`machine:image` |String |No |-|The docker image used as the machine image.|
57
+ |`machine:extra_hosts` |Array<String>|No |-|Extra hosts to be added to `/etc/hosts` in the machine|
58
+ |`machine:network_mode` |String |No |-|Docker Network Mode, one of `bridge`, `host`.|
59
+ |`machine:extra_write_accesses` |Array<String>|No |-|Extra write access to each service. By default, a service mounts only own directory as read-write and mounts the other service directories as read-only volume. To add extra write access, you specify `'<service-name>:to:<service-name>'`|
60
+
61
+
62
+
49
63
  ## Sample `.devkitkat.yml` that runs services in local environment
50
64
 
51
65
  ```yaml
@@ -60,7 +74,9 @@ services:
60
74
  ## Sample `.devkitkat.yml` that runs services in docker containers
61
75
 
62
76
  ```yaml
63
- image: ruby:2.6
77
+ machine:
78
+ driver: docker
79
+ image: your-dev-machine-image:latest
64
80
 
65
81
  services:
66
82
  web:
@@ -46,6 +46,10 @@ module Devkitkat
46
46
  opts.separator ""
47
47
  opts.separator "Options:"
48
48
 
49
+ opts.on("-d", "--driver", "Machine Driver") do |v|
50
+ options[:driver] = v
51
+ end
52
+
49
53
  opts.on("-d", "--debug", "Debug mode") do |v|
50
54
  options[:debug] = v
51
55
  end
@@ -94,6 +98,7 @@ module Devkitkat
94
98
  opts.separator "clean - Clean the service dir"
95
99
  opts.separator "poop - Poop"
96
100
  opts.separator "show-variables - Show all variables via 'export' command"
101
+ opts.separator "remove-containers - Remove all related containers"
97
102
  end
98
103
  end
99
104
 
@@ -59,5 +59,9 @@ module Devkitkat
59
59
 
60
60
  File.join(script_dir, 'shared')
61
61
  end
62
+
63
+ def machine_driver
64
+ config.service_hash(name).dig(:machine, :driver)
65
+ end
62
66
  end
63
67
  end
@@ -84,7 +84,8 @@ module Devkitkat
84
84
  'Image' => image,
85
85
  'name' => name,
86
86
  'HostConfig' => {
87
- 'Binds' => all_mounts
87
+ 'Binds' => all_mounts,
88
+ 'Privileged' => true
88
89
  }
89
90
  }
90
91
 
@@ -121,7 +122,7 @@ module Devkitkat
121
122
  else
122
123
  "#{service.dir}:#{ROOT_IN_CONTAINER}/services/#{service.name}:ro"
123
124
  end
124
- end
125
+ end.append('/var/run/docker.sock:/var/run/docker.sock')
125
126
  end
126
127
 
127
128
  def allowed_by_extra_write_accesses?(service)
@@ -162,6 +163,7 @@ module Devkitkat
162
163
 
163
164
  prepare!(['chown', "#{user_name}:#{user_name}", ROOT_IN_CONTAINER])
164
165
  prepare!(['chown', '-R', "#{user_name}:#{user_name}", "#{ROOT_IN_CONTAINER}/services/#{service.name}"])
166
+ prepare!(['usermod', '-aG', 'docker', user_name])
165
167
  end
166
168
 
167
169
  def prepare!(cmds, params = {})
@@ -40,9 +40,11 @@ module Devkitkat
40
40
  if File.exist?(service.script_path)
41
41
  scripter.write(%Q{echo "INFO: This script is a custom script."})
42
42
  scripter.write(service.script_path)
43
+ @machine_driver = command.options[:driver]
43
44
  elsif predefined_command_available?
44
45
  scripter.write(%Q{echo "INFO: This script is a predefined script in devkitkat."})
45
46
  scripter.write(predefined_command.to_script)
47
+ @machine_driver = predefined_command.machine_driver
46
48
  else
47
49
  false
48
50
  end
@@ -51,6 +53,7 @@ module Devkitkat
51
53
  end
52
54
 
53
55
  def execute!
56
+ driver = get_driver_klass.new(service)
54
57
  driver.prepare
55
58
 
56
59
  driver.execute(scripter.file_path).tap do |result|
@@ -60,10 +63,6 @@ module Devkitkat
60
63
  driver.cleanup
61
64
  end
62
65
 
63
- def driver
64
- @driver ||= driver_klass.new(service)
65
- end
66
-
67
66
  def scripter
68
67
  @scripter ||= Scripter.new(service)
69
68
  end
@@ -80,8 +79,10 @@ module Devkitkat
80
79
  @predefined_command ||= predefined_command_klass.new(service)
81
80
  end
82
81
 
83
- def driver_klass
84
- Object.const_get("Devkitkat::Service::Driver::#{config.machine_driver.camelize}")
82
+ def get_driver_klass
83
+ driver = @machine_driver || service.machine_driver || config.machine_driver
84
+
85
+ Object.const_get("Devkitkat::Service::Driver::#{driver.camelize}")
85
86
  end
86
87
 
87
88
  def predefined_command_klass
@@ -18,9 +18,12 @@ module Devkitkat
18
18
  def predefined_global_variables
19
19
  variables = []
20
20
  variables << "export DK_ROOT_DIR=#{command.kit_root}"
21
+ variables << "export DK_COMMAND_TARGET=#{command.target}"
21
22
  variables << "export DK_MACHINE_DRIVER=#{config.machine_driver.to_s}"
22
23
  variables << "export DK_MACHINE_LOCATION=#{config.machine_location.to_s}"
23
24
  variables << "export DK_MACHINE_IMAGE=#{config.machine_image.to_s}"
25
+ variables << "export DK_MACHINE_EXTRA_HOSTS=#{config.machine_extra_hosts.join(',').to_s}"
26
+ variables << "export DK_MACHINE_NETWORK_MODE=#{config.machine_network_mode.to_s}"
24
27
  variables << "export DK_APPLICATION=#{config.application.to_s}"
25
28
  variables
26
29
  end
@@ -36,6 +39,8 @@ module Devkitkat
36
39
  end
37
40
 
38
41
  config.service_hash(service.name).each do |key, value|
42
+ next if value.is_a?(Hash)
43
+
39
44
  variables << "export DK_#{service.name.upcase}_#{key.upcase}=#{value}"
40
45
  end
41
46
 
@@ -65,6 +70,8 @@ module Devkitkat
65
70
 
66
71
  def config_service_variables
67
72
  config.service_hash(service.name).map do |key, value|
73
+ next if value.is_a?(Hash)
74
+
68
75
  "export #{key}=#{value}"
69
76
  end
70
77
  end
@@ -26,6 +26,10 @@ fi
26
26
  def available?
27
27
  true
28
28
  end
29
+
30
+ def machine_driver
31
+ 'none'
32
+ end
29
33
  end
30
34
  end
31
35
  end
@@ -23,6 +23,10 @@ EOL
23
23
  def file_path
24
24
  File.join(command.kit_root, '.gitignore')
25
25
  end
26
+
27
+ def machine_driver
28
+ 'none'
29
+ end
26
30
  end
27
31
  end
28
32
  end
@@ -29,6 +29,10 @@ fi
29
29
  def available?
30
30
  true
31
31
  end
32
+
33
+ def machine_driver
34
+ 'none'
35
+ end
32
36
  end
33
37
  end
34
38
  end
@@ -15,6 +15,10 @@ module Devkitkat
15
15
  def available?
16
16
  service.system? && !File.exist?(service.shared_script_path)
17
17
  end
18
+
19
+ def machine_driver
20
+ 'none'
21
+ end
18
22
  end
19
23
  end
20
24
  end
@@ -11,6 +11,10 @@ module Devkitkat
11
11
  def available?
12
12
  raise NotImplementedError
13
13
  end
14
+
15
+ def machine_driver
16
+ nil
17
+ end
14
18
  end
15
19
  end
16
20
  end
@@ -16,6 +16,10 @@ module Devkitkat
16
16
  def available?
17
17
  true
18
18
  end
19
+
20
+ def machine_driver
21
+ 'none'
22
+ end
19
23
  end
20
24
  end
21
25
  end
@@ -19,6 +19,10 @@ module Devkitkat
19
19
  def available?
20
20
  service.repo_defined?
21
21
  end
22
+
23
+ def machine_driver
24
+ 'none'
25
+ end
22
26
  end
23
27
  end
24
28
  end
@@ -13,6 +13,10 @@ module Devkitkat
13
13
  def available?
14
14
  service.repo_defined?
15
15
  end
16
+
17
+ def machine_driver
18
+ 'none'
19
+ end
16
20
  end
17
21
  end
18
22
  end
@@ -0,0 +1,21 @@
1
+ module Devkitkat
2
+ class Service
3
+ class PredefinedCommand
4
+ class RemoveContainers < Base
5
+ def to_script
6
+ <<~EOS
7
+ docker rm -f $(docker ps -a -f name=#{config.application}-* -q)
8
+ EOS
9
+ end
10
+
11
+ def available?
12
+ true
13
+ end
14
+
15
+ def machine_driver
16
+ 'none'
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -11,6 +11,10 @@ module Devkitkat
11
11
  def available?
12
12
  true
13
13
  end
14
+
15
+ def machine_driver
16
+ 'none'
17
+ end
14
18
  end
15
19
  end
16
20
  end
@@ -1,3 +1,3 @@
1
1
  module Devkitkat
2
- VERSION = "0.1.26"
2
+ VERSION = "0.1.29"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devkitkat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.26
4
+ version: 0.1.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shinya Maeda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-25 00:00:00.000000000 Z
11
+ date: 2020-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -228,6 +228,7 @@ files:
228
228
  - lib/devkitkat/service/predefined_command/poop.rb
229
229
  - lib/devkitkat/service/predefined_command/pull.rb
230
230
  - lib/devkitkat/service/predefined_command/reconfigure.rb
231
+ - lib/devkitkat/service/predefined_command/remove_containers.rb
231
232
  - lib/devkitkat/service/predefined_command/show_variables.rb
232
233
  - lib/devkitkat/version.rb
233
234
  homepage: https://gitlab.com/dosuken123/devkitkat