Class: Bosh::Cli::Command::ShareRelease

Inherits:
Base
  • Object
show all
Defined in:
lib/bosh/cli/commands/share_release.rb

Instance Method Summary collapse

Instance Method Details

#share_release(tarball_path) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bosh/cli/commands/share_release.rb', line 7

def share_release(tarball_path)
  # need to be in release dir to get blobstore credentials
  check_if_release_dir

  unless File.exist?(tarball_path)
    err("Release tarball file doesn't exist")
  end

  tarball = Bosh::Cli::ReleaseTarball.new(tarball_path)
  say("\nVerifying release...")
  tarball.validate(:allow_sparse => true)
  nl

  unless tarball.valid?
    err('Release is invalid, please fix, verify and upload again')
  end

  upload_name = "boshrelease-#{tarball.release_name}-#{tarball.version}.tgz"

  f = ::FileWithProgressBar.open(tarball_path, 'r')
  f.out = Bosh::Cli::Config.output

  raw_blobstore_client = unwrap_blobstore_client(blobstore)
  bucket_name = raw_blobstore_client.instance_variable_get("@bucket_name")

  fog = fog_storage(raw_blobstore_client)
  dir = fog.directories.get(bucket_name)

  say("\nUploading release...")
  if file = dir.files.new(key: upload_name, body: f)
    file.public = true
    file.save
    nl
    say(file.public_url)
  else
    err('Failed to upload file to blobstore')
  end
end