Method: Cnvrg::CLI#upload_image_old

Defined in:
lib/cnvrg/cli.rb

#upload_image_old(image_id, is_public, is_base, *message) ⇒ Object



4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
# File 'lib/cnvrg/cli.rb', line 4583

def upload_image_old(image_id, is_public, is_base, *message)
  verify_logged_in(true)
  log_start(__method__, args, options)
  image = Docker::Image.get(image_id)
  project_home = get_project_home
  @project = Project.new(project_home)
  last_local_commit = @project.last_local_commit
  image_name = @project.slug + "#{last_local_commit}"
  path = File.expand_path('~') + "/.cnvrg/tmp/#{image_name}.tar"
  owner = Cnvrg::CLI.get_owner()
  if !message.nil? or !message.empty?
    message = message.join(" ")
  end

  log_message("Saving image's current state", Thor::Shell::Color::BLUE)
  image.save(path)

  begin
    log_message("Compressing image file to upload", Thor::Shell::Color::BLUE)
    gzipRes = system("gzip -f #{path}")
    if !gzipRes

      log_message("Couldn't create tar file from image", Thor::Shell::Color::RED)
      exit(1)
    end
    path = path + ".gz"
    @files = Cnvrg::Files.new(owner, "")

    exit_status = $?.exitstatus
    if exit_status == 0
      log_message("Uploading image file", Thor::Shell::Color::BLUE)

      diff = container_changes(Dir.pwd)
      res = @files.upload_image(path, image_name, owner, is_public, is_base, diff[1], diff[0], diff[2], message, image.commit_id)
      if res
        File.delete(path)
        image_loc = is_project_with_docker(Dir.pwd)
        image_loc.update_slug(res["result"]["id"])

        checks = Helpers.checkmark()
        log_message("#{checks} Done", Thor::Shell::Color::GREEN)
      else
        log_message("Couldn't upload image", Thor::Shell::Color::RED)

      end
    else
      log_message("Couldn't create image file for: #{image_name}", Thor::Shell::Color::RED)
      exit(1)
    end
  rescue => e
    log_message("Couldn't upload image file for: #{image_name}", Thor::Shell::Color::RED)
    log_error(e)
  rescue SignalException

    say "Couldn't upload image file for: #{image_name}", Thor::Shell::Color::RED
    exit(1)
  end
end