2014-10-29 16:39:26 +00:00
|
|
|
require "vagrant/util/safe_exec"
|
|
|
|
require "vagrant/util/subprocess"
|
|
|
|
require "vagrant/util/which"
|
|
|
|
|
2014-10-29 03:54:16 +00:00
|
|
|
module VagrantPlugins
|
2014-11-12 20:49:55 +00:00
|
|
|
module AtlasPush
|
2014-10-29 03:54:16 +00:00
|
|
|
class Push < Vagrant.plugin("2", :push)
|
2014-11-12 20:49:55 +00:00
|
|
|
UPLOADER_BIN = "atlas-upload".freeze
|
2014-10-29 16:39:26 +00:00
|
|
|
|
2014-10-29 03:54:16 +00:00
|
|
|
def push
|
2014-10-29 16:39:26 +00:00
|
|
|
uploader = self.uploader_path
|
|
|
|
|
|
|
|
# If we didn't find the uploader binary it is a critical error
|
|
|
|
raise Errors::UploaderNotFound if !uploader
|
|
|
|
|
|
|
|
# We found it. Build up the command and the args.
|
|
|
|
execute(uploader)
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
|
|
|
# Executes the uploader with the proper flags based on the configuration.
|
|
|
|
# This function shouldn't return since it will exec, but might return
|
|
|
|
# if we're on a system that doesn't support exec, so handle that properly.
|
|
|
|
def execute(uploader)
|
|
|
|
cmd = []
|
2015-01-05 21:04:00 +00:00
|
|
|
cmd << "-debug" if !Vagrant.log_level.nil?
|
2014-11-11 23:58:02 +00:00
|
|
|
cmd << "-vcs" if config.vcs
|
2014-11-12 20:49:55 +00:00
|
|
|
cmd += config.includes.map { |v| ["-include", v] }
|
|
|
|
cmd += config.excludes.map { |v| ["-exclude", v] }
|
2015-02-04 00:19:51 +00:00
|
|
|
cmd += metadata.map { |k,v| ["-metadata", "#{k}=#{v}"] }
|
2014-12-02 06:05:13 +00:00
|
|
|
cmd += ["-address", config.address] if config.address
|
2014-12-09 00:54:19 +00:00
|
|
|
cmd += ["-token", config.token] if config.token
|
2014-11-11 23:58:02 +00:00
|
|
|
cmd << config.app
|
|
|
|
cmd << File.expand_path(config.dir, env.root_path)
|
2014-10-29 16:39:26 +00:00
|
|
|
Vagrant::Util::SafeExec.exec(uploader, *cmd.flatten)
|
|
|
|
end
|
|
|
|
|
|
|
|
# This returns the path to the uploader binary, or nil if it can't
|
|
|
|
# be found.
|
|
|
|
#
|
|
|
|
# @return [String]
|
|
|
|
def uploader_path
|
|
|
|
# Determine the uploader path
|
2015-02-04 00:20:12 +00:00
|
|
|
if uploader = config.uploader_path
|
2014-10-29 16:39:26 +00:00
|
|
|
return uploader
|
|
|
|
end
|
|
|
|
|
|
|
|
if Vagrant.in_installer?
|
2014-12-02 05:52:03 +00:00
|
|
|
path = File.join(
|
|
|
|
Vagrant.installer_embedded_dir, "bin", UPLOADER_BIN)
|
|
|
|
return path if File.file?(path)
|
2014-10-29 16:39:26 +00:00
|
|
|
end
|
2014-12-02 05:52:03 +00:00
|
|
|
|
|
|
|
return Vagrant::Util::Which.which(UPLOADER_BIN)
|
2014-10-29 03:54:16 +00:00
|
|
|
end
|
2015-02-04 00:19:51 +00:00
|
|
|
|
|
|
|
# The metadata command for this push.
|
|
|
|
#
|
|
|
|
# @return [Array<String>]
|
|
|
|
def metadata
|
|
|
|
hash = {
|
|
|
|
"box" => env.vagrantfile.config.vm.box,
|
|
|
|
"box_url" => env.vagrantfile.config.vm.box_url,
|
|
|
|
}.reject { |k,v| v.nil? || v.empty? }
|
|
|
|
end
|
2014-10-29 03:54:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|