devkitkat 0.1.1 → 0.1.2

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: e730a451bae542a99bfa35ea7f4f5c0eb3f65da04c1b6e686e3d8dce16770c07
4
- data.tar.gz: e865d0c254cff4b007b2680ef0e61f62fff9cd2b1dbddb2c53dde21b888f4016
3
+ metadata.gz: 1637e6c031dc94fed2e73fe7663b9363c844d4e03ed2366b60f73cc2c2b6caeb
4
+ data.tar.gz: cb76526b40ecef0262144353ad818259a9b420f067ac93bc047dac03688f165b
5
5
  SHA512:
6
- metadata.gz: 7f1f690b3a05189d32ba031d8f1b5d40b92a7ca9879af34142c45dc07565f50459e56f65cfa48b4b1368c768d27ebfd6d13c342af11663cd5893b42c696789c1
7
- data.tar.gz: f80a184c8992db158b4750d0c3421109f3ea0e74f51f94bb480e6e5b245cc8802998650b38cace5beb1cf0147b0bc68f71485ada2aedc8c446f52f3bf122b546
6
+ metadata.gz: 17e7a1f6465aee29d9c49a68535d51148a857c2d91b7585db753f8764fb4e8a95da973b15ddd50eb140fdca37226bb3c1dcb3103247c2692dbbe109cac1fefa2
7
+ data.tar.gz: 22c906e910232a9e18ac648027a9ad97e93157c3353cba02c0bbbcb2ed91b594a635b9db0c9616421ba922cb2b5135f293d67acd6f1b6ab7993b63844e6e525f
data/.gitlab-ci.yml CHANGED
@@ -1,25 +1,38 @@
1
- image: ruby:2.6
2
-
3
- services:
4
- - docker:19.03.1-dind
5
-
6
- variables:
7
- DOCKER_HOST: tcp://docker:2375
8
- DOCKER_TLS_CERTDIR: ""
9
-
10
1
  rspec:
11
2
  stage: test
12
- variables:
13
- LANG: C.UTF-8
14
- LC_ALL: C.UTF-8
3
+ tags:
4
+ - do-runner
15
5
  before_script:
16
- - apt-get update
17
- - apt-get install -y cmake docker.io
18
6
  - docker info
19
7
  - pwd
20
- script:
21
- - mkdir ../test
22
- - cp -a . ../test
23
- - cd ../test
8
+ - gem install bundler
24
9
  - bin/setup
10
+ script:
25
11
  - bundle exec rspec
12
+
13
+ # services:
14
+ # - docker:19.03.1-dind
15
+
16
+ # variables:
17
+ # DOCKER_HOST: tcp://docker:2375
18
+ # DOCKER_TLS_CERTDIR: ""
19
+
20
+ # rspec:
21
+ # stage: test
22
+ # tags:
23
+ # - do-runner
24
+ # variables:
25
+ # LANG: C.UTF-8
26
+ # LC_ALL: C.UTF-8
27
+ # before_script:
28
+ # - sudo apt-get update
29
+ # - apt-get install -y cmake docker.io
30
+ # - docker info
31
+ # - pwd
32
+ # - gem install bundler
33
+ # script:
34
+ # - mkdir ../test
35
+ # - cp -a . ../test
36
+ # - cd ../test
37
+ # - bin/setup
38
+ # - bundle exec rspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- devkitkat (0.1.0)
4
+ devkitkat (0.1.1)
5
5
  activesupport (~> 6.0.0)
6
6
  colorize (~> 0.8.1)
7
7
  docker-api (~> 1.34.2)
@@ -25,11 +25,11 @@ GEM
25
25
  excon (>= 0.47.0)
26
26
  multi_json
27
27
  excon (0.67.0)
28
- i18n (1.6.0)
28
+ i18n (1.7.0)
29
29
  concurrent-ruby (~> 1.0)
30
30
  method_source (0.9.2)
31
31
  minitest (5.12.2)
32
- multi_json (1.13.1)
32
+ multi_json (1.14.0)
33
33
  parallel (1.17.0)
34
34
  pry (0.12.2)
35
35
  coderay (~> 1.1.0)
@@ -56,7 +56,7 @@ GEM
56
56
  thread_safe (0.3.6)
57
57
  tzinfo (1.2.5)
58
58
  thread_safe (~> 0.1)
59
- zeitwerk (2.1.10)
59
+ zeitwerk (2.2.0)
60
60
 
61
61
  PLATFORMS
62
62
  ruby
data/README.md CHANGED
@@ -269,3 +269,8 @@ The gem is available as open source under the terms of the [MIT License](https:/
269
269
  ## Code of Conduct
270
270
 
271
271
  Everyone interacting in the Devkitkat project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/devkitkat/blob/master/CODE_OF_CONDUCT.md).
