Skip to content
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
22 changes: 22 additions & 0 deletions lib/proto/health.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
syntax = "proto3";

package grpc.health.v1;

message HealthCheckRequest {
string service = 1;
}

message HealthCheckResponse {
enum ServingStatus {
UNKNOWN = 0;
SERVING = 1;
NOT_SERVING = 2;
SERVICE_UNKNOWN = 3;
}
ServingStatus status = 1;
}

service Health {
rpc Check(HealthCheckRequest) returns (HealthCheckResponse);
rpc Watch(HealthCheckRequest) returns (stream HealthCheckResponse);
}
20 changes: 20 additions & 0 deletions lib/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,26 @@ function withSession(docker, auth, handler) {
},
});

// BuildKit health-checks the session's gRPC connection (grpc.health.v1.Health/Check)
// and tears the session down after a couple of consecutive failed checks
// (moby/buildkit session/grpc.go). Without a Health service the check returns
// UNIMPLEMENTED, so BuildKit drops the session before the build's first vertex and
// the build stalls (typically at "load metadata for <base image>"). Serve SERVING so
// the session stays up for the lifetime of the build.
const healthPkg = protoLoader.loadSync(
path.resolve(__dirname, "proto", "health.proto")
);
const healthService = grpc.loadPackageDefinition(healthPkg);

server.addService(healthService.grpc.health.v1.Health.service, {
Check(call, callback) {
callback(null, { status: "SERVING" });
},
Watch(call) {
call.write({ status: "SERVING" });
},
});

function done() {
server.forceShutdown();
socket.end();
Expand Down