dock0 0.2.2 → 0.2.3

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
  SHA1:
3
- metadata.gz: 95cc83b7d86b80b1baa9f4f0797a30cf0b2dc9c1
4
- data.tar.gz: fb56e339692dbdbc0637a341f32af33b2c51d9d4
3
+ metadata.gz: 93d7456a2290387ed74a1b3d5dacfd934faf86b2
4
+ data.tar.gz: f0752fe961880c4cc65eef15125f89627d0356b8
5
5
  SHA512:
6
- metadata.gz: 4624dcbc724f1da805be5b330bdef462133608d3bdf702eb840f24deeec3f128ea3d101eebc8c62baad36558e5701b937f38d471806e3c22ca1dc8c53ab16874
7
- data.tar.gz: c1e16756f6dbcd25d969712ff4a7668549037792ba4b5d4e190504e201811df369c6199460e2d1860cf7f18cbc4db1fd60166d048082fe1bcc450d62f10571ba
6
+ metadata.gz: 0aae22f19127ceaa4eefad8b4eb50f5e58e9e0a793c1260702e5cda3a14728ad2080db9da300a911123fec1bdb79556973eecd63f8751d8b62683fd505630c64
7
+ data.tar.gz: 2e5d2ea2a39355e3516c28f85d9ea45c860ff46937f9f3bed59db305498055db92ec8c0f7ee854e3cbfe8bd51d4bad1c288b667e68139788ed6b543963ff2df5
data/README.md CHANGED
@@ -8,27 +8,33 @@ dock0
8
8
  [![Build Status](https://img.shields.io/travis/dock0/dock0.svg)](https://travis-ci.org/dock0/dock0)
9
9
  [![MIT Licensed](https://img.shields.io/badge/license-MIT-green.svg)](https://tldrlegal.com/license/mit-license)
10
10
 
11
- Dynamic Arch image generator for building a read-only host system for [Docker](https://www.docker.io)
11
+ Component generator for building Arch systems
12
12
 
13
13
  ## Usage
14
14
 
15
- This is basically a meta-script that builds Arch images. Its primary use is to build read-only Docker hosts for me, but it could realistically be repurposed for other kinds of minimal deployments.
15
+ ### Build a rootfs
16
16
 
17
- An example configuration can be found in [this repo](https://www.github.com/dock0/host_config).
17
+ ```
18
+ dock0 image config.yaml
19
+ ```
18
20
 
19
- The dock0 command accepts a list of configuration files as arguments. It changes to the directory of the first file given, so all other files and configuration options can use relative pathing based from that location:
21
+ This will build a compressed rootfs from your configuration. Here is [an example configuration](https://github.com/dock0/vm_root)
20
22
 
21
- dock0 /opt/my_dock0/config.yaml ./configs/foobar.yaml
23
+ ### Build a config bundle
22
24
 
23
- The module's Dock0::Image class exposes various methods, but the recommended option is to run .easy_mode(), which runs through them all in the preferred order. This is the sequence (@config represents the merged configs provided):
25
+ ```
26
+ dock0 config config.yaml
27
+ ```
24
28
 
25
- 1. `.prepare_device()` makes an ext2 filesystem at `@config['paths']['device']` and mounts it at `@config['paths']['mount']`
26
- 2. `.prepare_root()` creates a filesystem at `@config['paths']['build_file']` and mounts it at `@config['paths']['build']`
27
- 3. `.install_packages()` pacstraps the root filesystem with all the packages listed in `@config['paths']['package_list']`
28
- 4. `.apply_overlay()` copies the contents of `@config['paths']['overlay']` into the root filesystem
29
- 5. `.run_scripts()` runs all the ruby scripts in `@config['paths']['scripts']` in its own scope (the have access to `@config` and such)
30
- 6. `.run_commands()` runs all commands in `@config['commands']['chroot']` using arch-chroot and all commands in `@config['commands']['host']` on the host system
31
- 7. `.finalize()` unmounts the root FS, packs it in a squashfs, puts it on the target device, and unmounts that
29
+ This builds a config tarball designed to be used to customize a rootfs. Here is [an example configuration](https://github.com/dock0/vm_config)
30
+
31
+ ### Build a system deployment
32
+
33
+ ```
34
+ dock0 install config.yaml
35
+ ```
36
+
37
+ This downloads created artifacts and runs build scripts to combine precreated and dynamic components into a full system. Here is [an example configuration](https://github.com/dock0/vm_install)
32
38
 
33
39
  ## Installation
34
40
 
data/bin/dock0 CHANGED
@@ -28,6 +28,16 @@ Mercenary.program(:dock0) do |p|
28
28
  end
29
29
  end
30
30
 
31
+ p.command(:install) do |c|
32
+ c.syntax 'install CONFIG1 [... CONFIGN]'
33
+ c.description 'Build/update a install'
34
+
35
+ c.action do |args, _|
36
+ Dock0.easy_mode :Install, args
37
+ puts 'All done!'
38
+ end
39
+ end
40
+
31
41
  p.action do
32
42
  puts p
33
43
  exit 1
data/lib/dock0.rb CHANGED
@@ -70,3 +70,4 @@ end
70
70
  require 'dock0/version'
71
71
  require 'dock0/image'
72
72
  require 'dock0/config'
73
+ require 'dock0/install'
@@ -0,0 +1,87 @@
1
+ require 'fileutils'
2
+ require 'open-uri'
3
+
4
+ module Dock0
5
+ ##
6
+ # An Install is a deployment of components onto a system
7
+ class Install < Base
8
+ def default_config
9
+ {
10
+ 'paths' => {
11
+ 'templates' => './templates',
12
+ 'scripts' => './scripts',
13
+ 'build' => './build'
14
+ },
15
+ 'artifacts' => []
16
+ }
17
+ end
18
+
19
+ def build_url(artifact)
20
+ org = @config[:org]
21
+ name, version, file = artifact.fetch('name', 'version', 'file')
22
+ "https://github.com/#{org}/#{name}/releases/download/#{version}/#{file}"
23
+ end
24
+
25
+ def build_path(artifact)
26
+ "#{artifact['name']}/#{artifact['file']}"
27
+ end
28
+
29
+ def download(artifact)
30
+ url, path = artifact.values_at('url', 'full_path')
31
+ puts "Downloading #{url} to #{path}"
32
+ File.open(path, 'wb') do |fh|
33
+ open(url, 'rb') { |request| fh.write request.read }
34
+ end
35
+ end
36
+
37
+ def chmod(artifact)
38
+ File.chmod(artifact['mode'], full_path) if artifact['mode']
39
+ end
40
+
41
+ def link(artifact)
42
+ FileUtils.ln_sf artifact['link'], artifact['path']
43
+ end
44
+
45
+ def load_artifacts
46
+ @config['artifacts'].each do |artifact|
47
+ artifact['url'] ||= build_url(artifact)
48
+ artifact['path'] ||= build_path(artifact)
49
+ artifact['full_path'] = "#{@config['build']}/#{artifact['path']}"
50
+ download artifact
51
+ chmod artifact
52
+ link(artifact) if artifact['link']
53
+ end
54
+ end
55
+
56
+ def templates
57
+ Dir.chdir(@paths['templates']) do
58
+ Dir.glob('**/*').select { |x| File.file? x }
59
+ end
60
+ end
61
+
62
+ def render_templates
63
+ templates.each do |path|
64
+ puts "Templating #{path}"
65
+ template = File.read "#{@paths['templates']}/#{path}"
66
+ parsed = ERB.new(template, nil, '<>').result(binding)
67
+
68
+ target_path = "#{@paths['build']}/#{path}"
69
+ FileUtils.mkdir_p File.dirname(target_path)
70
+ File.open(target_path, 'w') { |fh| fh.write parsed }
71
+ end
72
+ end
73
+
74
+ def finalize
75
+ puts "Packing config into #{@paths['output']}"
76
+ tar = Dir.chdir(File.dirname(@paths['build'])) { run 'tar cz .' }
77
+ File.open(@paths['output'], 'w') { |fh| fh << tar }
78
+ end
79
+
80
+ def easy_mode
81
+ load_artifacts
82
+ render_templates
83
+ run_scripts
84
+ finalize
85
+ end
86
+ end
87
+ end
data/lib/dock0/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  ##
2
2
  # Set the version (needed for Mercenary -v)
3
3
  module Dock0
4
- VERSION = '0.2.2'
4
+ VERSION = '0.2.3'
5
5
  end
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.2.2
4
+ version: 0.2.3
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-12-06 00:00:00.000000000 Z
11
+ date: 2014-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mercenary
@@ -114,6 +114,7 @@ files:
114
114
  - lib/dock0.rb
115
115
  - lib/dock0/config.rb
116
116
  - lib/dock0/image.rb
117
+ - lib/dock0/install.rb
117
118
  - lib/dock0/version.rb
118
119
  - spec/dock0_spec.rb
119
120
  - spec/examples/alpha.yml