dock0 0.1.4 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d0c85a99736593eaac925427d5d0b99d0eea0f55
4
- data.tar.gz: 454ce31758bf64e21dcce751b72e8f16ff28a851
3
+ metadata.gz: 5e03efc79249c833960aa75d7df70773e809fec0
4
+ data.tar.gz: 06e14ea724f68d12664dc0e9df7bc5d5c5a20a86
5
5
  SHA512:
6
- metadata.gz: 7f0f0a10d88d24def266db10a99833a0226f95e7eac7b26f5bf269469154f818e3a6659a8d6f710068faf901f173f365bf7c18f56afd6e8a9427e7b8af9f4c39
7
- data.tar.gz: c81724d111c0556768b1475f86985062243bf1d67ed4fec577d57c2111841f5ccbd2595233405fe23da413e9a8080cdaa4f6f425f52a7e9f7bbcead09ff2218d
6
+ metadata.gz: 06c1c5c0a8f07af437714525a1c76a11fbbf790c27ab832e1126f639676fd97ad324ba8c2cbf201dc5a6bb75a093712d0098ff16390a777bf02b5a1faef1ac71
7
+ data.tar.gz: e6cc0e1b04ffc8edff39e8aa5d5cae671ca56f1b60280ab7180f851bd0855663ad9b5c6705150430ce18524594f4befa042034a5f146d530b96b7c8181e1e060
data/bin/dock0 CHANGED
@@ -1,8 +1,30 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'dock0'
4
+ require 'mercenary'
4
5
 
5
- Dir.chdir File.dirname(ARGV.first)
6
- Dock0.new(*ARGV).easy_mode
6
+ Mercenary.program(:dock0) do |p|
7
+ p.version Dock0::VERSION
8
+ p.description 'Tool for creating server components'
9
+ p.syntax 'dock0 [command] CONFIG1 [... CONFIGN]'
7
10
 
8
- puts 'All done!'
11
+ p.command(:image) do |c|
12
+ c.syntax 'image CONFIG1 [... CONFIGN]'
13
+ c.description 'Build a root image'
14
+
15
+ c.action do |args, _|
16
+ Dock0.easy_mode Dock0::Image, args
17
+ puts 'All done!'
18
+ end
19
+ end
20
+
21
+ p.command(:config) do |c|
22
+ c.syntax 'config CONFIG1 [... CONFIGN]'
23
+ c.description 'Build a configuration bundle'
24
+
25
+ c.action do |args, _|
26
+ Dock0.easy_mode Dock0::Config, args
27
+ puts 'All done!'
28
+ end
29
+ end
30
+ end
data/dock0.gemspec CHANGED
@@ -1,6 +1,9 @@
1
+ $:.unshift File.expand_path('../lib/', __FILE__)
2
+ require 'dock0/version'
3
+
1
4
  Gem::Specification.new do |s|
2
5
  s.name = 'dock0'
3
- s.version = '0.1.4'
6
+ s.version = Dock0::VERSION
4
7
  s.date = Time.now.strftime("%Y-%m-%d")
5
8
 
6
9
  s.summary = 'Builds a read-only Arch host for Docker'
@@ -14,8 +17,10 @@ Gem::Specification.new do |s|
14
17
  s.test_files = `git ls-files spec/*`.split
15
18
  s.executables = ['dock0']
16
19
 
20
+ s.add_dependency 'mercenary', '~> 0.3.4'
21
+
17
22
  s.add_development_dependency 'rubocop', '~> 0.27.0'
18
- s.add_development_dependency 'rake', '~> 10.3.2'
23
+ s.add_development_dependency 'rake', '~> 10.4.0'
19
24
  s.add_development_dependency 'coveralls', '~> 0.7.1'
20
25
  s.add_development_dependency 'rspec', '~> 3.1.0'
21
26
  s.add_development_dependency 'fuubar', '~> 2.0.0'
data/lib/dock0.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'yaml'
2
+ require 'English'
3
+
1
4
  ##
2
5
  # Dock0 provides an interface for building Arch images
3
6
  module Dock0
@@ -8,7 +11,54 @@ module Dock0
8
11
  def new(*args)
9
12
  Dock0::Image.new(*args)
10
13
  end
14
+
15
+ ##
16
+ # Helper for simplifying object creation
17
+ def easy_mode(type, args)
18
+ Dir.chdir File.dirname(args.first)
19
+ const_get(type).new(*args).easy_mode
20
+ end
21
+ end
22
+
23
+ ##
24
+ # Base class for common methods
25
+ class Base
26
+ attr_reader :config
27
+
28
+ DEFAULT_CONFIG = {
29
+ 'paths' => {
30
+ 'scripts' => './scripts'
31
+ }
32
+ }
33
+
34
+ def initialize(*configs)
35
+ @config = configs.each_with_object(DEFAULT_CONFIG.dup) do |path, obj|
36
+ new = YAML.load(File.read(path))
37
+ next unless new
38
+ obj.merge! new
39
+ end
40
+ @paths = @config['paths']
41
+ end
42
+
43
+ def run(cmd)
44
+ results = `#{cmd} 2>&1`
45
+ return results if $CHILD_STATUS.success?
46
+ fail "Failed running #{cmd}:\n#{results}"
47
+ end
48
+
49
+ def run_script(script)
50
+ Dir.chdir('.') { instance_eval File.read(script), script, 0 }
51
+ end
52
+
53
+ def run_scripts
54
+ Dir.glob(@paths['scripts'] + '/*.rb').sort.each do |script|
55
+ puts "Running #{script}"
56
+ run_script script
57
+ end
58
+ end
11
59
  end
