Class: Dockly::Deb

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

Instance Method Summary collapse

Instance Method Details

#buildObject



39
40
41
42
43
44
# File 'lib/dockly/deb.rb', line 39

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

#build_pathObject



46
47
48
49
# File 'lib/dockly/deb.rb', line 46

def build_path
  ensure_present! :build_dir
  "#{build_dir}/#{output_filename}"
end

#create_package!Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dockly/deb.rb', line 24

def create_package!
  ensure_present! :build_dir
  FileUtils.mkdir_p(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)


51
52
53
54
55
56
57
58
59
60
# File 'lib/dockly/deb.rb', line 51

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



20
21
22
# File 'lib/dockly/deb.rb', line 20

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

#output_filenameObject



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

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

#s3_object_nameObject



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

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

#s3_urlObject



70
71
72
# File 'lib/dockly/deb.rb', line 70

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

#upload_to_s3Object



62
63
64
65
66
67
68
# File 'lib/dockly/deb.rb', line 62

def upload_to_s3
  return if s3_bucket.nil?
  create_package! 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