-
Notifications
You must be signed in to change notification settings - Fork 3
/
out
executable file
·60 lines (41 loc) · 1.48 KB
/
out
1
2
3
4
5
6
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/ruby
require 'fileutils'
require 'json'
require 'rubygems'
$stdout = STDERR
input = JSON.load($stdin.read, nil, { symbolize_names: true, create_additions: false })
unless input[:source] && input[:source][:stage] && input[:source][:private_key] && input[:params] && input[:params][:path]
missing = []
missing << :stage unless input[:source][:stage]
missing << :private_key unless input[:source][:private_key]
missing << :path unless input[:params][:path]
puts("Missing required settings: #{missing.map{ |s| "'#{s}'" }.join(', ') }")
exit 1
end
private_key_path = '/tmp/capistrano-resource-private-key'
File.write(private_key_path, input[:source][:private_key])
File.chmod(0600, private_key_path)
output = %x| ssh-agent |
output.split("\n").each do |line|
assignment ,= line.split(';')
key, value = assignment.split('=')
ENV[key] = value
end
%x| DISPLAY= ssh-add #{private_key_path} > /dev/null |
current_dir = Dir.pwd
Dir.chdir("#{ARGV.first}/#{input[:params][:path]}")
gem 'bundler'
require 'bundler/cli'
Bundler::CLI.new(
[],
{ 'no-color': false, retry: 3, verbose: false },
{ current_command: Bundler::Thor::Command.new(:install, '', '', '') }
).invoke(:install)
Bundler::CLI.new(
[ 'cap', input[:source][:stage], 'deploy' ],
{ 'no-color': false, retry: 3, verbose: false },
{ current_command: Bundler::Thor::Command.new(:exec, '', '', '') }
).invoke(:exec)
Dir.chdir(current_dir)
$stdout = STDOUT
puts({ version: { ref: :none }, metadata: [] }.to_json)