linecook-gem 0.1.5 → 0.1.6

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: 3890b7bac9016028f98b6967d21b9f60518ac84f
4
- data.tar.gz: c3e4bfe870cf93ea51aa28cfb44f0a12ed330c26
3
+ metadata.gz: 5ad8c9eb3eb01a5e5578360ba001fac59a8723f3
4
+ data.tar.gz: 1237ff044167090a98b47bd7961b420215a4a98e
5
5
  SHA512:
6
- metadata.gz: f18cdad769a08a53c6ce845da61cecdab88f57d75ba762175327809a17bf57905bf7f7bb854a448e7d04d839726e005aba5f5a2d05a8a941e56875cea2262878
7
- data.tar.gz: 59bf75141b3503ee285ad9cde5532f74cdc2a2b697f49cde355325f87abce4bec39890cbb465a978ddb0307a84db6f7f521d05b76e9661b2950157f189e1cac5
6
+ metadata.gz: 5685db5fa8d4eb2bc6f7b154f18c877638328cb08b36bc5ad55b369f8c10b65ea06e75550a4a8ffd72dff99396b7e94b2d4930186919f2a1d7742290998dc63a
7
+ data.tar.gz: 0a4f8b340dc8226e8107eb484ceffd08d0f0f701be8c80c967c8318e1ffd42aa5dedec1387dbe80a11f5dd446853e684b3f9130b2c7a9f47453bb453a46f7bef
@@ -7,11 +7,11 @@ module Linecook
7
7
 
8
8
  def_instance_delegators :@container, :stop, :start, :ip, :info
9
9
 
10
- def initialize(name, image: nil)
10
+ def initialize(name, tag: nil, image: nil)
11
11
  Linecook::Builder.start
12
- @name = name
12
+ @id = tag ? "#{name}-#{tag}" : name
13
13
  @image = image || Linecook.config[:provisioner][:default_image]
14
- @container = Linecook::Lxc::Container.new(name: @name, image: @image, remote: Linecook::Builder.ssh)
14
+ @container = Linecook::Lxc::Container.new(name: @id, image: @image, remote: Linecook::Builder.ssh)
15
15
  end
16
16
 
17
17
  def ssh
@@ -19,9 +19,12 @@ module Linecook
19
19
  end
20
20
 
21
21
  def snapshot(save: false)
22
- path = "/tmp/#{@name}-#{Time.now.to_i}.squashfs"
22
+ path = "/tmp/#{@id}-#{Time.now.to_i}.squashfs"
23
+ @container.pause
23
24
  Linecook::Builder.ssh.run("sudo mksquashfs #{@container.root} #{path} -wildcards -e 'usr/src' 'var/lib/apt/lists/archive*' 'var/cache/apt/archives'") # FIXME make these excludes dynamic based on OS
25
+ @container.resume
24
26
  Linecook::Builder.ssh.download(path, local: File.join(Linecook::ImageManager::IMAGE_PATH, File.basename(path))) if save
27
+ Linecook::Builder.ssh.run("sudo rm -f #{path}")
25
28
  path
26
29
  end
27
30
  end
@@ -36,9 +36,17 @@ module Linecook
36
36
  unmount unless running?
37
37
  end
38
38
 
39
+ def pause
40
+ execute("lxc-stop #{container_str} -k") if running?
41
+ end
42
+
43
+ def resume
44
+ execute("lxc-start #{container_str} -d") unless running?
45
+ end
46
+
39
47
  def stop
40
48
  setup_dirs
41
- execute("lxc-stop #{container_str} -k")
49
+ execute("lxc-stop #{container_str} -k") if running?
42
50
  unmount
43
51
  end
44
52
 
data/lib/linecook/cli.rb CHANGED
@@ -108,8 +108,10 @@ class Linecook::CLI < Thor
108
108
 
109
109
  desc 'bake', 'Bake a new image.'
110
110
  method_option :name, type: :string, required: true, banner: 'ROLE_NAME', desc: 'Name of the role to build', aliases: '-n'
111
+ method_option :tag, type: :string, required: false, banner: 'TAG', desc: 'Optional tag for a build', aliases: '-t'
111
112
  method_option :image, type: :string, banner: 'SOURCE_IMAGE', desc: 'Source image to seed the build.', aliases: '-i'
112
113
  method_option :keep, type: :boolean, default: true, desc: 'Keep the build running when done', aliases: '-k'
114
+ method_option :clean, type: :boolean, default: false, desc: 'Clean up all build artifacts', aliases: '-c'
113
115
  method_option :build, type: :boolean, default: true, desc: 'Build the image', aliases: '-b'
114
116
  method_option :snapshot, type: :boolean, default: false, desc: 'Snapshot the resulting build to create an image', aliases: '-s'
115
117
  method_option :upload, type: :boolean, default: false, desc: 'Upload the resulting build. Implies --snapshot and --encrypt.', aliases: '-u'
@@ -1,3 +1,5 @@
1
+ require 'fileutils'
2
+
1
3
  require 'linecook/image/crypt'
2
4
  require 'linecook/image/github'
3
5
  require 'linecook/image/s3'
@@ -19,7 +21,9 @@ module Linecook
19
21
  def upload(image, profile: :private)
20
22
  path = File.join(IMAGE_PATH, File.basename(image))
21
23
  puts "Encrypting and uploading image #{path}"
22
- provider(profile).upload(Linecook::Crypto.new.encrypt_file(path))
24
+ encrypted = Linecook::Crypto.new.encrypt_file(path)
25
+ provider(profile).upload(encrypted)
26
+ FileUtils.rm_f(encrypted)
23
27
  end
24
28
 
25
29
  def url(image, profile: :private)
@@ -1,4 +1,5 @@
1
1
  require 'securerandom'
2
+ require 'fileutils'
2
3
 
3
4
  require 'linecook/builder/build'
4
5
  require 'linecook/provisioner/chef-zero'
@@ -8,13 +9,15 @@ module Linecook
8
9
  module Baker
9
10
  extend self
10
11
 
11
- def bake(name: nil, image: nil, snapshot: nil, upload: nil, package: nil, build: nil, keep: nil)
12
- build_agent = Linecook::Build.new(name, image: image)
12
+ def bake(name: nil, tag: nil, image: nil, snapshot: nil, upload: nil, package: nil, build: nil, keep: nil, clean: nil)
13
+ build_agent = Linecook::Build.new(name, tag: tag, image: image)
13
14
  provider(name).provision(build_agent, name) if build
14
15
  snapshot = build_agent.snapshot(save: true) if snapshot || upload || package
15
16
  Linecook::ImageManager.upload(snapshot) if upload || package
16
17
  Linecook::Packager.package(snapshot) if package
18
+ ensure
17
19
  build_agent.stop unless keep
20
+ FileUtils.rm_f(snapshot) if clean
18
21
  end
19
22
 
20
23
  private
@@ -1,3 +1,3 @@
1
1
  module Linecook
2
- VERSION = '0.1.5'
2
+ VERSION = '0.1.6'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linecook-gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dale Hamel