Skip to content

Commit f1b92e9

Browse files
committed
update Build commands to return dockerfile mapping for use in printing rule check warnings
Signed-off-by: Talon Bowler <[email protected]>
1 parent db11785 commit f1b92e9

File tree

14 files changed

+215
-122
lines changed

14 files changed

+215
-122
lines changed

build/build.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,19 @@ func toRepoOnly(in string) (string, error) {
147147
return strings.Join(out, ","), nil
148148
}
149149

150-
func Build(ctx context.Context, nodes []builder.Node, opt map[string]Options, docker *dockerutil.Client, configDir string, w progress.Writer) (resp map[string]*client.SolveResponse, err error) {
150+
func Build(ctx context.Context, nodes []builder.Node, opt map[string]Options, docker *dockerutil.Client, configDir string, w progress.Writer) (resp map[string]*client.SolveResponse, dockerfileMappings map[string]string, err error) {
151151
return BuildWithResultHandler(ctx, nodes, opt, docker, configDir, w, nil)
152152
}
153153

154-
func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[string]Options, docker *dockerutil.Client, configDir string, w progress.Writer, resultHandleFunc func(driverIndex int, rCtx *ResultHandle)) (resp map[string]*client.SolveResponse, err error) {
154+
func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[string]Options, docker *dockerutil.Client, configDir string, w progress.Writer, resultHandleFunc func(driverIndex int, rCtx *ResultHandle)) (resp map[string]*client.SolveResponse, dockerfileMappings map[string]string, err error) {
155+
dockerfileMappings = map[string]string{}
155156
if len(nodes) == 0 {
156-
return nil, errors.Errorf("driver required for build")
157+
return nil, nil, errors.Errorf("driver required for build")
157158
}
158159

159160
nodes, err = filterAvailableNodes(nodes)
160161
if err != nil {
161-
return nil, errors.Wrapf(err, "no valid drivers found")
162+
return nil, nil, errors.Wrapf(err, "no valid drivers found")
162163
}
163164

164165
var noMobyDriver *driver.DriverHandle
@@ -194,7 +195,7 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
194195

195196
drivers, err := resolveDrivers(ctx, nodes, opt, w)
196197
if err != nil {
197-
return nil, err
198+
return nil, nil, err
198199
}
199200

200201
defers := make([]func(), 0, 2)
@@ -227,21 +228,22 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
227228
opt.Platforms = np.platforms
228229
gatewayOpts, err := np.BuildOpts(ctx)
229230
if err != nil {
230-
return nil, err
231+
return nil, nil, err
231232
}
232-
so, release, err := toSolveOpt(ctx, np.Node(), multiDriver, opt, gatewayOpts, configDir, w, docker)
233+
so, release, dockerfileMapping, err := toSolveOpt(ctx, np.Node(), multiDriver, opt, gatewayOpts, configDir, w, docker)
233234
if err != nil {
234-
return nil, err
235+
return nil, nil, err
235236
}
236237
if err := saveLocalState(so, k, opt, np.Node(), configDir); err != nil {
237-
return nil, err
238+
return nil, nil, err
238239
}
239240
addGitAttrs(so)
240241
defers = append(defers, release)
241242
reqn = append(reqn, &reqForNode{
242243
resolvedNode: np,
243244
so: so,
244245
})
246+
dockerfileMappings[k+":"+dockerfileMapping.Dst] = dockerfileMapping.Src
245247
}
246248
reqForNodes[k] = reqn
247249
for _, at := range opt.Session {
@@ -260,7 +262,7 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
260262
for _, e := range np.so.Exports {
261263
if e.Type == "moby" {
262264
if ok, _ := strconv.ParseBool(e.Attrs["push"]); ok {
263-
return nil, errors.Errorf("multi-node push can't currently be performed with the docker driver, please switch to a different driver")
265+
return nil, nil, errors.Errorf("multi-node push can't currently be performed with the docker driver, please switch to a different driver")
264266
}
265267
}
266268
}
@@ -278,7 +280,7 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
278280
k2 := strings.TrimPrefix(v, "target:")
279281
dps2, ok := drivers[k2]
280282
if !ok {
281-
return nil, errors.Errorf("failed to find target %s for context %s", k2, strings.TrimPrefix(k, "context:")) // should be validated before already
283+
return nil, nil, errors.Errorf("failed to find target %s for context %s", k2, strings.TrimPrefix(k, "context:")) // should be validated before already
282284
}
283285
var found bool
284286
for _, dp2 := range dps2 {
@@ -288,7 +290,7 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
288290
}
289291
}
290292
if !found {
291-
return nil, errors.Errorf("failed to use %s as context %s for %s because targets build with different drivers", k2, strings.TrimPrefix(k, "context:"), name)
293+
return nil, nil, errors.Errorf("failed to use %s as context %s for %s because targets build with different drivers", k2, strings.TrimPrefix(k, "context:"), name)
292294
}
293295
}
294296
}
@@ -297,7 +299,7 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
297299

298300
sharedSessions, err := detectSharedMounts(ctx, reqForNodes)
299301
if err != nil {
300-
return nil, err
302+
return nil, nil, err
301303
}
302304
sharedSessionsWG := map[string]*sync.WaitGroup{}
303305

@@ -702,15 +704,15 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
702704
return nil
703705
}(k)
704706
if err != nil {
705-
return nil, err
707+
return nil, nil, err
706708
}
707709
}
708710

709711
if err := eg.Wait(); err != nil {
710-
return nil, err
712+
return nil, nil, err
711713
}
712714

713-
return resp, nil
715+
return resp, dockerfileMappings, nil
714716
}
715717

716718
func extractIndexAnnotations(exports []client.ExportEntry) (map[exptypes.AnnotationKey]string, error) {

0 commit comments

Comments
 (0)