devkitkat 0.1.21 → 0.1.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +13 -11
- data/README.md +2 -2
- data/bin/devkitkat +1 -1
- data/devkitkat.gemspec +2 -1
- data/lib/devkitkat/command.rb +6 -8
- data/lib/devkitkat/config.rb +33 -20
- data/lib/devkitkat/processor.rb +48 -0
- data/lib/devkitkat/service/concerns/service_initializer.rb +17 -0
- data/lib/devkitkat/service/driver/base.rb +23 -0
- data/lib/devkitkat/service/driver/docker/container.rb +163 -0
- data/lib/devkitkat/service/driver/docker/image.rb +33 -0
- data/lib/devkitkat/service/driver/docker.rb +45 -0
- data/lib/devkitkat/service/driver/none.rb +19 -0
- data/lib/devkitkat/service/executor/logger.rb +22 -0
- data/lib/devkitkat/service/executor/scripter.rb +48 -0
- data/lib/devkitkat/service/executor/variables.rb +82 -0
- data/lib/devkitkat/service/executor.rb +102 -0
- data/lib/devkitkat/service/predefined_command/add_example.rb +33 -0
- data/lib/devkitkat/service/predefined_command/add_git_ignore.rb +29 -0
- data/lib/devkitkat/service/predefined_command/add_script.rb +35 -0
- data/lib/devkitkat/service/predefined_command/add_shared_script.rb +21 -0
- data/lib/devkitkat/service/predefined_command/base.rb +17 -0
- data/lib/devkitkat/service/predefined_command/clean.rb +22 -0
- data/lib/devkitkat/service/predefined_command/clone.rb +25 -0
- data/lib/devkitkat/service/predefined_command/exec.rb +18 -0
- data/lib/devkitkat/service/predefined_command/poop.rb +17 -0
- data/lib/devkitkat/service/predefined_command/pull.rb +19 -0
- data/lib/devkitkat/service/predefined_command/reconfigure.rb +26 -0
- data/lib/devkitkat/service/predefined_command/show_variables.rb +17 -0
- data/lib/devkitkat/service.rb +13 -214
- data/lib/devkitkat/version.rb +1 -1
- data/lib/devkitkat.rb +12 -5
- metadata +41 -12
- data/docs/READ.md +0 -1
- data/docs/config/READ.md +0 -1
- data/docs/machine/READ.md +0 -1
- data/docs/service/READ.md +0 -1
- data/lib/devkitkat/executor/docker.rb +0 -154
- data/lib/devkitkat/executor/local.rb +0 -25
- data/lib/devkitkat/executor.rb +0 -62
- data/lib/devkitkat/main.rb +0 -50
@@ -0,0 +1,82 @@
|
|
1
|
+
module Devkitkat
|
2
|
+
class Service
|
3
|
+
class Executor
|
4
|
+
class Variables
|
5
|
+
include Concerns::ServiceInitializer
|
6
|
+
|
7
|
+
def to_script
|
8
|
+
[predefined_global_variables,
|
9
|
+
predefined_service_variables,
|
10
|
+
predefined_service_specific_variables,
|
11
|
+
config_global_variables,
|
12
|
+
config_service_variables,
|
13
|
+
command_variables].flatten.join("\n")
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def predefined_global_variables
|
19
|
+
variables = []
|
20
|
+
variables << "export DK_ROOT_DIR=#{command.kit_root}"
|
21
|
+
variables << "export DK_MACHINE_DRIVER=#{config.machine_driver.to_s}"
|
22
|
+
variables << "export DK_MACHINE_LOCATION=#{config.machine_location.to_s}"
|
23
|
+
variables << "export DK_MACHINE_IMAGE=#{config.machine_image.to_s}"
|
24
|
+
variables << "export DK_APPLICATION=#{config.application.to_s}"
|
25
|
+
variables
|
26
|
+
end
|
27
|
+
|
28
|
+
def predefined_service_variables
|
29
|
+
variables = []
|
30
|
+
|
31
|
+
all_services.each do |service|
|
32
|
+
variables << "export DK_#{service.name.upcase}_DIR=#{service.dir}"
|
33
|
+
|
34
|
+
DIVISIONS.each do |division|
|
35
|
+
variables << "export DK_#{service.name.upcase}_#{division.upcase}_DIR=#{service.send("#{division}_dir")}"
|
36
|
+
end
|
37
|
+
|
38
|
+
config.service_hash(service.name).each do |key, value|
|
39
|
+
variables << "export DK_#{service.name.upcase}_#{key.upcase}=#{value}"
|
40
|
+
end
|
41
|
+
|
42
|
+
if service.system?
|
43
|
+
variables << "export DK_#{service.name.upcase}_SHARED_SCRIPT_PATH=#{service.shared_script_path}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
variables
|
48
|
+
end
|
49
|
+
|
50
|
+
def predefined_service_specific_variables
|
51
|
+
variables = []
|
52
|
+
|
53
|
+
variables << "export DK_SELF_DIR=#{service.dir}"
|
54
|
+
|
55
|
+
DIVISIONS.each do |division|
|
56
|
+
variables << "export DK_SELF_#{division.upcase}_DIR=#{service.send("#{division}_dir")}"
|
57
|
+
end
|
58
|
+
|
59
|
+
variables
|
60
|
+
end
|
61
|
+
|
62
|
+
def config_global_variables
|
63
|
+
config.variables.map { |key, value| "export #{key}=#{value}" }
|
64
|
+
end
|
65
|
+
|
66
|
+
def config_service_variables
|
67
|
+
config.service_hash(service.name).map do |key, value|
|
68
|
+
"export #{key}=#{value}"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def command_variables
|
73
|
+
command.variables&.map { |key, value| "export #{key}=#{value}" }
|
74
|
+
end
|
75
|
+
|
76
|
+
def all_services
|
77
|
+
@all_services ||= config.all_services.map { |service| Service.new(service, config, command) }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'require_all'
|
2
|
+
require_rel 'concerns/*.rb'
|
3
|
+
require_rel 'driver/*.rb'
|
4
|
+
require_rel 'executor/*.rb'
|
5
|
+
require_rel 'predefined_command/*.rb'
|
6
|
+
|
7
|
+
module Devkitkat
|
8
|
+
class Service
|
9
|
+
class Executor
|
10
|
+
include Concerns::ServiceInitializer
|
11
|
+
|
12
|
+
ScriptError = Class.new(StandardError)
|
13
|
+
|
14
|
+
def initialize(service)
|
15
|
+
@service = service
|
16
|
+
end
|
17
|
+
|
18
|
+
def execute
|
19
|
+
logger.new_file
|
20
|
+
|
21
|
+
scripter.new_file do
|
22
|
+
if prepare_script
|
23
|
+
execute!
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
true
|
28
|
+
rescue ScriptError => e
|
29
|
+
puts "Failure: #{e}".colorize(:red)
|
30
|
+
|
31
|
+
false
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def prepare_script
|
37
|
+
scripter.write(variables.to_script)
|
38
|
+
scripter.write(logger.to_script) if logger.available?
|
39
|
+
|
40
|
+
if File.exist?(service.script_path)
|
41
|
+
scripter.write(%Q{echo "INFO: This script is a custom script."})
|
42
|
+
scripter.write(service.script_path)
|
43
|
+
elsif predefined_command_available?
|
44
|
+
scripter.write(%Q{echo "INFO: This script is a predefined script in devkitkat."})
|
45
|
+
scripter.write(predefined_command.to_script)
|
46
|
+
else
|
47
|
+
false
|
48
|
+
end
|
49
|
+
|
50
|
+
true
|
51
|
+
end
|
52
|
+
|
53
|
+
def execute!
|
54
|
+
driver.prepare
|
55
|
+
|
56
|
+
driver.execute(scripter.file_path).tap do |result|
|
57
|
+
raise ScriptError, process_error_message($?) unless result
|
58
|
+
end
|
59
|
+
ensure
|
60
|
+
driver.cleanup
|
61
|
+
end
|
62
|
+
|
63
|
+
def driver
|
64
|
+
@driver ||= driver_klass.new(service)
|
65
|
+
end
|
66
|
+
|
67
|
+
def scripter
|
68
|
+
@scripter ||= Scripter.new(service)
|
69
|
+
end
|
70
|
+
|
71
|
+
def logger
|
72
|
+
@logger ||= Logger.new(service)
|
73
|
+
end
|
74
|
+
|
75
|
+
def variables
|
76
|
+
@variables ||= Variables.new(service)
|
77
|
+
end
|
78
|
+
|
79
|
+
def predefined_command
|
80
|
+
@predefined_command ||= predefined_command_klass.new(service)
|
81
|
+
end
|
82
|
+
|
83
|
+
def driver_klass
|
84
|
+
Object.const_get("Devkitkat::Service::Driver::#{config.machine_driver.camelize}")
|
85
|
+
end
|
86
|
+
|
87
|
+
def predefined_command_klass
|
88
|
+
Object.const_get("Devkitkat::Service::PredefinedCommand::#{command.name.camelize}")
|
89
|
+
end
|
90
|
+
|
91
|
+
def predefined_command_available?
|
92
|
+
Object.const_defined?("Devkitkat::Service::PredefinedCommand::#{command.name.camelize}") &&
|
93
|
+
predefined_command.available?
|
94
|
+
end
|
95
|
+
|
96
|
+
def process_error_message(exit_code)
|
97
|
+
%Q[The command "#{command.script}" for "#{service.name}" exited with non-zero code: #{exit_code}.
|
98
|
+
See the log file: #{service.log_path}]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'devkitkat/service/predefined_command/base'
|
2
|
+
|
3
|
+
module Devkitkat
|
4
|
+
class Service
|
5
|
+
class PredefinedCommand
|
6
|
+
class AddExample < Base
|
7
|
+
def to_script
|
8
|
+
names = command.args
|
9
|
+
|
10
|
+
raise ArgumentError, 'Please specify at least one example name' if names.empty?
|
11
|
+
|
12
|
+
FileUtils.mkdir_p(service.example_dir)
|
13
|
+
|
14
|
+
names.map do |name|
|
15
|
+
file_path = File.join(service.example_dir, name)
|
16
|
+
|
17
|
+
<<-EOS
|
18
|
+
if [[ ! -f "#{file_path}" ]]; then
|
19
|
+
touch #{file_path}
|
20
|
+
chmod 755 #{file_path}
|
21
|
+
fi
|
22
|
+
EOS
|
23
|
+
end.join("\n")
|
24
|
+
end
|
25
|
+
|
26
|
+
def available?
|
27
|
+
true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'devkitkat/service/predefined_command/base'
|
2
|
+
|
3
|
+
module Devkitkat
|
4
|
+
class Service
|
5
|
+
class PredefinedCommand
|
6
|
+
class AddGitIgnore < Base
|
7
|
+
def to_script
|
8
|
+
<<~EOS
|
9
|
+
cat > #{file_path} << EOL
|
10
|
+
services/**/script-*
|
11
|
+
services/**/src
|
12
|
+
services/**/log
|
13
|
+
services/**/cache
|
14
|
+
services/**/data
|
15
|
+
EOL
|
16
|
+
EOS
|
17
|
+
end
|
18
|
+
|
19
|
+
def available?
|
20
|
+
service.system? && !File.exist?(file_path)
|
21
|
+
end
|
22
|
+
|
23
|
+
def file_path
|
24
|
+
File.join(command.kit_root, '.gitignore')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'devkitkat/service/predefined_command/base'
|
2
|
+
|
3
|
+
module Devkitkat
|
4
|
+
class Service
|
5
|
+
class PredefinedCommand
|
6
|
+
class AddScript < Base
|
7
|
+
def to_script
|
8
|
+
names = command.args.any? ? command.args : %w[configure unconfigure start]
|
9
|
+
|
10
|
+
FileUtils.mkdir_p(service.script_dir)
|
11
|
+
|
12
|
+
names.map do |name|
|
13
|
+
file_path = File.join(service.script_dir, name)
|
14
|
+
|
15
|
+
<<-EOS
|
16
|
+
if [[ ! -f "#{file_path}" ]]; then
|
17
|
+
cat > #{file_path} << EOL
|
18
|
+
#!/bin/bash
|
19
|
+
set -e
|
20
|
+
|
21
|
+
# TODO: Define scripts
|
22
|
+
EOL
|
23
|
+
chmod 755 #{file_path}
|
24
|
+
fi
|
25
|
+
EOS
|
26
|
+
end.join("\n")
|
27
|
+
end
|
28
|
+
|
29
|
+
def available?
|
30
|
+
true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'devkitkat/service/predefined_command/base'
|
2
|
+
|
3
|
+
module Devkitkat
|
4
|
+
class Service
|
5
|
+
class PredefinedCommand
|
6
|
+
class AddSharedScript < Base
|
7
|
+
def to_script
|
8
|
+
<<~EOS
|
9
|
+
mkdir -p #{service.script_dir}
|
10
|
+
touch #{service.shared_script_path}
|
11
|
+
chmod 755 #{service.shared_script_path}
|
12
|
+
EOS
|
13
|
+
end
|
14
|
+
|
15
|
+
def available?
|
16
|
+
service.system? && !File.exist?(service.shared_script_path)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Devkitkat
|
2
|
+
class Service
|
3
|
+
class PredefinedCommand
|
4
|
+
class Base
|
5
|
+
include Concerns::ServiceInitializer
|
6
|
+
|
7
|
+
def to_script
|
8
|
+
raise NotImplementedError
|
9
|
+
end
|
10
|
+
|
11
|
+
def available?
|
12
|
+
raise NotImplementedError
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'devkitkat/service/predefined_command/base'
|
2
|
+
|
3
|
+
module Devkitkat
|
4
|
+
class Service
|
5
|
+
class PredefinedCommand
|
6
|
+
class Clean < Base
|
7
|
+
def to_script
|
8
|
+
<<~EOS
|
9
|
+
rm -rf #{service.src_dir}
|
10
|
+
rm -rf #{service.data_dir}
|
11
|
+
rm -rf #{service.cache_dir}
|
12
|
+
rm -rf #{service.log_dir}
|
13
|
+
EOS
|
14
|
+
end
|
15
|
+
|
16
|
+
def available?
|
17
|
+
true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'devkitkat/service/predefined_command/base'
|
2
|
+
|
3
|
+
module Devkitkat
|
4
|
+
class Service
|
5
|
+
class PredefinedCommand
|
6
|
+
class Clone < Base
|
7
|
+
def to_script
|
8
|
+
<<~EOS
|
9
|
+
set -e
|
10
|
+
|
11
|
+
if [ -n "$GIT_DEPTH" ]; then
|
12
|
+
git clone #{service.repo} #{service.src_dir} --depth $GIT_DEPTH
|
13
|
+
else
|
14
|
+
git clone #{service.repo} #{service.src_dir}
|
15
|
+
fi
|
16
|
+
EOS
|
17
|
+
end
|
18
|
+
|
19
|
+
def available?
|
20
|
+
service.repo_defined?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Devkitkat
|
2
|
+
class Service
|
3
|
+
class PredefinedCommand
|
4
|
+
class Pull < Base
|
5
|
+
def to_script
|
6
|
+
<<~EOS
|
7
|
+
cd #{service.src_dir}
|
8
|
+
git checkout master
|
9
|
+
git pull origin master
|
10
|
+
EOS
|
11
|
+
end
|
12
|
+
|
13
|
+
def available?
|
14
|
+
service.repo_defined?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Devkitkat
|
2
|
+
class Service
|
3
|
+
class PredefinedCommand
|
4
|
+
class Reconfigure < Base
|
5
|
+
def to_script
|
6
|
+
unconfigure_path = File.join(service.script_dir, 'unconfigure')
|
7
|
+
configure_path = File.join(service.script_dir, 'configure')
|
8
|
+
|
9
|
+
<<~EOS
|
10
|
+
if [[ -f "#{unconfigure_path}" ]]; then
|
11
|
+
#{unconfigure_path}
|
12
|
+
fi
|
13
|
+
|
14
|
+
if [[ -f "#{configure_path}" ]]; then
|
15
|
+
#{configure_path}
|
16
|
+
fi
|
17
|
+
EOS
|
18
|
+
end
|
19
|
+
|
20
|
+
def available?
|
21
|
+
true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|