dock0 0.2.0 → 0.2.1
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 +4 -4
- data/Rakefile +2 -2
- data/bin/dock0 +8 -3
- data/lib/dock0.rb +15 -7
- data/lib/dock0/config.rb +20 -5
- data/lib/dock0/image.rb +18 -21
- data/lib/dock0/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc715c368b527dcfc38003b9a92c518d02b33a04
|
4
|
+
data.tar.gz: 5dc7b512052f879254ba807a80b8e0c4d8cc0eb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f532497c23cad81480947e8bf5c8952814d4761a0713c4089448cb8740adb5aec9162d718800ecbacd9bf491f155eac20f5b0a9002ebb844f04fd0cc4ef60dba
|
7
|
+
data.tar.gz: 0c5c7adfcb2eea1fa55722f470792a4c15c78076744e7853085ffc519114ee84c3feb55435dee1c40c7dbb668a150a7d1c7de0d596065646ba17968916ddfd4d
|
data/Rakefile
CHANGED
@@ -7,8 +7,8 @@ RSpec::Core::RakeTask.new(:spec)
|
|
7
7
|
|
8
8
|
desc 'Run Rubocop on the gem'
|
9
9
|
RuboCop::RakeTask.new(:rubocop) do |task|
|
10
|
-
task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
|
10
|
+
task.patterns = ['lib/**/*.rb', 'spec/**/*.rb', 'bin/*']
|
11
11
|
task.fail_on_error = true
|
12
12
|
end
|
13
13
|
|
14
|
-
task default: [:spec, :rubocop, :build]
|
14
|
+
task default: [:spec, :rubocop, :build, :install]
|
data/bin/dock0
CHANGED
@@ -6,14 +6,14 @@ require 'mercenary'
|
|
6
6
|
Mercenary.program(:dock0) do |p|
|
7
7
|
p.version Dock0::VERSION
|
8
8
|
p.description 'Tool for creating server components'
|
9
|
-
p.syntax 'dock0
|
9
|
+
p.syntax 'dock0 <subcommand> [args]'
|
10
10
|
|
11
11
|
p.command(:image) do |c|
|
12
12
|
c.syntax 'image CONFIG1 [... CONFIGN]'
|
13
13
|
c.description 'Build a root image'
|
14
14
|
|
15
15
|
c.action do |args, _|
|
16
|
-
Dock0.easy_mode
|
16
|
+
Dock0.easy_mode :Image, args
|
17
17
|
puts 'All done!'
|
18
18
|
end
|
19
19
|
end
|
@@ -23,8 +23,13 @@ Mercenary.program(:dock0) do |p|
|
|
23
23
|
c.description 'Build a configuration bundle'
|
24
24
|
|
25
25
|
c.action do |args, _|
|
26
|
-
Dock0.easy_mode
|
26
|
+
Dock0.easy_mode :Config, args
|
27
27
|
puts 'All done!'
|
28
28
|
end
|
29
29
|
end
|
30
|
+
|
31
|
+
p.action do
|
32
|
+
puts p
|
33
|
+
exit
|
34
|
+
end
|
30
35
|
end
|
data/lib/dock0.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
require 'English'
|
3
|
+
require 'fileutils'
|
3
4
|
|
4
5
|
##
|
5
6
|
# Dock0 provides an interface for building Arch images
|
@@ -25,14 +26,8 @@ module Dock0
|
|
25
26
|
class Base
|
26
27
|
attr_reader :config
|
27
28
|
|
28
|
-
DEFAULT_CONFIG = {
|
29
|
-
'paths' => {
|
30
|
-
'scripts' => './scripts'
|
31
|
-
}
|
32
|
-
}
|
33
|
-
|
34
29
|
def initialize(*configs)
|
35
|
-
@config = configs.each_with_object(
|
30
|
+
@config = configs.each_with_object(default_config) do |path, obj|
|
36
31
|
new = YAML.load(File.read(path))
|
37
32
|
next unless new
|
38
33
|
obj.merge! new
|
@@ -40,6 +35,14 @@ module Dock0
|
|
40
35
|
@paths = @config['paths']
|
41
36
|
end
|
42
37
|
|
38
|
+
def default_config
|
39
|
+
{
|
40
|
+
'paths' => {
|
41
|
+
'scripts' => './scripts'
|
42
|
+
}
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
43
46
|
def run(cmd)
|
44
47
|
results = `#{cmd} 2>&1`
|
45
48
|
return results if $CHILD_STATUS.success?
|
@@ -56,6 +59,11 @@ module Dock0
|
|
56
59
|
run_script script
|
57
60
|
end
|
58
61
|
end
|
62
|
+
|
63
|
+
def cleanup(list)
|
64
|
+
puts "Removing: #{list.join(', ')}"
|
65
|
+
FileUtils.rm_rf list
|
66
|
+
end
|
59
67
|
end
|
60
68
|
end
|
61
69
|
|
data/lib/dock0/config.rb
CHANGED
@@ -5,12 +5,16 @@ module Dock0
|
|
5
5
|
##
|
6
6
|
# A Config is a system-specific customization layer
|
7
7
|
class Config < Base
|
8
|
-
|
9
|
-
|
10
|
-
'
|
11
|
-
|
8
|
+
def default_config
|
9
|
+
{
|
10
|
+
'paths' => {
|
11
|
+
'templates' => './templates',
|
12
|
+
'scripts' => './scripts',
|
13
|
+
'build' => './build/config',
|
14
|
+
'output' => './build.tar.gz'
|
15
|
+
}
|
12
16
|
}
|
13
|
-
|
17
|
+
end
|
14
18
|
|
15
19
|
def templates
|
16
20
|
Dir.chdir(@paths['templates']) do
|
@@ -20,6 +24,7 @@ module Dock0
|
|
20
24
|
|
21
25
|
def render_templates
|
22
26
|
templates.each do |path|
|
27
|
+
puts "Templating #{path}"
|
23
28
|
template = File.read "#{@paths['templates']}/#{path}"
|
24
29
|
parsed = ERB.new(template, nil, '<>').result(binding)
|
25
30
|
|
@@ -29,8 +34,18 @@ module Dock0
|
|
29
34
|
end
|
30
35
|
end
|
31
36
|
|
37
|
+
def finalize
|
38
|
+
puts "Packing config into #{@paths['output']}"
|
39
|
+
tar = Dir.chdir(File.dirname(@paths['build'])) { run 'tar cz .' }
|
40
|
+
File.open(@paths['output'], 'w') { |fh| fh << tar }
|
41
|
+
end
|
42
|
+
|
32
43
|
def easy_mode
|
44
|
+
cleanup @paths.values_at('build', 'output')
|
33
45
|
render_templates
|
46
|
+
run_scripts
|
47
|
+
finalize
|
48
|
+
cleanup @paths.values_at('build')
|
34
49
|
end
|
35
50
|
end
|
36
51
|
end
|
data/lib/dock0/image.rb
CHANGED
@@ -4,21 +4,23 @@ module Dock0
|
|
4
4
|
##
|
5
5
|
# An Image is a rootfs for a system
|
6
6
|
class Image < Base
|
7
|
-
|
8
|
-
|
9
|
-
'
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
'
|
18
|
-
|
19
|
-
|
7
|
+
def default_config # rubocop:disable Metrics/MethodLength
|
8
|
+
{
|
9
|
+
'paths' => {
|
10
|
+
'build_file' => './build_file',
|
11
|
+
'build' => './build_file_mount',
|
12
|
+
'package_list' => './packages',
|
13
|
+
'overlay' => './overlay',
|
14
|
+
'scripts' => './scripts',
|
15
|
+
'output' => './root.fs.sfs'
|
16
|
+
},
|
17
|
+
'fs' => {
|
18
|
+
'size' => 512,
|
19
|
+
'type' => 'ext4',
|
20
|
+
'flags' => '-F'
|
21
|
+
}
|
20
22
|
}
|
21
|
-
|
23
|
+
end
|
22
24
|
|
23
25
|
def run_chroot(cmd)
|
24
26
|
run "arch-chroot #{@paths['build']} #{cmd}"
|
@@ -68,20 +70,15 @@ module Dock0
|
|
68
70
|
run "mksquashfs #{@paths['build_file']} #{@paths['output']}"
|
69
71
|
end
|
70
72
|
|
71
|
-
def cleanup
|
72
|
-
puts 'Removing temporary build image'
|
73
|
-
File.unlink @paths['build_file']
|
74
|
-
end
|
75
|
-
|
76
73
|
def easy_mode
|
74
|
+
cleanup @paths.values_at('build_file', 'build', 'output')
|
77
75
|
prepare_root
|
78
76
|
install_packages
|
79
77
|
apply_overlay
|
80
78
|
run_scripts
|
81
79
|
run_commands
|
82
|
-
sleep 5
|
83
80
|
finalize
|
84
|
-
cleanup
|
81
|
+
cleanup @paths.values_at('build_file', 'build')
|
85
82
|
end
|
86
83
|
end
|
87
84
|
end
|
data/lib/dock0/version.rb
CHANGED