github.com/pdmccormick/importable-docker-buildx@v0.0.0-20240426161518-e47091289030/controller/pb/progress.go (about)

     1  package pb
     2  
     3  import (
     4  	"github.com/docker/buildx/util/progress"
     5  	control "github.com/moby/buildkit/api/services/control"
     6  	"github.com/moby/buildkit/client"
     7  	"github.com/opencontainers/go-digest"
     8  )
     9  
    10  type writer struct {
    11  	ch chan<- *StatusResponse
    12  }
    13  
    14  func NewProgressWriter(ch chan<- *StatusResponse) progress.Writer {
    15  	return &writer{ch: ch}
    16  }
    17  
    18  func (w *writer) Write(status *client.SolveStatus) {
    19  	w.ch <- ToControlStatus(status)
    20  }
    21  
    22  func (w *writer) WriteBuildRef(target string, ref string) {
    23  	return
    24  }
    25  
    26  func (w *writer) ValidateLogSource(digest.Digest, interface{}) bool {
    27  	return true
    28  }
    29  
    30  func (w *writer) ClearLogSource(interface{}) {}
    31  
    32  func ToControlStatus(s *client.SolveStatus) *StatusResponse {
    33  	resp := StatusResponse{}
    34  	for _, v := range s.Vertexes {
    35  		resp.Vertexes = append(resp.Vertexes, &control.Vertex{
    36  			Digest:        v.Digest,
    37  			Inputs:        v.Inputs,
    38  			Name:          v.Name,
    39  			Started:       v.Started,
    40  			Completed:     v.Completed,
    41  			Error:         v.Error,
    42  			Cached:        v.Cached,
    43  			ProgressGroup: v.ProgressGroup,
    44  		})
    45  	}
    46  	for _, v := range s.Statuses {
    47  		resp.Statuses = append(resp.Statuses, &control.VertexStatus{
    48  			ID:        v.ID,
    49  			Vertex:    v.Vertex,
    50  			Name:      v.Name,
    51  			Total:     v.Total,
    52  			Current:   v.Current,
    53  			Timestamp: v.Timestamp,
    54  			Started:   v.Started,
    55  			Completed: v.Completed,
    56  		})
    57  	}
    58  	for _, v := range s.Logs {
    59  		resp.Logs = append(resp.Logs, &control.VertexLog{
    60  			Vertex:    v.Vertex,
    61  			Stream:    int64(v.Stream),
    62  			Msg:       v.Data,
    63  			Timestamp: v.Timestamp,
    64  		})
    65  	}
    66  	for _, v := range s.Warnings {
    67  		resp.Warnings = append(resp.Warnings, &control.VertexWarning{
    68  			Vertex: v.Vertex,
    69  			Level:  int64(v.Level),
    70  			Short:  v.Short,
    71  			Detail: v.Detail,
    72  			Url:    v.URL,
    73  			Info:   v.SourceInfo,
    74  			Ranges: v.Range,
    75  		})
    76  	}
    77  	return &resp
    78  }
    79  
    80  func FromControlStatus(resp *StatusResponse) *client.SolveStatus {
    81  	s := client.SolveStatus{}
    82  	for _, v := range resp.Vertexes {
    83  		s.Vertexes = append(s.Vertexes, &client.Vertex{
    84  			Digest:        v.Digest,
    85  			Inputs:        v.Inputs,
    86  			Name:          v.Name,
    87  			Started:       v.Started,
    88  			Completed:     v.Completed,
    89  			Error:         v.Error,
    90  			Cached:        v.Cached,
    91  			ProgressGroup: v.ProgressGroup,
    92  		})
    93  	}
    94  	for _, v := range resp.Statuses {
    95  		s.Statuses = append(s.Statuses, &client.VertexStatus{
    96  			ID:        v.ID,
    97  			Vertex:    v.Vertex,
    98  			Name:      v.Name,
    99  			Total:     v.Total,
   100  			Current:   v.Current,
   101  			Timestamp: v.Timestamp,
   102  			Started:   v.Started,
   103  			Completed: v.Completed,
   104  		})
   105  	}
   106  	for _, v := range resp.Logs {
   107  		s.Logs = append(s.Logs, &client.VertexLog{
   108  			Vertex:    v.Vertex,
   109  			Stream:    int(v.Stream),
   110  			Data:      v.Msg,
   111  			Timestamp: v.Timestamp,
   112  		})
   113  	}
   114  	for _, v := range resp.Warnings {
   115  		s.Warnings = append(s.Warnings, &client.VertexWarning{
   116  			Vertex:     v.Vertex,
   117  			Level:      int(v.Level),
   118  			Short:      v.Short,
   119  			Detail:     v.Detail,
   120  			URL:        v.Url,
   121  			SourceInfo: v.Info,
   122  			Range:      v.Ranges,
   123  		})
   124  	}
   125  	return &s
   126  }