func copyForForward()

in frontend/gateway.go [171:220]


func copyForForward(ctx context.Context, client gwclient.Client) solveRequestOpt {
	return func(req *gwclient.SolveRequest) error {
		// Inputs are any additional build contexts or really any llb that the client sent along.
		inputs, err := client.Inputs(ctx)
		if err != nil {
			return err
		}

		if req.FrontendInputs == nil {
			req.FrontendInputs = make(map[string]*pb.Definition, len(inputs))
		}

		for k, v := range inputs {
			if _, ok := req.FrontendInputs[k]; ok {
				// Do not overwrite existing inputs
				continue
			}

			def, err := v.Marshal(ctx)
			if err != nil {
				return errors.Wrap(err, "error marshaling frontend input")
			}
			req.FrontendInputs[k] = def.ToPB()
		}

		opts := client.BuildOpts().Opts
		if req.FrontendOpt == nil {
			req.FrontendOpt = make(map[string]string, len(opts))
		}

		for k, v := range opts {

			if k == "filename" || k == "dockerfilekey" || k == "target" {
				// These are some well-known keys that the dockerfile frontend uses
				// which we'll be overriding with our own values (as needed) in the
				// caller.
				// Basically there should not be a need, nor is it desirable, to forward these along.
				continue
			}

			if _, ok := req.FrontendOpt[k]; ok {
				// Do not overwrite existing opts
				continue
			}
			req.FrontendOpt[k] = v
		}

		return nil
	}
}