Define Artifact diffs layers

It also add in simpledocker a naive implementation using the container-diff binary, which is supposed to go away with a proper API implementation.
This commit is contained in:
Ettore Di Giacinto
2019-11-09 13:58:15 +01:00
parent 1131a52f97
commit 45651a3bcc
5 changed files with 117 additions and 14 deletions

View File

@@ -16,6 +16,7 @@
package backend
import (
"encoding/json"
"os/exec"
"github.com/mudler/luet/pkg/compiler"
@@ -89,4 +90,25 @@ func (*SimpleImg) ExportImage(opts compiler.CompilerBackendOptions) error {
return nil
}
// TODO: Dup in docker, refactor common code in helpers for shared parts
// TODO: Use container-diff (https://github.com/GoogleContainerTools/container-diff) for checking out layer diffs
// Changes uses container-diff (https://github.com/GoogleContainerTools/container-diff) for retrieving out layer diffs
func (*SimpleImg) Changes(fromImage, toImage string) ([]compiler.ArtifactLayer, error) {
diffargs := []string{"diff", fromImage, toImage, "--type=file", "-j"}
Spinner(22)
defer SpinnerStop()
out, err := exec.Command("container-diff", diffargs...).CombinedOutput()
if err != nil {
return []compiler.ArtifactLayer{}, errors.Wrap(err, "Failed Resolving layer diffs: "+string(out))
}
var diffs []compiler.ArtifactLayer
err = json.Unmarshal(out, &diffs)
if err != nil {
return []compiler.ArtifactLayer{}, errors.Wrap(err, "Failed unmarshalling json response: "+string(out))
}
return diffs, nil
}