Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/psexec interactive #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions lib/travis/worker/job/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,79 @@ def run_script
exit $(cat ~/build.sh.exit)
EOF
session.exec("GUEST_API_URL=%s bash ~/wrapper.sh" % guest_api_url) { exit_exec? }
elsif payload[:config][:os] == 'windows' && Hash === payload[:config][:windows] && payload[:config][:windows][:run_in_session1]
session.upload_file("~/build_wrapper.sh", <<EOF % [Travis::Worker::VirtualMachine.config[:username], Travis::Worker::VirtualMachine.config[:password]])
#!/bin/bash
#curl -X POST -d '{"message":"Interactive runner started"}' $GUEST_API_URL/logs
WIN_HOME_DIR=`cygpath -adw ~`
PS1_FILE=$WIN_HOME_DIR\\\\run_pswrapper.ps1

/cygdrive/c/Tools/PsExec.exe -u "%s" -p "%s" -acceptEula -h -i 1 powershell -file "$PS1_FILE" 2>/dev/null >/dev/null

if [ -f ~/build.sh.exit ] ; then
exit $(cat ~/build.sh.exit)
else
echo "Runner script was probably not executed, returning 1";
exit 1;
fi

EOF

session.upload_file("~/run_pswrapper.ps1", <<EOF % guest_api_url)
$GUEST_API_URL="%s";
[System.Reflection.Assembly]::LoadWithPartialName("System.Net");
[System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions");
$ser = New-Object System.Web.Script.Serialization.JavaScriptSerializer;

$json = $ser.serialize(@{message= "`n`nMinttyRunner started`n`n"});
$bytes = [System.Text.Encoding]::ASCII.GetBytes($json);
$cl = new-object System.Net.WebClient;
$cl.uploaddata("$GUEST_API_URL/logs", $bytes);

$p = new-object system.diagnostics.process;
$p.StartInfo.UseShellExecute = $false;
$p.StartInfo.CreateNoWindow = $true;
$p.StartInfo.FileName = "c:\\cygwin\\bin\\mintty.exe";
$p.StartInfo.Arguments = "-l - --exec /bin/bash -l -c 'exec /bin/bash ~/build.sh'";
$p.StartInfo.RedirectStandardError = $p.StartInfo.RedirectStandardOutput = $true;

$block = {
try
{
$hash = @{message = $event.SourceEventArgs.Data};
$json = $ser.Serialize($hash);
$cl = new-object System.Net.WebClient;
$bytes = [System.Text.Encoding]::ASCII.GetBytes($json);
$cl.uploaddata("$GUEST_API_URL/logs", $bytes);
}
catch
{
}
}

Register-ObjectEvent -InputObject $p -EventName OutputDataReceived -Action $block -SourceIdentifier OutputReader | Out-Null;
$p.Start() | out-null;
$p.BeginOutputReadLine();
while(-not $p.HasExited)
{
sleep 1;
};
if($p.StandardError -ne $null)
{
$p.StandardError.ReadToEnd()|Out-Host;
};
Unregister-Event -SourceIdentifier OutputReader;
$p.WaitForExit();

$json = $ser.serialize(@{message= "`n`nMinttyRunner finished`n`n"});
$bytes = [System.Text.Encoding]::ASCII.GetBytes($json);
$cl = new-object System.Net.WebClient;
$cl.uploaddata("$GUEST_API_URL/logs", $bytes);

exit $($p.ExitCode);

EOF
session.exec("GUEST_API_URL=%s bash --login ~/build_wrapper.sh" % guest_api_url) { exit_exec? }
else
session.exec("GUEST_API_URL=%s bash --login ~/build.sh" % guest_api_url) { exit_exec? }
end
Expand Down
5 changes: 5 additions & 0 deletions lib/travis/worker/virtual_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ def self.provider
self.const_get(provider_name)
end
end

def self.config
provider_name = Travis::Worker.config.vms.provider
Travis::Worker.config.send(provider_name.to_sym)
end
end
end
end
13 changes: 5 additions & 8 deletions lib/travis/worker/virtual_machine/soap_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ def vm_names

log_header { "#{name}:worker:virtual_machine:soap_provider" }

attr_reader :name, :ip, :endpoint, :vm
attr_reader :name, :ip, :endpoint, :vm, :client

def initialize(name)
@name = name
end

def prepare
info "soap API adapter prepared"
@client = Savon.client(client_config)
end

def sandboxed(opts = {})
Expand Down Expand Up @@ -108,7 +109,7 @@ def soap_config
end

def client_config
raise "soap.service_endpoint must be specified!" if soap_config.service_endpoint.blank?
raise "soap.service_endpoint must be specified!" if soap_config.service_endpoint.blank?
res = {
env_namespace: :s,
namespace_identifier: nil,
Expand All @@ -121,18 +122,14 @@ def client_config
res
end

def client
@client ||= Savon.client(client_config)
end

def template_name(opts)
if soap_config.image_override
soap_config.image_override
else
raise "Could not construct templateName, dist field must not be empty" unless opts[:dist]

[ soap_config.template_name_prefix,
opts[:dist],
[ soap_config.template_name_prefix,
opts[:dist],
opts[:group]
].select(&:present?).join('_')
end
Expand Down