12
60
  end
13
61
 
62
+ require 'dock0/version'
14
63
  require 'dock0/image'
64
+ require 'dock0/config'
@@ -0,0 +1,36 @@
1
+ require 'erb'
2
+ require 'fileutils'
3
+
4
+ module Dock0
5
+ ##
6
+ # A Config is a system-specific customization layer
7
+ class Config < Base
8
+ DEFAULT_CONFIG = {
9
+ 'paths' => {
10
+ 'templates' => './templates',
11
+ 'build' => './build'
12
+ }
13
+ }
14
+
15
+ def templates
16
+ Dir.chdir(@paths['templates']) do
17
+ Dir.glob('**/*').select { |x| File.file? x }
18
+ end
19
+ end
20
+
21
+ def render_templates
22
+ templates.each do |path|
23
+ template = File.read "#{@paths['templates']}/#{path}"
24
+ parsed = ERB.new(template, nil, '<>').result(binding)
25
+
26
+ target_path = "#{@paths['build']}/templates/#{path}"
27
+ FileUtils.mkdir_p File.dirname(target_path)
28
+ File.open(target_path, 'w') { |fh| fh.write parsed }
29
+ end
30
+ end
31
+
32
+ def easy_mode
33
+ render_templates
34
+ end
35
+ end
36
+ end
data/lib/dock0/image.rb CHANGED
@@ -1,13 +1,9 @@
1
- require 'yaml'
2
1
  require 'fileutils'
3
- require 'English'
4
2
 
5
3
  module Dock0
6
4
  ##
7
- # An Image is an Arch system being built
8
- class Image
9
- attr_reader :device_path, :config, :stamp
10
-
5
+ # An Image is a rootfs for a system
6
+ class Image < Base
11
7
  DEFAULT_CONFIG = {
12
8
  'paths' => {
13
9
  'build_file' => '/opt/build_file',
@@ -24,24 +20,6 @@ module Dock0
24
20
  }
25
21
  }
26
22
 
27
- ##
28
- # Make a new Image object with the given config
29
-
30
- def initialize(*configs)
31
- @config = configs.each_with_object(DEFAULT_CONFIG.dup) do |path, obj|
32
- new = YAML.load(File.read(path))
33
- next unless new
34
- obj.merge! new
35
- end
36
- @paths = @config['paths']
37
- end
38
-
39
- def run(cmd)
40
- results = `#{cmd} 2>&1`
41
- return results if $CHILD_STATUS.success?
42
- fail "Failed running #{cmd}:\n#{results}"
43
- end
44
-
45
23
  def run_chroot(cmd)
46
24
  run "arch-chroot #{@paths['build']} #{cmd}"
47
25
  end
@@ -50,7 +28,7 @@ module Dock0
50
28
  build_file = @paths['build_file']
51
29
  filesystem = @config['fs']
52
30
  puts "Making build FS at #{build_file}"
53
- run "dd if=/dev/zero of=#{build_file} bs=1M count=#{filesystem['size']}"
31
+ run "dd if=/dev/zero of=#{build_file} bs=1MB count=#{filesystem['size']}"
54
32
  mkfs = "mkfs.#{filesystem['type']} #{filesystem['flags']}"
55
33
  run "#{mkfs} #{build_file}"
56
34
  puts "Mounting FS at #{@paths['build']}"
@@ -71,17 +49,6 @@ module Dock0
71
49
  FileUtils.cp_r overlay_path, @paths['build']
72
50
  end
73
51
 
74
- def run_script(script)
75
- Dir.chdir('.') { instance_eval File.read(script), script, 0 }
76
- end
77
-
78
- def run_scripts
79
- Dir.glob(@paths['scripts'] + '/*.rb').sort.each do |script|
80
- puts "Running #{script}"
81
- run_script script
82
- end
83
- end
84
-
85
52
  def run_commands
86
53
  cmds = @config.fetch('commands', {})
87
54
  cmds.fetch('chroot', []).each do |cmd|
@@ -0,0 +1,5 @@
1
+ ##
2
+ # Set the version (needed for Mercenary -v)
3
+ module Dock0
4
+ VERSION = '0.2.0'
5
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dock0
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.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: 2014-11-23 00:00:00.000000000 Z
11
+ date: 2014-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mercenary
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.4
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rubocop
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -30,14 +44,14 @@ dependencies:
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: 10.3.2
47
+ version: 10.4.0
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: 10.3.2
54
+ version: 10.4.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: coveralls
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -98,7 +112,9 @@ files:
98
112
  - bin/dock0
99
113
  - dock0.gemspec
100
114
  - lib/dock0.rb
115
+ - lib/dock0/config.rb
101
116
  - lib/dock0/image.rb
117
+ - lib/dock0/version.rb
102
118
  - spec/dock0_spec.rb
103
119
  - spec/examples/alpha.yml
104
120
  - spec/examples/beta.yml