Exemple #1
0
func (c *CommonConfig) initLogger() {
	if c.Info == nil {
		c.Info = log.NewStdLogger(os.Stderr)
	}

	if c.Debug == nil {
		c.Debug = log.NewNopLogger()
	}
}
Exemple #2
0
func runDocker2ACI(arg string) error {
	debug := log.NewNopLogger()
	info := log.NewStdLogger(os.Stderr)

	if flagDebug {
		debug = log.NewStdLogger(os.Stderr)
	}

	squash := !flagNoSquash

	var aciLayerPaths []string
	// try to convert a local file
	u, err := url.Parse(arg)
	if err != nil {
		return fmt.Errorf("error parsing argument: %v", err)
	}

	var compression common.Compression

	switch flagCompression {
	case "none":
		compression = common.NoCompression
	case "gzip":
		compression = common.GzipCompression
	default:
		return fmt.Errorf("unknown compression method: %s", flagCompression)
	}

	cfg := docker2aci.CommonConfig{
		Squash:      squash,
		OutputDir:   ".",
		TmpDir:      os.TempDir(),
		Compression: compression,
		Debug:       debug,
		Info:        info,
	}
	if u.Scheme == "docker" {
		if flagImage != "" {
			return fmt.Errorf("flag --image works only with files.")
		}
		dockerURL := strings.TrimPrefix(arg, "docker://")

		indexServer := docker2aci.GetIndexName(dockerURL)

		var username, password string
		username, password, err = docker2aci.GetDockercfgAuth(indexServer)
		if err != nil {
			return fmt.Errorf("error reading .dockercfg file: %v", err)
		}
		remoteConfig := docker2aci.RemoteConfig{
			CommonConfig: cfg,
			Username:     username,
			Password:     password,
			Insecure: common.InsecureConfig{
				SkipVerify: flagInsecureSkipVerify,
				AllowHTTP:  flagInsecureAllowHTTP,
			},
		}

		aciLayerPaths, err = docker2aci.ConvertRemoteRepo(dockerURL, remoteConfig)
	} else {
		fileConfig := docker2aci.FileConfig{
			CommonConfig: cfg,
			DockerURL:    flagImage,
		}
		aciLayerPaths, err = docker2aci.ConvertSavedFile(arg, fileConfig)
		if serr, ok := err.(*common.ErrSeveralImages); ok {
			err = fmt.Errorf("%s, use option --image with one of:\n\n%s", serr, strings.Join(serr.Images, "\n"))
		}
	}
	if err != nil {
		return fmt.Errorf("conversion error: %v", err)
	}

	// we get last layer's manifest, this will include all the elements in the
	// previous layers. If we're squashing, the last element of aciLayerPaths
	// will be the squashed image.
	manifest, err := getManifest(aciLayerPaths[len(aciLayerPaths)-1])
	if err != nil {
		return err
	}

	if err := printConvertedVolumes(*manifest); err != nil {
		return err
	}
	if err := printConvertedPorts(*manifest); err != nil {
		return err
	}

	fmt.Printf("\nGenerated ACI(s):\n")
	for _, aciFile := range aciLayerPaths {
		fmt.Println(aciFile)
	}

	return nil
}