fixup: make sure the outputdir exists

This commit is contained in:
Ettore Di Giacinto
2021-05-21 22:25:18 +02:00
parent e83f600ed3
commit 27c2e3c51f

View File

@@ -793,10 +793,15 @@ func (cs *LuetCompiler) resolveJoinImages(concurrency int, keepPermissions bool,
} }
Info("Generating image with hash ", image) Info("Generating image with hash ", image)
// Make sure there is an output path
if err := os.MkdirAll(p.GetOutputPath(), os.ModePerm); err != nil {
return errors.Wrap(err, "while creating output path")
}
// otherwise, generate it and push it aside // otherwise, generate it and push it aside
joinDir, err := ioutil.TempDir(p.GetOutputPath(), "join") joinDir, err := ioutil.TempDir(p.GetOutputPath(), "join")
if err != nil { if err != nil {
return errors.Wrap(err, "Could not create tempdir") return errors.Wrap(err, "could not create tempdir for joining images")
} }
defer os.RemoveAll(joinDir) // clean up defer os.RemoveAll(joinDir) // clean up
@@ -822,7 +827,7 @@ func (cs *LuetCompiler) resolveJoinImages(concurrency int, keepPermissions bool,
artifactDir, err := ioutil.TempDir(p.GetOutputPath(), "artifact") artifactDir, err := ioutil.TempDir(p.GetOutputPath(), "artifact")
if err != nil { if err != nil {
return errors.Wrap(err, "Could not create tempdir") return errors.Wrap(err, "could not create tempdir for final artifact")
} }
defer os.RemoveAll(joinDir) // clean up defer os.RemoveAll(joinDir) // clean up
@@ -830,13 +835,13 @@ func (cs *LuetCompiler) resolveJoinImages(concurrency int, keepPermissions bool,
// no need to compress, as we are going to toss it away. // no need to compress, as we are going to toss it away.
a := artifact.NewPackageArtifact(filepath.Join(artifactDir, p.GetPackage().GetFingerPrint()+".join.tar")) a := artifact.NewPackageArtifact(filepath.Join(artifactDir, p.GetPackage().GetFingerPrint()+".join.tar"))
if err := a.Compress(joinDir, concurrency); err != nil { if err := a.Compress(joinDir, concurrency); err != nil {
return errors.Wrap(err, "Error met while creating package archive") return errors.Wrap(err, "error met while creating package archive")
} }
joinImageName := fmt.Sprintf("%s:%s", cs.Options.PushImageRepository, overallFp) joinImageName := fmt.Sprintf("%s:%s", cs.Options.PushImageRepository, overallFp)
opts, err := a.GenerateFinalImage(joinImageName, cs.Backend, keepPermissions) opts, err := a.GenerateFinalImage(joinImageName, cs.Backend, keepPermissions)
if err != nil { if err != nil {
return errors.Wrap(err, "Could not create tempdir") return errors.Wrap(err, "could not create final image")
} }
if cs.Options.Push { if cs.Options.Push {
if err = cs.Backend.Push(opts); err != nil { if err = cs.Backend.Push(opts); err != nil {