Esempio n. 1
0
// Find a best match for docker authentication
// Docker's config is a bunch of special-cases, try to cover most of them here.
// TODO: This may not work at all when we switch to a private V2 registry
func findAuth(registry string) docker.AuthConfiguration {
	// Ignore the error. If .dockercfg doesn't exist, maybe we don't need auth
	auths, _ := docker.NewAuthConfigurationsFromDockerCfg()
	if auths == nil || auths.Configs == nil {
		return docker.AuthConfiguration{}
	}

	auth, ok := auths.Configs[registry]
	if ok {
		return auth
	}
	// no exact match, so let's try harder

	// Docker only uses the hostname for private indexes
	for reg, auth := range auths.Configs {
		// extract the hostname if the key is a url
		if u, e := url.Parse(reg); e == nil && u.Host != "" {
			reg = u.Host
		}
		if registry == reg {
			return auth
		}
	}

	// Still no match
	// Try the default docker index server
	return auths.Configs[defaultIndexServer]
}
Esempio n. 2
0
// NewExecuteContext craetes a new empty ExecuteContext
func NewExecuteContext(
	config *config.Config,
	client client.DockerClient,
	execEnv *execenv.ExecEnv,
	quiet bool,
) *ExecuteContext {

	authConfigs, err := docker.NewAuthConfigurationsFromDockerCfg()
	if err != nil {
		logging.Log.Warnf("Failed to load auth config: %s", err)
	}

	return &ExecuteContext{
		modified:    make(map[task.Name]bool),
		Resources:   newResourceCollection(),
		WorkingDir:  config.WorkingDir,
		Client:      client,
		authConfigs: authConfigs,
		Env:         execEnv,
		Quiet:       quiet,
	}
}