mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-09 21:17:09 +08:00
Enable to restore build options from the server
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
This commit is contained in:
@ -74,6 +74,9 @@ func (c *Client) List(ctx context.Context) (keys []string, retErr error) {
|
||||
}
|
||||
|
||||
func (c *Client) Disconnect(ctx context.Context, key string) error {
|
||||
if key == "" {
|
||||
return nil
|
||||
}
|
||||
_, err := c.client().Disconnect(ctx, &pb.DisconnectRequest{Ref: key})
|
||||
return err
|
||||
}
|
||||
@ -107,6 +110,10 @@ func (c *Client) Invoke(ctx context.Context, ref string, pid string, invokeConfi
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Client) Inspect(ctx context.Context, ref string) (*pb.InspectResponse, error) {
|
||||
return c.client().Inspect(ctx, &pb.InspectRequest{Ref: ref})
|
||||
}
|
||||
|
||||
func (c *Client) Build(ctx context.Context, options pb.BuildOptions, in io.ReadCloser, w io.Writer, out console.File, progressMode string) (string, *client.SolveResponse, error) {
|
||||
ref := identity.NewID()
|
||||
pw, err := progress.NewPrinter(context.TODO(), w, out, progressMode)
|
||||
|
@ -38,6 +38,7 @@ type session struct {
|
||||
buildOnGoing atomic.Bool
|
||||
statusChan chan *client.SolveStatus
|
||||
cancelBuild func()
|
||||
buildOptions *pb.BuildOptions
|
||||
inputPipe *io.PipeWriter
|
||||
|
||||
result *build.ResultContext
|
||||
@ -113,6 +114,9 @@ func (m *Server) Disconnect(ctx context.Context, req *pb.DisconnectRequest) (res
|
||||
s.cancelBuild()
|
||||
}
|
||||
s.cancelRunningProcesses()
|
||||
if s.result != nil {
|
||||
s.result.Done()
|
||||
}
|
||||
}
|
||||
delete(m.session, key)
|
||||
m.sessionMu.Unlock()
|
||||
@ -134,6 +138,23 @@ func (m *Server) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Server) Inspect(ctx context.Context, req *pb.InspectRequest) (*pb.InspectResponse, error) {
|
||||
ref := req.Ref
|
||||
if ref == "" {
|
||||
return nil, errors.New("inspect: empty key")
|
||||
}
|
||||
var bo *pb.BuildOptions
|
||||
m.sessionMu.Lock()
|
||||
if s, ok := m.session[ref]; ok {
|
||||
bo = s.buildOptions
|
||||
} else {
|
||||
m.sessionMu.Unlock()
|
||||
return nil, errors.Errorf("inspect: unknown key %v", ref)
|
||||
}
|
||||
m.sessionMu.Unlock()
|
||||
return &pb.InspectResponse{Options: bo}, nil
|
||||
}
|
||||
|
||||
func (m *Server) Build(ctx context.Context, req *pb.BuildRequest) (*pb.BuildResponse, error) {
|
||||
ref := req.Ref
|
||||
if ref == "" {
|
||||
|
Reference in New Issue
Block a user