Skip to content

Commit 4056d18

Browse files
Merge pull request #337 from depot/fix-buildx
2 parents 743e2b3 + 34fdf94 commit 4056d18

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ RUN \
1010
go build -ldflags="${LDFLAGS}" \
1111
-o /out/ ./cmd/...
1212

13-
FROM --platform=$TARGETPLATFORM ubuntu:20.04
13+
FROM ubuntu:24.04
1414

1515
RUN apt-get update && apt-get install -y ca-certificates curl && rm -rf /var/lib/apt/lists/*
1616
COPY entrypoint.sh /usr/bin/entrypoint.sh

pkg/cmd/buildctl/proxy.go

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"io"
7+
"log"
78
"net"
89
"net/url"
910
"os"
@@ -50,6 +51,8 @@ var (
5051
// buildx uses to get metadata like disk usage and build history.
5152
var builds atomic.Int64
5253

54+
const PROXY_DEBUG = false
55+
5356
func BuildkitdClient(ctx context.Context, conn net.Conn, buildkitdAddress string) (*grpc.ClientConn, error) {
5457
dialContext := func(context.Context, string) (net.Conn, error) {
5558
return conn, nil
@@ -78,13 +81,26 @@ func Proxy(ctx context.Context, conn net.Conn, acquireState func() *ProxyState,
7881
ctx, cancel := context.WithCancel(ctx)
7982
defer cancel()
8083

84+
var logger *log.Logger
85+
if PROXY_DEBUG {
86+
logFile, err := os.OpenFile("/var/log/proxy.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
87+
if err != nil {
88+
log.Printf("Failed to open proxy log file: %v", err)
89+
return
90+
}
91+
defer logFile.Close()
92+
logger = log.New(logFile, "", log.LstdFlags)
93+
} else {
94+
logger = log.New(io.Discard, "", log.LstdFlags)
95+
}
96+
8197
opts := []grpc.ServerOption{
8298
grpc.KeepaliveEnforcementPolicy(depot.LoadKeepaliveEnforcementPolicy()),
8399
grpc.KeepaliveParams(depot.LoadKeepaliveServerParams()),
84100
}
85101
server := grpc.NewServer(opts...)
86102

87-
control.RegisterControlServer(server, &ControlProxy{state: acquireState, platform: platform, cancel: cancel, status: status})
103+
control.RegisterControlServer(server, &ControlProxy{state: acquireState, platform: platform, cancel: cancel, status: status, logger: logger})
88104
gateway.RegisterLLBBridgeServer(server, &GatewayProxy{state: acquireState, platform: platform})
89105
trace.RegisterTraceServiceServer(server, &TracesProxy{state: acquireState})
90106
content.RegisterContentServer(server, &ContentProxy{state: acquireState})
@@ -112,9 +128,11 @@ type ControlProxy struct {
112128
status chan *client.SolveStatus
113129
platform string
114130
cancel context.CancelFunc
131+
logger *log.Logger
115132
}
116133

117134
func (p *ControlProxy) Prune(in *control.PruneRequest, toBuildx control.Control_PruneServer) error {
135+
p.logger.Printf("Prune called!\n")
118136
ctx := toBuildx.Context()
119137
md, ok := metadata.FromIncomingContext(ctx)
120138
if ok {
@@ -152,6 +170,7 @@ func (p *ControlProxy) Prune(in *control.PruneRequest, toBuildx control.Control_
152170
}
153171

154172
func (p *ControlProxy) Solve(ctx context.Context, in *control.SolveRequest) (*control.SolveResponse, error) {
173+
p.logger.Printf("Solve called!\n")
155174
if builds.Load() == 1 {
156175
return &control.SolveResponse{}, nil
157176
}
@@ -177,6 +196,7 @@ func (p *ControlProxy) Solve(ctx context.Context, in *control.SolveRequest) (*co
177196
}
178197

179198
func (p *ControlProxy) Status(in *control.StatusRequest, toBuildx control.Control_StatusServer) error {
199+
p.logger.Printf("Status called!\n")
180200
if builds.Load() == 1 {
181201
return nil
182202
}
@@ -261,6 +281,7 @@ func (p *ControlProxy) Status(in *control.StatusRequest, toBuildx control.Contro
261281
}
262282

263283
func (p *ControlProxy) Session(buildx control.Control_SessionServer) error {
284+
p.logger.Printf("Session called!\n")
264285
if builds.Load() == 1 {
265286
return nil
266287
}
@@ -310,6 +331,7 @@ func (p *ControlProxy) Session(buildx control.Control_SessionServer) error {
310331
// Those API calls would keep the builder alive, even if the user is not using it.
311332
// ListWorkers call is common among builds and those commands.
312333
func (p *ControlProxy) ListWorkers(ctx context.Context, in *control.ListWorkersRequest) (*control.ListWorkersResponse, error) {
334+
p.logger.Printf("ListWorkers called %d!\n", builds.Load())
313335
num := builds.Add(1)
314336
// When we get a second build request we know it is not an buildx metadata call such as disk usage.
315337
if num > 1 {
@@ -322,6 +344,9 @@ func (p *ControlProxy) ListWorkers(ctx context.Context, in *control.ListWorkersR
322344
md, ok := metadata.FromIncomingContext(ctx)
323345
if ok && !isOlderThanBuildx013(md.Get("user-agent")) {
324346
builds.Add(1)
347+
p.logger.Printf("new buildx detected, incremented builds to %d!\n", builds.Load())
348+
} else {
349+
p.logger.Printf("new buildx not detected, builds is %d!\n", builds.Load())
325350
}
326351

327352
return &control.ListWorkersResponse{
@@ -397,24 +422,30 @@ func (p *ControlProxy) scheduleShutdown() {
397422

398423
// Used by desktop. We ignore and shutdown.
399424
func (p *ControlProxy) DiskUsage(ctx context.Context, in *control.DiskUsageRequest) (*control.DiskUsageResponse, error) {
425+
p.logger.Printf("DiskUsage called!\n")
400426
p.scheduleShutdown()
401427
return &control.DiskUsageResponse{}, nil
402428
}
403429

404430
// Used by desktop. We ignore and shutdown.
405431
func (p *ControlProxy) Info(ctx context.Context, in *control.InfoRequest) (*control.InfoResponse, error) {
406-
p.scheduleShutdown()
407-
return nil, status.Errorf(codes.Unimplemented, "method Info not implemented")
432+
p.logger.Printf("Info called!\n")
433+
return &control.InfoResponse{BuildkitVersion: &worker.BuildkitVersion{
434+
Package: "buildkit",
435+
Version: "v0.13.2",
436+
Revision: "1234567890",
437+
}}, nil
408438
}
409439

410440
// Used by desktop. We ignore and shutdown.
411441
func (p *ControlProxy) ListenBuildHistory(in *control.BuildHistoryRequest, toBuildx control.Control_ListenBuildHistoryServer) error {
442+
p.logger.Printf("ListenBuildHistory called!\n")
412443
return status.Errorf(codes.Unimplemented, "method ListenBuildHistory not implemented")
413444
}
414445

415446
// Used by desktop. We ignore and shutdown.
416447
func (p *ControlProxy) UpdateBuildHistory(ctx context.Context, in *control.UpdateBuildHistoryRequest) (*control.UpdateBuildHistoryResponse, error) {
417-
p.scheduleShutdown()
448+
p.logger.Printf("UpdateBuildHistory called!\n")
418449
return &control.UpdateBuildHistoryResponse{}, nil
419450
}
420451

0 commit comments

Comments
 (0)