linecook-gem 0.2.1 → 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: ad86918c27d3bed05ac3aaad743e427877835f97
4
- data.tar.gz: 93df415c037673ac86283e8ae03f81e49c9b0dfa
3
+ metadata.gz: b82d8effb1494b4d5c4fcfd3c91f4b36fd6af24f
4
+ data.tar.gz: 1780d0a2b8dffc44dfc7a7fe52b95cff4024f662
5
5
  SHA512:
6
- metadata.gz: 7bf26a041fdf59d7380f5532e22eeaeb3d0b89aeb8f1e7f08cd57a6d4482e592868526f5e83c41a31b628a6004dc192849eb948703c16b1d32f1e45da5671293
7
- data.tar.gz: 8a65d3ffa6bbe955e9280d11a0218326717b40a218d009c278cf4d729b4e144948791ca821b0520f4dbf7b94658a6e35938f9384d27be2e361b41d841eb2831c
6
+ metadata.gz: dbd66174b697182fdb039743d3abd5804f3884d2dca1d0e12817731cd17565cc939689eb0082d612bb3ddb54d1ffd8b78c2fea2ddd2f563faeb97e5ff0711bc0
7
+ data.tar.gz: 623f5b9b461ace37d1699fc0e8ff5a11c4a510ec0cac780abab1433d68f7a71483bc3c94f606c4db89d659e78012dfcc935869142284f4bbab051a492adea703
@@ -17,6 +17,10 @@ module Linecook
17
17
  @container = Linecook::Lxc::Container.new(name: @id, image: @image, remote: Linecook::Builder.ssh)
18
18
  end
19
19
 
20
+ def clean
21
+ Linecook::ImageManager.clean(type: @image[:type]) if @image.is_a?(Hash) && @image[:type]
22
+ end
23
+
20
24
  def ssh
21
25
  @ssh ||= Linecook::SSH.new(@container.ip, username: USERNAME, proxy: Linecook::Builder.ssh, keyfile: Linecook::SSH.private_key, setup: false)
22
26
  end
@@ -92,7 +92,7 @@ module Linecook
92
92
  def wait_ssh
93
93
  if @remote
94
94
  user = Linecook::Build::USERNAME
95
- cexec("useradd -m -G sudo #{user}")
95
+ cexec("id -u #{user} &>/dev/null || useradd -m -G sudo #{user}")
96
96
  cexec("mkdir -p /home/#{user}/.ssh")
97
97
  Linecook::Builder.ssh.upload(Linecook::SSH.public_key, "/tmp/#{@name}-pubkey")
98
98
  Linecook::Builder.ssh.run("sudo mv /tmp/#{@name}-pubkey #{@root}/home/#{user}/.ssh/authorized_keys")
data/lib/linecook/cli.rb CHANGED
@@ -43,6 +43,13 @@ class Image < Thor
43
43
  Linecook::ImageManager.fetch(name)
44
44
  end
45
45
 
46
+ desc 'clean', 'Clean up cached images'
47
+ method_option :type, type: :string, required: true, banner: 'ID', desc: 'Type of image to list', aliases: '-t'
48
+ def clean
49
+ opts = options.symbolize_keys
50
+ puts Linecook::ImageManager.clean(**opts)
51
+ end
52
+
46
53
  desc 'upload IMAGE', 'Upload an image'
47
54
  method_options name: :string
48
55
  def upload(image)
@@ -27,6 +27,12 @@ module Linecook
27
27
  path
28
28
  end
29
29
 
30
+ def clean(type: nil)
31
+ Dir["#{File.join([IMAGE_PATH, type].compact)}/**/*"].each do |image|
32
+ FileUtils.rm_f(image) unless `mount`.index(image)
33
+ end
34
+ end
35
+
30
36
  def upload(image, profile: :private, type: nil)
31
37
  path = File.join(IMAGE_PATH, File.basename(image))
32
38
  puts "Encrypting and uploading image #{path}"
@@ -24,6 +24,7 @@ module Linecook
24
24
  build.start
25
25
  build.ssh.forward(chef_port)
26
26
  build.ssh.upload(script, '/tmp/chef_bootstrap')
27
+ build.ssh.run('[ -f /var/chef/cache/chef-client-running.pid ] && sudo rm -f /var/chef/cache/chef-client-running.pid')
27
28
  build.ssh.run('sudo bash /tmp/chef_bootstrap')
28
29
  build.ssh.run('sudo rm -rf /etc/chef')
29
30
  build.ssh.stop_forwarding
@@ -17,7 +17,8 @@ module Linecook
17
17
  Linecook::Packager.package(snapshot, type: build_agent.type) if package
18
18
  ensure
19
19
  build_agent.stop(clean: clean) unless keep
20
- FileUtils.rm_f(snapshot) if clean
20
+ build_agent.clean if clean
21
+ FileUtils.rm_f(snapshot) if clean && File.exists?(snapshot.to_s)
21
22
  end
22
23
 
23
24
  private
@@ -1,3 +1,3 @@
1
1
  module Linecook
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.3'
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.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dale Hamel