2021-10-28 21:42:06 +00:00
|
|
|
// Copyright © 2021 Ettore Di Giacinto <mudler@gentoo.org>
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package image_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2021-10-31 09:39:07 +00:00
|
|
|
"runtime"
|
2021-10-28 21:42:06 +00:00
|
|
|
|
2021-12-17 14:21:03 +00:00
|
|
|
"github.com/mudler/luet/pkg/api/core/context"
|
2021-10-28 21:42:06 +00:00
|
|
|
. "github.com/mudler/luet/pkg/api/core/image"
|
|
|
|
"github.com/mudler/luet/pkg/api/core/types/artifact"
|
|
|
|
"github.com/mudler/luet/pkg/compiler/backend"
|
|
|
|
"github.com/mudler/luet/pkg/helpers/file"
|
2021-12-31 20:01:40 +00:00
|
|
|
. "github.com/onsi/ginkgo/v2"
|
2021-10-28 21:42:06 +00:00
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Create", func() {
|
|
|
|
Context("Creates an OCI image from a standard tar", func() {
|
|
|
|
It("creates an image which is loadable", func() {
|
2021-12-17 14:21:03 +00:00
|
|
|
ctx := context.NewContext()
|
2021-10-28 21:42:06 +00:00
|
|
|
|
2021-12-17 14:21:03 +00:00
|
|
|
dst, err := ctx.TempFile("dst")
|
2021-10-28 21:42:06 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
defer os.RemoveAll(dst.Name())
|
2021-12-17 14:21:03 +00:00
|
|
|
srcTar, err := ctx.TempFile("srcTar")
|
2021-10-28 21:42:06 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
defer os.RemoveAll(srcTar.Name())
|
|
|
|
|
|
|
|
b := backend.NewSimpleDockerBackend(ctx)
|
|
|
|
|
|
|
|
b.DownloadImage(backend.Options{ImageName: "alpine"})
|
|
|
|
img, err := b.ImageReference("alpine", false)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2021-11-10 14:12:54 +00:00
|
|
|
_, dir, err := Extract(ctx, img, nil)
|
2021-10-28 21:42:06 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
|
|
|
Expect(file.Touch(filepath.Join(dir, "test"))).ToNot(HaveOccurred())
|
|
|
|
Expect(file.Exists(filepath.Join(dir, "bin"))).To(BeTrue())
|
|
|
|
|
|
|
|
a := artifact.NewPackageArtifact(srcTar.Name())
|
|
|
|
a.Compress(dir, 1)
|
|
|
|
|
|
|
|
// Unfortunately there is no other easy way to test this
|
2021-10-31 09:39:07 +00:00
|
|
|
err = CreateTar(srcTar.Name(), dst.Name(), "testimage", runtime.GOARCH, runtime.GOOS)
|
2021-10-28 21:42:06 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
b.LoadImage(dst.Name())
|
|
|
|
|
|
|
|
Expect(b.ImageExists("testimage")).To(BeTrue())
|
|
|
|
|
|
|
|
img, err = b.ImageReference("testimage", false)
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
2021-11-10 14:12:54 +00:00
|
|
|
_, dir, err = Extract(ctx, img, nil)
|
2021-10-28 21:42:06 +00:00
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
Expect(file.Exists(filepath.Join(dir, "bin"))).To(BeTrue())
|
|
|
|
Expect(file.Exists(filepath.Join(dir, "test"))).To(BeTrue())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|