75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/reemo.rb', line 75
def run_()
is_developping = options[:develop]
if is_developping
puts("==== DEVELOP OPTION IS ON ====")
end
if !File.exists?(GLOBAL_CONFIG_YAML_PATH)
STDERR.puts <<EOS
Error: Configure not found
You should configure server setting like the following.
$ reemo server-config --host=hogehoge.io --http-port=4567 --ssh-port=2222
EOS
exit(1)
end
config_yaml_map = YAML::load_file(GLOBAL_CONFIG_YAML_PATH)
host = config_yaml_map["server"]["host"]
http_port = config_yaml_map["server"]["http_port"]
ssh_port = config_yaml_map["server"]["ssh_port"]
url = URI.parse("http://#{host}:#{http_port}/build")
if !Dir.exists?(CONFIG_DIR_PATH)
Dir.mkdir(CONFIG_DIR_PATH)
end
session_id = nil
old_session_id = File.exists?(OLD_SESSION_ID_FILE_PATH)? File.read(OLD_SESSION_ID_FILE_PATH) : nil
Tempfile.open(){|tar_gz_f|
workspace_tar_gz_path = tar_gz_f.path
Zlib::GzipWriter.open(tar_gz_f){|sgz|
Archive::Tar::Minitar::Output.open(sgz){|tar|
ignore_file_path = IGNORE_FILE_NAME
all_file_paths = Dir.glob("**/*", File::FNM_DOTMATCH).reject{|e| [".",".."].any?{|s| s== File::basename(e)}}
if File.exists?(ignore_file_path)
ignore = Buff::Ignore::IgnoreFile.new(IGNORE_FILE_NAME)
file_paths = ignore.apply(all_file_paths)
else
file_paths = all_file_paths
end
file_paths.each{|entry|
Minitar.pack_file(entry, tar)
}
}
}
tar_gz_f.close()
File.open(workspace_tar_gz_path, 'rb') do |f|
req = Net::HTTP::Post::Multipart.new(
url.path,
"file" => UploadIO.new(f, "application/tar+gzip", "dummy.tar.gz"),
"old_session_id" => old_session_id
)
res = Net::HTTP.start(url.host, url.port) do |http|
http.request(req)
end
session_id = res.entity
end
}
if is_developping
puts("Session ID: #{session_id}")
end
File.write(OLD_SESSION_ID_FILE_PATH, session_id)
user_name = session_id
ssh_command = "ssh -t -p #{ssh_port} #{user_name}@#{host}"
system(ssh_command)
open("http://#{host}:#{http_port}/output?session_id=#{session_id}"){|f|
Tempfile.open(){|tmp_out_f|
IO.copy_stream(f, tmp_out_f)
tmp_out_f.close()
if !File.zero?(tmp_out_f.path)
if !Dir.exists?(OUTPUT_DIR_PATH)
Dir.mkdir(OUTPUT_DIR_PATH)
end
system("tar xzf #{tmp_out_f.path} -C #{OUTPUT_DIR_PATH}/") end
}
}
end
|