func convertReal(backend internal.Docker2ACIBackend, dockerURL string, squash bool, outputDir string, tmpDir string, compression common.Compression) ([]string, error) { log.Debug("Getting image info...") ancestry, parsedDockerURL, err := backend.GetImageInfo(dockerURL) if err != nil { return nil, err } layersOutputDir := outputDir if squash { layersOutputDir, err = ioutil.TempDir(tmpDir, "docker2aci-") if err != nil { return nil, fmt.Errorf("error creating dir: %v", err) } defer os.RemoveAll(layersOutputDir) } conversionStore := newConversionStore() var images acirenderer.Images var aciLayerPaths []string var curPwl []string for i := len(ancestry) - 1; i >= 0; i-- { layerID := ancestry[i] // only compress individual layers if we're not squashing layerCompression := compression if squash { layerCompression = common.NoCompression } aciPath, manifest, err := backend.BuildACI(i, layerID, parsedDockerURL, layersOutputDir, tmpDir, curPwl, layerCompression) if err != nil { return nil, fmt.Errorf("error building layer: %v", err) } key, err := conversionStore.WriteACI(aciPath) if err != nil { return nil, fmt.Errorf("error inserting in the conversion store: %v", err) } images = append(images, acirenderer.Image{Im: manifest, Key: key, Level: uint16(i)}) aciLayerPaths = append(aciLayerPaths, aciPath) curPwl = manifest.PathWhitelist } // acirenderer expects images in order from upper to base layer images = util.ReverseImages(images) if squash { squashedImagePath, err := squashLayers(images, conversionStore, *parsedDockerURL, outputDir, compression) if err != nil { return nil, fmt.Errorf("error squashing image: %v", err) } aciLayerPaths = []string{squashedImagePath} } return aciLayerPaths, nil }
func (c *converter) convert() ([]string, error) { c.config.Debug.Println("Getting image info...") ancestry, parsedDockerURL, err := c.backend.GetImageInfo(c.dockerURL) if err != nil { return nil, err } layersOutputDir := c.config.OutputDir if c.config.Squash { layersOutputDir, err = ioutil.TempDir(c.config.TmpDir, "docker2aci-") if err != nil { return nil, fmt.Errorf("error creating dir: %v", err) } defer os.RemoveAll(layersOutputDir) } conversionStore := newConversionStore() // only compress individual layers if we're not squashing layerCompression := c.config.Compression if c.config.Squash { layerCompression = common.NoCompression } aciLayerPaths, aciManifests, err := c.backend.BuildACI(ancestry, parsedDockerURL, layersOutputDir, c.config.TmpDir, layerCompression) if err != nil { return nil, err } var images acirenderer.Images for i, aciLayerPath := range aciLayerPaths { key, err := conversionStore.WriteACI(aciLayerPath) if err != nil { return nil, fmt.Errorf("error inserting in the conversion store: %v", err) } images = append(images, acirenderer.Image{Im: aciManifests[i], Key: key, Level: uint16(len(aciLayerPaths) - 1 - i)}) } // acirenderer expects images in order from upper to base layer images = util.ReverseImages(images) if c.config.Squash { squashedImagePath, err := squashLayers(images, conversionStore, *parsedDockerURL, c.config.OutputDir, c.config.Compression, c.config.Debug) if err != nil { return nil, fmt.Errorf("error squashing image: %v", err) } aciLayerPaths = []string{squashedImagePath} } return aciLayerPaths, nil }