272
+
273
+ ## How to release a new version
274
+
275
+ 1. Update `Devkitkat::VERSION`
276
+ 1. Execute `bin/release`
data/bin/release ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ file_name=$(gem build devkitkat.gemspec | grep 'File:' | awk '{ print $2 }')
6
+ gem push ${file_name}
7
+ rm ${file_name}
@@ -4,9 +4,40 @@ module Devkitkat
4
4
 
5
5
  def initialize
6
6
  @options = {}
7
+ option_parser.parse!
7
8
 
8
- OptionParser.new do |opts|
9
+ @script, @target, *@args = ARGV
10
+
11
+ show_help if script == 'help'
12
+ end
13
+
14
+ def tty?
15
+ options[:tty]
16
+ end
17
+
18
+ def variables
19
+ options[:variables]
20
+ end
21
+
22
+ def tmp_dir
23
+ File.join(kit_root, 'tmp')
24
+ end
25
+
26
+ def create_tmp_dir
27
+ FileUtils.mkdir_p(tmp_dir)
28
+ end
29
+
30
+ def kit_root
31
+ Dir.pwd # TODO: root_path
32
+ end
33
+
34
+ private
35
+
36
+ def option_parser
37
+ @option_parser ||= OptionParser.new do |opts|
9
38
  opts.banner = "Usage: devkitkat <script> <target> [options]"
39
+ opts.separator ""
40
+ opts.separator "Options:"
10
41
 
11
42
  opts.on("-p", "--path PATH", "The root path of the .devkitkat.yml") do |v|
12
43
  options[:root_path] = v
@@ -37,29 +68,32 @@ module Devkitkat
37
68
  opts.on("-t", "--tty", "TTY mode. In this mode, log won't be emitted.") do |v|
38
69
  options[:tty] = v
39
70
  end
40
- end.parse!
41
-
42
- @script, @target, *@args = ARGV
43
- end
44
71
 
45
- def tty?
46
- options[:tty]
47
- end
48
-
49
- def variables
50
- options[:variables]
51
- end
72
+ opts.on("-v", "--version", "Show version") do |v|
73
+ puts Devkitkat::VERSION
74
+ exit
75
+ end
52
76
 
53
- def tmp_dir
54
- File.join(kit_root, 'tmp')
55
- end
77
+ opts.on("-h", "--help", "Show help") do |v|
78
+ show_help
79
+ end
56
80
 
57
- def create_tmp_dir
58
- FileUtils.mkdir_p(tmp_dir)
81
+ opts.separator ""
82
+ opts.separator "Commands:"
83
+ opts.separator "add-script - Add a script file"
84
+ opts.separator "add-example - Add an example file"
85
+ opts.separator "add-shared-script - Add s shared script"
86
+ opts.separator "clone - Clone repository"
87
+ opts.separator "pull - Pull latest source code"
88
+ opts.separator "clean - Clean the service dir"
89
+ opts.separator "poop - Poop"
90
+ opts.separator "help - Show help"
91
+ end
59
92
  end
60
93
 
61
- def kit_root
62
- Dir.pwd # TODO: root_path
94
+ def show_help
95
+ puts option_parser.help
96
+ exit
63
97
  end
64
98
  end
65
99
  end
@@ -3,7 +3,7 @@ module Devkitkat
3
3
  DEVKITKAT_FILE_NAME = '.devkitkat.yml'
4
4
  HIDDEN_SERVICES = %w[system]
5
5
  DEFAULT_APPLICATION_NAME = 'devkitkat'
6
- DEFAULT_IMAGE = 'ubuntu:18.04'
6
+ DEFAULT_IMAGE = 'registry.gitlab.com/dosuken123/thin-gdk/thin-gdk-monolith:master'
7
7
 
8
8
  attr_reader :devkitkat_yml, :kit_root
9
9
 
@@ -4,17 +4,22 @@ require 'docker'
4
4
  module Devkitkat
5
5
  class Executor
6
6
  class Docker
7
+ PreparationError = Class.new(StandardError)
8
+
7
9
  attr_reader :service, :script_file
8
10
 
9
11
  delegate :config, :command, to: :service
10
12
 
13
+ ROOT_IN_CONTAINER = '/devkitkat'
14
+
11
15
  def initialize(service)
12
16
  @service = service
13
17
  end
14
18
 
15
19
  def prepare
16
- pull_image
20
+ pull_image unless image_exist?
17
21
  start_container
22
+ sync_user_with_host
18
23
  end
19
24
 
20
25
  def cleanup
@@ -27,25 +32,25 @@ module Devkitkat
27
32
  rewrite_root_path!
28
33
  new_path = script_path_in_container
29
34
 
30
- container.exec([new_path])
35
+ exec([new_path], user: user_name)
31
36
  end
32
37
 
33
38
  private
34
39
 
35
40
  def rewrite_root_path!
36
41
  content = File.read(script_file)
37
- new_content = content.gsub(command.kit_root, root_in_container)
42
+ new_content = content.gsub(command.kit_root, ROOT_IN_CONTAINER)
38
43
  File.write(script_file, new_content)
