This patch continues the move to attempt to merge the build.Options struct into the controllerapi.Options message. To do this, we extract all the input parameters into a dedicated message (adding the missing ones, except for the InStream parameter which will require some additional fiddling around). We also rework the NamedContexts to allow containing States (by transmitting them as DefinitionOps), and adding a Linked field to the common options. Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
30 lines
850 B
Go
30 lines
850 B
Go
package buildflags
|
|
|
|
import (
|
|
"strings"
|
|
|
|
controllerapi "github.com/docker/buildx/controller/pb"
|
|
"github.com/docker/distribution/reference"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func ParseContextNames(values []string) (map[string]*controllerapi.NamedContext, error) {
|
|
if len(values) == 0 {
|
|
return nil, nil
|
|
}
|
|
result := make(map[string]*controllerapi.NamedContext, len(values))
|
|
for _, value := range values {
|
|
kv := strings.SplitN(value, "=", 2)
|
|
if len(kv) != 2 {
|
|
return nil, errors.Errorf("invalid context value: %s, expected key=value", value)
|
|
}
|
|
named, err := reference.ParseNormalizedNamed(kv[0])
|
|
if err != nil {
|
|
return nil, errors.Wrapf(err, "invalid context name %s", kv[0])
|
|
}
|
|
name := strings.TrimSuffix(reference.FamiliarString(named), ":latest")
|
|
result[name] = &controllerapi.NamedContext{Path: kv[1]}
|
|
}
|
|
return result, nil
|
|
}
|