Class: Dockly::Deb

Inherits:
Object
  • Object
show all
Includes:
Util::DSL, Util::Logger::Mixin
Defined in:
lib/dockly/deb.rb

Direct Known Subclasses

Rpm

Instance Method Summary collapse

Instance Method Details

#build ⇒ Object



43
44
45
46
47
48
# File 'lib/dockly/deb.rb', line 43

def build
  info "creating package"
  create_package!
  info "uploading to s3"
  upload_to_s3
end

#build_path ⇒ Object



50
51
52
53
# File 'lib/dockly/deb.rb', line 50

def build_path
  ensure_present! :build_dir, :deb_build_dir
  File.join(build_dir, deb_build_dir, output_filename)
end

#create_package! ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/dockly/deb.rb', line 28

def create_package!
  ensure_present! :build_dir, :deb_build_dir
  FileUtils.mkdir_p(File.join(build_dir, deb_build_dir))
  FileUtils.rm(build_path) if File.exist?(build_path)
  debug "exporting #{package_name} to #{build_path}"
  build_package
  if @deb_package
    @deb_package.output(build_path)
    info "exported #{package_name} to #{build_path}"
  end
ensure
  @dir_package.cleanup if @dir_package
  @deb_package.cleanup if @deb_package
end

#exists? ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
58
59
60
61
62
63
64
# File 'lib/dockly/deb.rb', line 55

def exists?
  debug "#{name}: checking for package: #{s3_url}"
  Dockly::AWS.s3.head_object(s3_bucket, s3_object_name)
  info "#{name}: found package: #{s3_url}"
  true
rescue
  info "#{name}: could not find package: " +
       "#{s3_url}"
  false
end

#file(source, destination) ⇒ Object



24
25
26
# File 'lib/dockly/deb.rb', line 24

def file(source, destination)
  @files << { :source => source, :destination => destination }
end

#output_filename ⇒ Object



82
83
84
# File 'lib/dockly/deb.rb', line 82

def output_filename
  "#{package_name}_#{version}.#{release}_#{arch}.deb"
end

#s3_object_name ⇒ Object



78
79
80
# File 'lib/dockly/deb.rb', line 78

def s3_object_name
  "#{package_name}/#{Dockly::Util::Git.git_sha}/#{output_filename}"
end

#s3_url ⇒ Object



74
75
76
# File 'lib/dockly/deb.rb', line 74

def s3_url
  "s3://#{s3_bucket}/#{s3_object_name}"
end

#startup_script ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/dockly/deb.rb', line 86

def startup_script
  scripts = []
  bb = Dockly::BashBuilder.new
  scripts << bb.normalize_for_dockly
  scripts << bb.get_and_install_deb(s3_url, "/opt/dockly/#{File.basename(s3_url)}")

  scripts.join("\n")
end

#upload_to_s3 ⇒ Object



66
67
68
69
70
71
72
# File 'lib/dockly/deb.rb', line 66

def upload_to_s3
  return if s3_bucket.nil?
  raise "Package wasn't created!" unless File.exist?(build_path)
  info "uploading package to s3"
  Dockly::AWS.s3.put_bucket(s3_bucket) rescue nil
  Dockly::AWS.s3.put_object(s3_bucket, s3_object_name, File.new(build_path))
end