39
44
  end
40
45
 
41
46
  def script_path_in_container
42
47
  relative_path = script_file.delete_prefix(command.kit_root)
43
- File.join(root_in_container, relative_path)
48
+ File.join(ROOT_IN_CONTAINER, relative_path)
44
49
  end
45
50
 
46
51
  def log_path_in_container
47
52
  relative_path = service.log_path.delete_prefix(command.kit_root)
48
- File.join(root_in_container, relative_path)
53
+ File.join(ROOT_IN_CONTAINER, relative_path)
49
54
  end
50
55
 
51
56
  def docker_image
@@ -57,13 +62,12 @@ module Devkitkat
57
62
  end
58
63
 
59
64
  def container_parameter
60
- # TODO: Speicfy users otherwise the created files are owned by root
61
65
  params = {
62
66
  'Cmd' => %w[tail -f],
63
67
  'Image' => docker_image,
64
68
  'name' => service.container_name,
65
69
  'HostConfig' => {
66
- 'Binds' => ["#{command.kit_root}:#{root_in_container}"]
70
+ 'Binds' => ["#{command.kit_root}:#{ROOT_IN_CONTAINER}"]
67
71
  }
68
72
  }
69
73
 
@@ -81,21 +85,65 @@ module Devkitkat
81
85
  params
82
86
  end
83
87
 
84
- def root_in_container
85
- "/devkitkat"
86
- end
87
-
88
88
  def pull_image
89
+ puts "Pulling image #{docker_image}..."
89
90
  ::Docker::Image.create('fromImage' => docker_image)
91
+ puts "Pulled image #{docker_image}..."
92
+ end
93
+
94
+ def image_exist?
95
+ ::Docker::Image.get(docker_image)
96
+ rescue
97
+ false
90
98
  end
91
99
 
92
100
  def start_container
93
101
  container.start
94
102
  end
103
+
104
+ def user_name
105
+ 'devkitkat'
106
+ end
107
+
108
+ def group_id
109
+ @group_id ||= `id -u`
110
+ end
111
+
112
+ def user_id
113
+ @user_id ||= `id -g`
114
+ end
115
+
116
+ def exec(cmds, params = {})
117
+ stdout_messages, stderr_messages, exit_code =
118
+ container.exec(cmds, params)
119
+
120
+ exit_code == 0 ? true : false
121
+ end
122
+
123
+ def exec!(cmds, params = {})
124
+ unless exec(cmds, params)
125
+ raise PreparationError, "Failed to execute command in container. cmds: #{cmds}"
126
+ end
127
+ end
128
+
129
+ def sync_user_with_host
130
+ exec!(['addgroup', '--gid', group_id, user_name])
131
+
132
+ exec!(['adduser',
133
+ '--uid', user_id,
134
+ '--gid', group_id,
135
+ '--shell', '/bin/bash',
136
+ '--home', ROOT_IN_CONTAINER,
137
+ '--gecos', '',
138
+ '--disabled-password',
139
+ user_name])
140
+
141
+ exec!(['chown', '-R', "#{user_name}:#{user_name}", ROOT_IN_CONTAINER])
142
+ end
95
143
 
96
144
  def stop_container
97
- container.stop
98
- container.remove
145
+ # container.stop
146
+ container.remove(force: true)
99
147
  end
100
148
  end
101
149
  end
@@ -12,15 +12,14 @@ module Devkitkat
12
12
  raise ArgumentError, 'TTY mode accepts only one service'
13
13
  end
14
14
 
15
- log_paths = target_services.map(&:log_path)
16
- puts %Q{See the log at \n#{log_paths.join("\n")}}
17
-
18
15
  if target_services.count == 1
19
16
  # If the target is only one, it could be console access (TTY)
20
17
  # so we can't run in parallel.
21
18
  service = target_services.first
22
19
  execute_for(service)
23
20
  else
21
+ print_log_paths
22
+
24
23
  Parallel.map(target_services, progress: 'Executing', in_processes: 8) do |service|
25
24
  execute_for(service)
26
25
  end
@@ -42,5 +41,10 @@ module Devkitkat
42
41
  @target_services ||= config.resolve!(command.target, exclude: command.options[:exclude])
43
42
  .map { |name| Service.new(name, config, command) }
44
43
  end
44
+
45
+ def print_log_paths
46
+ log_paths = target_services.map(&:log_path)
47
+ puts %Q{See the log at \n#{log_paths.join("\n")}}
48
+ end
45
49
  end
46
50
  end
@@ -1,3 +1,3 @@
1
1
  module Devkitkat
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
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.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shinya Maeda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-10 00:00:00.000000000 Z
11
+ date: 2019-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -184,6 +184,7 @@ files:
184
184
  - bin/console
185
185
  - bin/devkitkat
186
186
  - bin/fast_rspec
187
+ - bin/release
187
188
  - bin/setup
188
189
  - devkitkat.gemspec
189
190
  - docs/READ.md