1
0
Fork 0

chore: update docker and k8s

This commit is contained in:
Ludovic Fernandez 2019-08-05 18:24:03 +02:00 committed by Traefiker Bot
parent 2b5c7f9e91
commit c2d440a914
1283 changed files with 67741 additions and 27918 deletions

View file

@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"fmt"
"strconv"
"strings"
"reflect"
@ -11,6 +12,7 @@ import (
"github.com/docker/docker/pkg/urlutil"
"github.com/docker/libcompose/utils"
composeYaml "github.com/docker/libcompose/yaml"
"github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
)
@ -25,14 +27,37 @@ var (
}
)
// CreateConfig unmarshals bytes to config and creates config based on version
func getComposeMajorVersion(version string) (int, error) {
if version == "" {
return 1, nil
}
parts := strings.Split(version, ".")
if len(parts) == 1 {
return strconv.Atoi(version)
} else if len(parts) == 2 {
return strconv.Atoi(parts[0])
} else {
return -1, fmt.Errorf("Invalid version string, expected single integer or dot delimited int.int. Got: %s", version)
}
}
// CreateConfig unmarshals bytes of a YAML manifest file and returns a new
// Config. Initialize any defaults that can't be parsed (but are optional)
// across various file formats. Most of these can remain unused.
//
// This function only handles parsing YAML in the general case. Any other file
// format validation should be handled by the caller.
func CreateConfig(bytes []byte) (*Config, error) {
var config Config
if err := yaml.Unmarshal(bytes, &config); err != nil {
return nil, err
}
if config.Version != "2" {
major, err := getComposeMajorVersion(config.Version)
if err != nil {
return nil, err
}
if major < 2 {
var baseRawServices RawServiceMap
if err := yaml.Unmarshal(bytes, &baseRawServices); err != nil {
return nil, err
@ -102,14 +127,22 @@ func Merge(existingServices *ServiceConfigs, environmentLookup EnvironmentLookup
}
}
major, err := getComposeMajorVersion(config.Version)
if err != nil {
return "", nil, nil, nil, err
}
var serviceConfigs map[string]*ServiceConfig
if config.Version == "2" {
switch major {
case 3:
logrus.Fatal("Note: Compose file version 3 is not yet implemented")
case 2:
var err error
serviceConfigs, err = MergeServicesV2(existingServices, environmentLookup, resourceLookup, file, baseRawServices, options)
if err != nil {
return "", nil, nil, nil, err
}
} else {
default:
serviceConfigsV1, err := MergeServicesV1(existingServices, environmentLookup, resourceLookup, file, baseRawServices, options)
if err != nil {
return "", nil, nil, nil, err

View file

@ -219,7 +219,11 @@ var servicesSchemaDataV2 = `{
"properties": {
"context": {"type": "string"},
"dockerfile": {"type": "string"},
"args": {"$ref": "#/definitions/list_or_dict"}
"args": {"$ref": "#/definitions/list_or_dict"},
"cache_from": {"$ref": "#/definitions/list_of_strings"},
"labels": {"$ref": "#/definitions/list_or_dict"},
"network": {"type": "string"},
"target": {"type": "string"}
},
"additionalProperties": false
}

View file

@ -32,15 +32,19 @@ type (
portsFormatChecker struct{}
)
func (checker environmentFormatChecker) IsFormat(input string) bool {
func (checker environmentFormatChecker) IsFormat(input interface{}) bool {
// If the value is a boolean, a warning should be given
// However, we can't determine type since gojsonschema converts the value to a string
// Adding a function with an interface{} parameter to gojsonschema is probably the best way to handle this
return true
}
func (checker portsFormatChecker) IsFormat(input string) bool {
_, _, err := nat.ParsePortSpecs([]string{input})
func (checker portsFormatChecker) IsFormat(input interface{}) bool {
in, ok := input.(string)
if !ok {
return true
}
_, _, err := nat.ParsePortSpecs([]string{in})
return err == nil
}

View file

@ -201,7 +201,7 @@ func generateErrorMessages(serviceMap RawServiceMap, schema map[string]interface
if err.Context().String() == "(root)" {
switch err.Type() {
case "additional_property_not_allowed":
validationErrors = append(validationErrors, fmt.Sprintf("Invalid service name '%s' - only [a-zA-Z0-9\\._\\-] characters are allowed", err.Field()))
validationErrors = append(validationErrors, fmt.Sprintf("Invalid service name '%s' - only [a-zA-Z0-9\\._\\-] characters are allowed", err.Details()["property"]))
default:
validationErrors = append(validationErrors, err.Description())
}
@ -213,7 +213,7 @@ func generateErrorMessages(serviceMap RawServiceMap, schema map[string]interface
switch err.Type() {
case "additional_property_not_allowed":
validationErrors = append(validationErrors, unsupportedConfigMessage(key, result.Errors()[i+1]))
validationErrors = append(validationErrors, unsupportedConfigMessage(result.Errors()[i].Details()["property"].(string), result.Errors()[i]))
case "number_one_of":
validationErrors = append(validationErrors, fmt.Sprintf("Service '%s' configuration key '%s' %s", serviceName, key, oneOfMessage(serviceMap, schema, err, result.Errors()[i+1])))

View file

@ -2,6 +2,7 @@ package auth
import (
"github.com/docker/cli/cli/config/configfile"
clitypes "github.com/docker/cli/cli/config/types"
"github.com/docker/docker/api/types"
"github.com/docker/docker/registry"
)
@ -29,7 +30,7 @@ func (c *ConfigLookup) Lookup(repoInfo *registry.RepositoryInfo) types.AuthConfi
if c.ConfigFile == nil || repoInfo == nil || repoInfo.Index == nil {
return types.AuthConfig{}
}
return registry.ResolveAuthConfig(c.ConfigFile.AuthConfigs, repoInfo.Index)
return registry.ResolveAuthConfig(convert(c.ConfigFile.AuthConfigs), repoInfo.Index)
}
// All uses a Docker config file to get all authentication information
@ -37,5 +38,25 @@ func (c *ConfigLookup) All() map[string]types.AuthConfig {
if c.ConfigFile == nil {
return map[string]types.AuthConfig{}
}
return c.ConfigFile.AuthConfigs
return convert(c.ConfigFile.AuthConfigs)
}
func convert(acs map[string]clitypes.AuthConfig) map[string]types.AuthConfig {
if acs == nil {
return nil
}
result := map[string]types.AuthConfig{}
for k, v := range acs {
result[k] = types.AuthConfig{
Username: v.Username,
Password: v.Password,
Auth: v.Auth,
Email: v.Email,
ServerAddress: v.ServerAddress,
IdentityToken: v.IdentityToken,
RegistryToken: v.RegistryToken,
}
}
return result
}

View file

@ -43,6 +43,9 @@ type DaemonBuilder struct {
Pull bool
BuildArgs map[string]*string
CacheFrom []string
Labels map[string]*string
Network string
Target string
LoggerFactory logger.Factory
}
@ -88,6 +91,12 @@ func (d *DaemonBuilder) Build(ctx context.Context, imageName string) error {
outFd, isTerminalOut = term.GetFdInfo(w)
}
// Convert map[string]*string to map[string]string
labels := make(map[string]string)
for lk, lv := range d.Labels {
labels[lk] = *lv
}
response, err := d.Client.ImageBuild(ctx, body, types.ImageBuildOptions{
Tags: []string{imageName},
NoCache: d.NoCache,
@ -98,6 +107,9 @@ func (d *DaemonBuilder) Build(ctx context.Context, imageName string) error {
AuthConfigs: d.AuthConfigs,
BuildArgs: d.BuildArgs,
CacheFrom: d.CacheFrom,
Labels: labels,
NetworkMode: d.Network,
Target: d.Target,
})
if err != nil {
return err
@ -157,10 +169,7 @@ func CreateTar(contextDirectory, dockerfile string) (io.ReadCloser, error) {
}
// And canonicalize dockerfile name to a platform-independent one
dockerfileName, err = archive.CanonicalTarNameForPath(dockerfileName)
if err != nil {
return nil, fmt.Errorf("Cannot canonicalize dockerfile path %s: %v", dockerfileName, err)
}
dockerfileName = archive.CanonicalTarNameForPath(dockerfileName)
if _, err = os.Lstat(filename); os.IsNotExist(err) {
return nil, fmt.Errorf("Cannot locate Dockerfile: %s", origDockerfile)

View file

@ -10,7 +10,6 @@ import (
cliconfig "github.com/docker/cli/cli/config"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/homedir"
"github.com/docker/go-connections/sockets"
"github.com/docker/go-connections/tlsconfig"
"github.com/docker/libcompose/version"
)
@ -87,27 +86,23 @@ func Create(c Options) (client.APIClient, error) {
if err != nil {
return nil, err
}
tr := &http.Transport{
TLSClientConfig: config,
}
proto, addr, _, err := client.ParseHost(c.Host)
if err != nil {
return nil, err
}
if err := sockets.ConfigureTransport(tr, proto, addr); err != nil {
return nil, err
}
httpClient = &http.Client{
Transport: tr,
Transport: &http.Transport{
TLSClientConfig: config,
},
}
}
customHeaders := map[string]string{}
customHeaders["User-Agent"] = fmt.Sprintf("Libcompose-Client/%s (%s)", version.VERSION, runtime.GOOS)
client, err := client.NewClient(c.Host, apiVersion, httpClient, customHeaders)
client, err := client.NewClientWithOpts(
client.WithHTTPClient(httpClient),
client.WithHost(c.Host),
client.WithVersion(apiVersion),
client.WithHTTPHeaders(customHeaders),
)
if err != nil {
return nil, err
}

View file

@ -411,6 +411,20 @@ func (s *Service) NetworkConnect(ctx context.Context, c *container.Container, ne
aliases = []string{s.Name()}
}
aliases = append(aliases, net.Aliases...)
if len(net.Aliases) >= 1 {
logrus.Infof("connect")
client.NetworkConnect(ctx, net.RealName, containerID, &network.EndpointSettings{
Aliases: aliases,
Links: links,
IPAddress: net.IPv4Address,
IPAMConfig: &network.EndpointIPAMConfig{
IPv4Address: net.IPv4Address,
IPv6Address: net.IPv6Address,
},
})
logrus.Infof("disconnect")
client.NetworkDisconnect(ctx, net.RealName, containerID, true)
}
return client.NetworkConnect(ctx, net.RealName, containerID, &network.EndpointSettings{
Aliases: aliases,
Links: links,

View file

@ -68,7 +68,7 @@ func (v *Volume) EnsureItExists(ctx context.Context) error {
func (v *Volume) create(ctx context.Context) error {
fmt.Printf("Creating volume %q with driver %q\n", v.fullName(), v.driver)
_, err := v.client.VolumeCreate(ctx, volume.VolumesCreateBody{
_, err := v.client.VolumeCreate(ctx, volume.VolumeCreateBody{
Name: v.fullName(),
Driver: v.driver,
DriverOpts: v.driverOptions,

View file

@ -13,6 +13,12 @@ type Build struct {
Context string
Dockerfile string
Args map[string]*string
CacheFrom []*string
Labels map[string]*string
// TODO: ShmSize (can be a string or int?) for v3.5
Target string
// Note: as of Sep 2018 this is undocumented but supported by docker-compose
Network string
}
// MarshalYAML implements the Marshaller interface.
@ -27,6 +33,18 @@ func (b Build) MarshalYAML() (interface{}, error) {
if len(b.Args) > 0 {
m["args"] = b.Args
}
if len(b.CacheFrom) > 0 {
m["cache_from"] = b.CacheFrom
}
if len(b.Labels) > 0 {
m["labels"] = b.Labels
}
if b.Target != "" {
m["target"] = b.Target
}
if b.Network != "" {
m["network"] = b.Network
}
return m, nil
}
@ -52,6 +70,22 @@ func (b *Build) UnmarshalYAML(unmarshal func(interface{}) error) error {
return err
}
b.Args = args
case "cache_from":
cacheFrom, err := handleBuildCacheFrom(mapValue)
if err != nil {
return err
}
b.CacheFrom = cacheFrom
case "labels":
labels, err := handleBuildLabels(mapValue)
if err != nil {
return err
}
b.Labels = labels
case "target":
b.Target = mapValue.(string)
case "network":
b.Network = mapValue.(string)
default:
// Ignore unknown keys
continue
@ -67,15 +101,44 @@ func handleBuildArgs(value interface{}) (map[string]*string, error) {
var args map[string]*string
switch v := value.(type) {
case map[interface{}]interface{}:
return handleBuildArgMap(v)
return handleBuildOptionMap(v)
case []interface{}:
return handleBuildArgSlice(v)
return handleBuildArgsSlice(v)
default:
return args, fmt.Errorf("Failed to unmarshal Build args: %#v", value)
}
}
func handleBuildArgSlice(s []interface{}) (map[string]*string, error) {
func handleBuildCacheFrom(value interface{}) ([]*string, error) {
var cacheFrom []*string
switch v := value.(type) {
case []interface{}:
return handleBuildCacheFromSlice(v)
default:
return cacheFrom, fmt.Errorf("Failed to unmarshal Build cache_from: %#v", value)
}
}
func handleBuildLabels(value interface{}) (map[string]*string, error) {
var labels map[string]*string
switch v := value.(type) {
case map[interface{}]interface{}:
return handleBuildOptionMap(v)
default:
return labels, fmt.Errorf("Failed to unmarshal Build labels: %#v", value)
}
}
func handleBuildCacheFromSlice(s []interface{}) ([]*string, error) {
var args = []*string{}
for _, arg := range s {
strArg := arg.(string)
args = append(args, &strArg)
}
return args, nil
}
func handleBuildArgsSlice(s []interface{}) (map[string]*string, error) {
var args = map[string]*string{}
for _, arg := range s {
// check if a value is provided
@ -93,7 +156,8 @@ func handleBuildArgSlice(s []interface{}) (map[string]*string, error) {
return args, nil
}
func handleBuildArgMap(m map[interface{}]interface{}) (map[string]*string, error) {
// Used for args and labels
func handleBuildOptionMap(m map[interface{}]interface{}) (map[string]*string, error) {
args := map[string]*string{}
for mapKey, mapValue := range m {
var argValue string