Don't export unless needed

This commit is contained in:
Ettore Di Giacinto
2020-11-10 16:57:20 +01:00
parent 665261e526
commit 36c58307e2

View File

@@ -353,13 +353,14 @@ func (cs *LuetCompiler) compileWithImage(image, buildertaggedImage, packageImage
return nil, errors.Wrap(err, "Failed building image for "+runnerOpts.ImageName+" "+runnerOpts.DockerFileName) return nil, errors.Wrap(err, "Failed building image for "+runnerOpts.ImageName+" "+runnerOpts.DockerFileName)
} }
} }
if generateArtifact {
if err := cs.Backend.ExportImage(runnerOpts); err != nil {
return nil, errors.Wrap(err, "Failed exporting image")
}
if err := cs.Backend.ExportImage(runnerOpts); err != nil { if !cs.Options.KeepImageExport {
return nil, errors.Wrap(err, "Failed exporting image") defer os.Remove(runnerOpts.Destination)
} }
if !cs.Options.KeepImageExport {
defer os.Remove(runnerOpts.Destination)
} }
if cs.Options.Push && buildPackageImage { if cs.Options.Push && buildPackageImage {
@@ -378,18 +379,20 @@ func (cs *LuetCompiler) compileWithImage(image, buildertaggedImage, packageImage
unpack = true unpack = true
} }
rootfs, err := ioutil.TempDir(p.GetOutputPath(), "rootfs") if generateArtifact {
if err != nil { rootfs, err := ioutil.TempDir(p.GetOutputPath(), "rootfs")
return nil, errors.Wrap(err, "Could not create tempdir") if err != nil {
} return nil, errors.Wrap(err, "Could not create tempdir")
defer os.RemoveAll(rootfs) // clean up }
defer os.RemoveAll(rootfs) // clean up
// TODO: Compression and such // TODO: Compression and such
err = cs.Backend.ExtractRootfs(CompilerBackendOptions{ err = cs.Backend.ExtractRootfs(CompilerBackendOptions{
ImageName: packageImage, ImageName: packageImage,
SourcePath: runnerOpts.Destination, Destination: rootfs}, keepPermissions) SourcePath: runnerOpts.Destination, Destination: rootfs}, keepPermissions)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "Could not extract rootfs") return nil, errors.Wrap(err, "Could not extract rootfs")
}
} }
if !keepImg { if !keepImg {