Skip to content
Merged
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
1 change: 1 addition & 0 deletions src/placeos-build/api/driver.cr
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ module PlaceOS::Build::Api
in Build::Compilation::NotFound
head code: :not_found
in Build::Compilation::Success
PlaceOS::Build.call_cloud_build_service(repository_uri, branch || "HEAD", file, commit, username: username, password: password)
path = builder.binary_store.path(result.executable)

response.content_type = "application/octet-stream"
Expand Down
35 changes: 1 addition & 34 deletions src/placeos-build/cli/build.cr
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
require "placeos-log-backend"
require "http/client"
require "uri"
require "http/headers"
require "../driver_store/s3"

module PlaceOS::Build
Expand Down Expand Up @@ -71,7 +68,7 @@ module PlaceOS::Build
password: password,
)
end
call_cloud_build_service(entrypoint, ref, username: username, password: password)
PlaceOS::Build.call_cloud_build_service(repository_uri, branch, entrypoint, ref, username: username, password: password)
rescue e
Log.warn(exception: e) { "failed to compile #{entrypoint}" }
end
Expand Down Expand Up @@ -107,36 +104,6 @@ module PlaceOS::Build
protected def self.is_driver?(path : Path)
!path.to_s.ends_with?("_spec.cr") && File.read_lines(path).any? &.includes?("< PlaceOS::Driver")
end

private def call_cloud_build_service(entrypoint, commit, username, password)
headers = HTTP::Headers.new
if token = BUILD_GIT_TOKEN
headers["X-Git-Token"] = token
elsif (user = username) && (pwd = password)
headers["X-Git-Username"] = user
headers["X-Git-Password"] = pwd
end
uri = URI.encode_www_form(entrypoint)
params = HTTP::Params{
"url" => repository_uri,
"branch" => branch,
"commit" => commit,
}

client = HTTP::Client.new(URI.parse(BUILD_SERVICE_URL))
begin
["amd64", "arm64"].each do |arch|
Log.debug { "Sending #{entrypoint} compilation request for architecture #{arch}" }
resp = client.post("/api/build/v1/#{arch}/#{uri}?#{params}", headers: headers)
unless resp.status_code == 202
Log.warn { "Compilation request for #{arch} returned status code #{resp.status_code}, while 202 expected" }
Log.debug { "Cloud build service returned with response: #{resp.body}" }
end
end
rescue e
Log.warn(exception: e) { "failed to invoke cloud build service #{entrypoint}" }
end
end
end
end
end
35 changes: 35 additions & 0 deletions src/placeos-build/cli/cloud_builder.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require "http/client"
require "uri"
require "http/headers"

module PlaceOS::Build
def self.call_cloud_build_service(repository_uri : String, branch : String, entrypoint : String, commit : String, username : String?, password : String?)
headers = HTTP::Headers.new
if token = BUILD_GIT_TOKEN
headers["X-Git-Token"] = token
elsif (user = username) && (pwd = password)
headers["X-Git-Username"] = user
headers["X-Git-Password"] = pwd
end
uri = URI.encode_www_form(entrypoint)
params = HTTP::Params{
"url" => repository_uri,
"branch" => branch,
"commit" => commit,
}

client = HTTP::Client.new(URI.parse(BUILD_SERVICE_URL))
begin
["amd64", "arm64"].each do |arch|
Log.debug { "Sending #{entrypoint} compilation request for architecture #{arch}" }
resp = client.post("/api/build/v1/#{arch}/#{uri}?#{params}", headers: headers)
unless resp.status_code == 202
Log.warn { "Compilation request for #{arch} returned status code #{resp.status_code}, while 202 expected" }
Log.debug { "Cloud build service returned with response: #{resp.body}" }
end
end
rescue e
Log.warn(exception: e) { "failed to invoke cloud build service #{entrypoint}" }
end
end
end