// SquashLayers receives a list of ACI layer file names ordered from base image // to application image and squashes them into one ACI func SquashLayers(images []acirenderer.Image, aciRegistry acirenderer.ACIRegistry, parsedDockerURL types.ParsedDockerURL, outputDir string) (string, error) { util.Debug("Squashing layers...") util.Debug("Rendering ACI...") renderedACI, err := acirenderer.GetRenderedACIFromList(images, aciRegistry) if err != nil { return "", fmt.Errorf("error rendering squashed image: %v", err) } manifests, err := getManifests(renderedACI, aciRegistry) if err != nil { return "", fmt.Errorf("error getting manifests: %v", err) } squashedFilename := getSquashedFilename(parsedDockerURL) squashedImagePath := path.Join(outputDir, squashedFilename) squashedImageFile, err := os.Create(squashedImagePath) if err != nil { return "", err } defer squashedImageFile.Close() util.Debug("Writing squashed ACI...") if err := writeSquashedImage(squashedImageFile, renderedACI, aciRegistry, manifests); err != nil { return "", fmt.Errorf("error writing squashed image: %v", err) } util.Debug("Validating squashed ACI...") if err := common.ValidateACI(squashedImagePath); err != nil { return "", fmt.Errorf("error validating image: %v", err) } util.Debug("ACI squashed!") return squashedImagePath, nil }
// Given an already populated dependency list, it will extract, under the provided // directory, the rendered ACI func RenderACIFromList(imgs acirenderer.Images, dir string, ap acirenderer.ACIProvider, uidRange *user.UidRange) error { renderedACI, err := acirenderer.GetRenderedACIFromList(imgs, ap) if err != nil { return err } return renderImage(renderedACI, dir, ap, uidRange) }
// squashLayers receives a list of ACI layer file names ordered from base image // to application image and squashes them into one ACI func squashLayers(images []acirenderer.Image, aciRegistry acirenderer.ACIRegistry, parsedDockerURL types.ParsedDockerURL, outputDir string, compression common.Compression) (path string, err error) { log.Debug("Squashing layers...") log.Debug("Rendering ACI...") renderedACI, err := acirenderer.GetRenderedACIFromList(images, aciRegistry) if err != nil { return "", fmt.Errorf("error rendering squashed image: %v", err) } manifests, err := getManifests(renderedACI, aciRegistry) if err != nil { return "", fmt.Errorf("error getting manifests: %v", err) } squashedFilename := getSquashedFilename(parsedDockerURL) squashedImagePath := filepath.Join(outputDir, squashedFilename) squashedTempFile, err := ioutil.TempFile(outputDir, "docker2aci-squashedFile-") if err != nil { return "", err } defer func() { if err == nil { err = squashedTempFile.Close() } else { // remove temp file on error // we ignore its error to not mask the real error os.Remove(squashedTempFile.Name()) } }() log.Debug("Writing squashed ACI...") if err := writeSquashedImage(squashedTempFile, renderedACI, aciRegistry, manifests, compression); err != nil { return "", fmt.Errorf("error writing squashed image: %v", err) } log.Debug("Validating squashed ACI...") if err := internal.ValidateACI(squashedTempFile.Name()); err != nil { return "", fmt.Errorf("error validating image: %v", err) } if err := os.Rename(squashedTempFile.Name(), squashedImagePath); err != nil { return "", err } log.Debug("ACI squashed!") return squashedImagePath, nil }