From b1f11af512f0abe614a62e02d4885bdf301e4f85 Mon Sep 17 00:00:00 2001 From: Mikhail Klementev Date: Sat, 17 Jun 2023 08:45:17 +0000 Subject: [PATCH] feat: implement container import --- cache/cache.go | 5 +++++ container/container.go | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/cache/cache.go b/cache/cache.go index ca95e93..0f06214 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -118,3 +118,8 @@ func PackageURL(dt distro.ID, orig string) (found bool, fileurl string) { found = true return } + +func ContainerURL(name string) (path string) { + path, _ = url.JoinPath(URL, "containers", fmt.Sprintf("%s.tar.gz", name)) + return +} diff --git a/container/container.go b/container/container.go index 6758cf6..0afe83f 100644 --- a/container/container.go +++ b/container/container.go @@ -79,6 +79,24 @@ func Images() (diis []Image, err error) { return } +func Import(path, name string) (err error) { + exist := Container{name: name}.Exist() + if exist && UseCache { + return + } + + cmd := exec.Command(Runtime, "import", path, name) + log.Debug().Msgf("%v", cmd) + + raw, err := cmd.CombinedOutput() + if err != nil { + log.Error().Err(err).Msg(string(raw)) + return + } + + return +} + type Volume struct { Src, Dest string }