dock0 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/dock0.gemspec +1 -0
- data/lib/dock0.rb +8 -11
- data/lib/dock0/config.rb +10 -10
- data/lib/dock0/image.rb +32 -32
- data/lib/dock0/install.rb +13 -13
- data/lib/dock0/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83c126fbfd1dce025ab4e55c8d5824c78427bfe5
|
4
|
+
data.tar.gz: b23d2424d470c95e2528b5abbc640c439b903c5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10e63b9f04934b722d6aac4b2ea9e87a409c4c55b464cf6c668542ca1592302d541243c4847ffc935b6220f288f44dfec4999b8aa57e229fff0d7891826c7e77
|
7
|
+
data.tar.gz: c64d88a22c91e0ce3be3fde0fe971d474d067f35fbe19f193fb0d3088be45afa75560e4720a3cf2549c6fbd858bec5cb7802f31a659e0f6fa8120079277dc2bb
|
data/dock0.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.add_dependency 'mercenary', '~> 0.3.4'
|
21
21
|
s.add_dependency 'menagerie', '~> 1.0.0'
|
22
22
|
s.add_dependency 'meld', '~> 1.0.0'
|
23
|
+
s.add_dependency 'cymbal', '~> 1.0.0'
|
23
24
|
|
24
25
|
s.add_development_dependency 'rubocop', '~> 0.29.0'
|
25
26
|
s.add_development_dependency 'rake', '~> 10.4.0'
|
data/lib/dock0.rb
CHANGED
@@ -2,6 +2,7 @@ require 'yaml'
|
|
2
2
|
require 'English'
|
3
3
|
require 'fileutils'
|
4
4
|
require 'meld'
|
5
|
+
require 'cymbal'
|
5
6
|
|
6
7
|
##
|
7
8
|
# Dock0 provides an interface for building Arch images
|
@@ -31,17 +32,13 @@ module Dock0
|
|
31
32
|
@config = configs.each_with_object(default_config) do |path, obj|
|
32
33
|
new = YAML.load(File.read(path))
|
33
34
|
next unless new
|
34
|
-
obj.deep_merge! new
|
35
|
+
obj.deep_merge! Cymbal.symbolize(new)
|
35
36
|
end
|
36
|
-
@paths = @config[
|
37
|
+
@paths = @config[:paths]
|
37
38
|
end
|
38
39
|
|
39
40
|
def default_config
|
40
|
-
{
|
41
|
-
'paths' => {
|
42
|
-
'scripts' => './scripts'
|
43
|
-
}
|
44
|
-
}
|
41
|
+
{ paths: { scripts: './scripts' } }
|
45
42
|
end
|
46
43
|
|
47
44
|
def run(cmd)
|
@@ -51,7 +48,7 @@ module Dock0
|
|
51
48
|
end
|
52
49
|
|
53
50
|
def templates
|
54
|
-
Dir.chdir(@paths[
|
51
|
+
Dir.chdir(@paths[:templates]) do
|
55
52
|
Dir.glob('**/*').select { |x| File.file? x }
|
56
53
|
end
|
57
54
|
end
|
@@ -59,10 +56,10 @@ module Dock0
|
|
59
56
|
def render_templates(prefix)
|
60
57
|
templates.each do |path|
|
61
58
|
puts "Templating #{path}"
|
62
|
-
template = File.read "#{@paths[
|
59
|
+
template = File.read "#{@paths[:templates]}/#{path}"
|
63
60
|
parsed = ERB.new(template, nil, '<>').result(binding)
|
64
61
|
|
65
|
-
target_path = "#{@paths[
|
62
|
+
target_path = "#{@paths[:build]}/#{prefix}/#{path}"
|
66
63
|
FileUtils.mkdir_p File.dirname(target_path)
|
67
64
|
File.open(target_path, 'w') { |fh| fh.write parsed }
|
68
65
|
end
|
@@ -73,7 +70,7 @@ module Dock0
|
|
73
70
|
end
|
74
71
|
|
75
72
|
def run_scripts
|
76
|
-
Dir.glob(@paths[
|
73
|
+
Dir.glob(@paths[:scripts] + '/*.rb').sort.each do |script|
|
77
74
|
puts "Running #{script}"
|
78
75
|
run_script script
|
79
76
|
end
|
data/lib/dock0/config.rb
CHANGED
@@ -7,29 +7,29 @@ module Dock0
|
|
7
7
|
class Config < Base
|
8
8
|
def default_config
|
9
9
|
{
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
paths: {
|
11
|
+
templates: './templates',
|
12
|
+
scripts: './scripts',
|
13
|
+
build: './build/config',
|
14
|
+
output: './build.tar.gz'
|
15
15
|
}
|
16
16
|
}
|
17
17
|
end
|
18
18
|
|
19
19
|
def finalize
|
20
|
-
puts "Packing config into #{@paths[
|
21
|
-
tar = Dir.chdir(File.dirname(@paths[
|
20
|
+
puts "Packing config into #{@paths[:output]}"
|
21
|
+
tar = Dir.chdir(File.dirname(@paths[:build])) do
|
22
22
|
run 'tar -cz --owner=root --group=root *'
|
23
23
|
end
|
24
|
-
File.open(@paths[
|
24
|
+
File.open(@paths[:output], 'w') { |fh| fh << tar }
|
25
25
|
end
|
26
26
|
|
27
27
|
def easy_mode
|
28
|
-
cleanup @paths.values_at(
|
28
|
+
cleanup @paths.values_at(:build, :output)
|
29
29
|
render_templates('templates')
|
30
30
|
run_scripts
|
31
31
|
finalize
|
32
|
-
cleanup @paths.values_at(
|
32
|
+
cleanup @paths.values_at(:build)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
data/lib/dock0/image.rb
CHANGED
@@ -6,58 +6,58 @@ module Dock0
|
|
6
6
|
class Image < Base
|
7
7
|
def default_config # rubocop:disable Metrics/MethodLength
|
8
8
|
{
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
paths: {
|
10
|
+
build_file: './root.fs',
|
11
|
+
build: './build',
|
12
|
+
package_list: './packages',
|
13
|
+
overlay: './overlay',
|
14
|
+
scripts: './scripts',
|
15
|
+
output: './root.fs.sfs'
|
16
16
|
},
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
fs: {
|
18
|
+
size: 512,
|
19
|
+
type: 'ext4',
|
20
|
+
flags: '-F'
|
21
21
|
}
|
22
22
|
}
|
23
23
|
end
|
24
24
|
|
25
25
|
def run_chroot(cmd)
|
26
|
-
run "arch-chroot #{@paths[
|
26
|
+
run "arch-chroot #{@paths[:build]} #{cmd}"
|
27
27
|
end
|
28
28
|
|
29
29
|
def prepare_root
|
30
|
-
build_file = @paths[
|
31
|
-
filesystem = @config[
|
30
|
+
build_file = @paths[:build_file]
|
31
|
+
filesystem = @config[:fs]
|
32
32
|
puts "Making build FS at #{build_file}"
|
33
|
-
run "dd if=/dev/zero of=#{build_file} bs=1MB count=#{filesystem[
|
34
|
-
mkfs = "mkfs.#{filesystem[
|
33
|
+
run "dd if=/dev/zero of=#{build_file} bs=1MB count=#{filesystem[:size]}"
|
34
|
+
mkfs = "mkfs.#{filesystem[:type]} #{filesystem[:flags]}"
|
35
35
|
run "#{mkfs} #{build_file}"
|
36
|
-
puts "Mounting FS at #{@paths[
|
37
|
-
FileUtils.mkdir_p @paths[
|
38
|
-
run "mount #{build_file} #{@paths[
|
36
|
+
puts "Mounting FS at #{@paths[:build]}"
|
37
|
+
FileUtils.mkdir_p @paths[:build]
|
38
|
+
run "mount #{build_file} #{@paths[:build]}"
|
39
39
|
end
|
40
40
|
|
41
41
|
def install_packages
|
42
|
-
File.read(@paths[
|
42
|
+
File.read(@paths[:package_list]).split("\n").each do |package|
|
43
43
|
puts "Installing #{package}"
|
44
|
-
run "pacstrap -G -M #{@paths[
|
44
|
+
run "pacstrap -G -M #{@paths[:build]} #{package}"
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
48
|
def apply_overlay
|
49
|
-
puts "Applying overlay from #{@paths[
|
50
|
-
overlay_path = @paths[
|
51
|
-
FileUtils.cp_r overlay_path, @paths[
|
49
|
+
puts "Applying overlay from #{@paths[:overlay]}"
|
50
|
+
overlay_path = @paths[:overlay] + '/.'
|
51
|
+
FileUtils.cp_r overlay_path, @paths[:build]
|
52
52
|
end
|
53
53
|
|
54
54
|
def run_commands
|
55
|
-
cmds = @config.fetch(
|
56
|
-
cmds.fetch(
|
55
|
+
cmds = @config.fetch(:commands, {})
|
56
|
+
cmds.fetch(:chroot, []).each do |cmd|
|
57
57
|
puts "Running #{cmd} in chroot"
|
58
58
|
run_chroot cmd
|
59
59
|
end
|
60
|
-
cmds.fetch(
|
60
|
+
cmds.fetch(:host, []).each do |cmd|
|
61
61
|
puts "Running #{cmd} on host"
|
62
62
|
run cmd
|
63
63
|
end
|
@@ -65,20 +65,20 @@ module Dock0
|
|
65
65
|
|
66
66
|
def finalize
|
67
67
|
puts 'Packing up root FS'
|
68
|
-
run "umount #{@paths[
|
69
|
-
FileUtils.rm_f @paths[
|
70
|
-
run "mksquashfs #{@paths[
|
68
|
+
run "umount #{@paths[:build]}"
|
69
|
+
FileUtils.rm_f @paths[:output]
|
70
|
+
run "mksquashfs #{@paths[:build_file]} #{@paths[:output]}"
|
71
71
|
end
|
72
72
|
|
73
73
|
def easy_mode
|
74
|
-
cleanup @paths.values_at(
|
74
|
+
cleanup @paths.values_at(:build_file, :build, :output)
|
75
75
|
prepare_root
|
76
76
|
install_packages
|
77
77
|
apply_overlay
|
78
78
|
run_scripts
|
79
79
|
run_commands
|
80
80
|
finalize
|
81
|
-
cleanup @paths.values_at(
|
81
|
+
cleanup @paths.values_at(:build_file, :build)
|
82
82
|
end
|
83
83
|
end
|
84
84
|
end
|
data/lib/dock0/install.rb
CHANGED
@@ -7,33 +7,33 @@ module Dock0
|
|
7
7
|
class Install < Base
|
8
8
|
def default_config
|
9
9
|
{
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
paths: {
|
11
|
+
templates: './templates',
|
12
|
+
scripts: './scripts',
|
13
|
+
build: './build',
|
14
|
+
base: '/'
|
15
15
|
},
|
16
|
-
|
17
|
-
|
16
|
+
org: 'dock0',
|
17
|
+
artifacts: []
|
18
18
|
}
|
19
19
|
end
|
20
20
|
|
21
21
|
def build_url(artifact)
|
22
|
-
org = artifact[
|
23
|
-
name, version, file = artifact.values_at(
|
22
|
+
org = artifact[:org] || @config[:org]
|
23
|
+
name, version, file = artifact.values_at(:name, :version, :file)
|
24
24
|
"https://github.com/#{org}/#{name}/releases/download/#{version}/#{file}"
|
25
25
|
end
|
26
26
|
|
27
27
|
def artifacts
|
28
|
-
@config[
|
29
|
-
artifact[
|
28
|
+
@config[:artifacts].map do |artifact|
|
29
|
+
artifact[:url] ||= build_url(artifact)
|
30
30
|
artifact
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
def load_artifacts
|
35
|
-
Dir.chdir("#{@paths[
|
36
|
-
menagerie = Menagerie.new @config[
|
35
|
+
Dir.chdir("#{@paths[:build]}/#{@paths[:base]}") do
|
36
|
+
menagerie = Menagerie.new @config[:menagerie]
|
37
37
|
menagerie.create artifacts
|
38
38
|
end
|
39
39
|
end
|
data/lib/dock0/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dock0
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Les Aker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mercenary
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 1.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: cymbal
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.0.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.0.0
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rubocop
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|