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

#buildObject



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

def build
  create_package!
  upload_to_s3
end

#build_pathObject



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

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

#copy_from_s3(sha) ⇒ Object



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

def copy_from_s3(sha)
  ensure_present! :s3_bucket
  object = s3_object_name_for(sha)
  info "Copying s3://#{s3_bucket}/#{object} to s3://#{s3_bucket}/#{s3_object_name}"
  Dockly.s3.copy_object(
    copy_source: File.join(s3_bucket, object),
    bucket: s3_bucket,
    key: s3_object_name,
    acl: 'bucket-owner-full-control',
  )
  info "Successfully copied s3://#{s3_bucket}/#{object} to s3://#{s3_bucket}/#{s3_object_name}"
end

#create_package!Object



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

def create_package!
  info "creating 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)


69
70
71
72
73
74
75
76
77
# File 'lib/dockly/deb.rb', line 69

def exists?
  debug "#{name}: checking for package: #{s3_url}"
  Dockly.s3.head_object(bucket: s3_bucket, key: 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



26
27
28
# File 'lib/dockly/deb.rb', line 26

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

#output_filenameObject



105
106
107
# File 'lib/dockly/deb.rb', line 105

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

#s3_object_nameObject



97
98
99
# File 'lib/dockly/deb.rb', line 97

def s3_object_name
  s3_object_name_for(Dockly::Util::Git.sha)
end

#s3_object_name_for(sha) ⇒ Object



101
102
103
# File 'lib/dockly/deb.rb', line 101

def s3_object_name_for(sha)
  "#{package_name}/#{sha}/#{output_filename}"
end

#s3_urlObject



93
94
95
# File 'lib/dockly/deb.rb', line 93

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

#startup_scriptObject



109
110
111
112
113
114
115
116
# File 'lib/dockly/deb.rb', line 109

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_s3Object



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/dockly/deb.rb', line 79

def upload_to_s3
  return if s3_bucket.nil?
  raise "Package wasn't created!" unless File.exist?(build_path)
  info "uploading package to s3"
  File.open(build_path, 'rb') do |file|
    Dockly.s3.put_object(
      bucket: s3_bucket,
      key: s3_object_name,
      body: file,
      acl: 'bucket-owner-full-control',
    )
  end
end