Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-arch OCI-repo support #303

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions pkg/api/core/image/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ import (
"path/filepath"
"runtime"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/mudler/luet/pkg/api/core/context"
. "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"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("Create", func() {
Expand All @@ -43,8 +44,9 @@ var _ = Describe("Create", func() {

b := backend.NewSimpleDockerBackend(ctx)

b.DownloadImage(backend.Options{ImageName: "alpine"})
img, err := b.ImageReference("alpine", false)
err = b.DownloadImage(backend.Options{ImageName: "alpine"})
Expect(err).ToNot(HaveOccurred())
img, err := b.ImageReference("alpine")
Expect(err).ToNot(HaveOccurred())

_, dir, err := Extract(ctx, img, nil)
Expand All @@ -66,7 +68,7 @@ var _ = Describe("Create", func() {

Expect(b.ImageExists("testimage")).To(BeTrue())

img, err = b.ImageReference("testimage", false)
img, err = b.ImageReference("testimage")
Expect(err).ToNot(HaveOccurred())

_, dir, err = Extract(ctx, img, nil)
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/core/types/artifact/artifact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ RUN echo bar > /test2`))
Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(result) // clean up

img, err := b.ImageReference(resultingImage, true)
img, err := b.ImageReference(resultingImage)
Expect(err).ToNot(HaveOccurred())
_, _, err = image.ExtractTo(
ctx,
Expand Down Expand Up @@ -203,7 +203,7 @@ RUN echo bar > /test2`))
Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(result) // clean up

img, err := b.ImageReference(resultingImage, false)
img, err := b.ImageReference(resultingImage)
Expect(err).ToNot(HaveOccurred())
_, _, err = image.ExtractTo(
ctx,
Expand Down
5 changes: 3 additions & 2 deletions pkg/compiler/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package compiler
import (
v1 "github.com/google/go-containerregistry/pkg/v1"

"github.com/pkg/errors"

"github.com/mudler/luet/pkg/api/core/types"
"github.com/mudler/luet/pkg/compiler/backend"
"github.com/pkg/errors"
)

func NewBackend(ctx types.Context, s string) (CompilerBackend, error) {
Expand Down Expand Up @@ -36,6 +37,6 @@ type CompilerBackend interface {
Push(opts backend.Options) error
ImageAvailable(string) bool

ImageReference(img1 string, ondisk bool) (v1.Image, error)
ImageReference(img1 string) (v1.Image, error)
ImageExists(string) bool
}
7 changes: 5 additions & 2 deletions pkg/compiler/backend/simpledocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ package backend
import (
"io"
"os/exec"
"strings"

"github.com/google/go-containerregistry/pkg/crane"
"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/daemon"
"github.com/google/go-containerregistry/pkg/v1/tarball"

bus "github.com/mudler/luet/pkg/api/core/bus"
"github.com/mudler/luet/pkg/api/core/image"
"github.com/mudler/luet/pkg/api/core/types"
Expand All @@ -47,6 +49,7 @@ func (s *SimpleDocker) BuildImage(opts Options) error {

buildarg := genBuildCommand(opts)
s.ctx.Info(":whale2: Building image " + name)
s.ctx.Debug(":whale2: Command: docker " + strings.Join(buildarg, " "))
cmd := exec.Command("docker", buildarg...)
cmd.Dir = opts.SourcePath
err := runCommand(s.ctx, cmd)
Expand Down Expand Up @@ -207,8 +210,8 @@ func (s *SimpleDocker) imageFromDisk(a string) (v1.Image, error) {
return crane.Load(f.Name())
}

func (s *SimpleDocker) ImageReference(a string, ondisk bool) (v1.Image, error) {
if ondisk {
func (s *SimpleDocker) ImageReference(a string) (v1.Image, error) {
if s.ImageExists(a) {
return s.imageFromDisk(a)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/compiler/backend/simpleimg.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/google/go-containerregistry/pkg/crane"
v1 "github.com/google/go-containerregistry/pkg/v1"

bus "github.com/mudler/luet/pkg/api/core/bus"
"github.com/mudler/luet/pkg/api/core/image"
"github.com/mudler/luet/pkg/api/core/types"
Expand Down Expand Up @@ -76,8 +77,7 @@ func (s *SimpleImg) RemoveImage(opts Options) error {
return nil
}

func (s *SimpleImg) ImageReference(a string, ondisk bool) (v1.Image, error) {

func (s *SimpleImg) ImageReference(a string) (v1.Image, error) {
f, err := s.ctx.TempFile("snapshot")
if err != nil {
return nil, err
Expand Down
13 changes: 7 additions & 6 deletions pkg/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import (

dockerfile "github.com/asottile/dockerfile"
"github.com/imdario/mergo"
"github.com/pkg/errors"
"gopkg.in/yaml.v2"

bus "github.com/mudler/luet/pkg/api/core/bus"
"github.com/mudler/luet/pkg/api/core/context"
"github.com/mudler/luet/pkg/api/core/image"
Expand All @@ -43,8 +46,6 @@ import (
"github.com/mudler/luet/pkg/helpers"
fileHelper "github.com/mudler/luet/pkg/helpers/file"
"github.com/mudler/luet/pkg/solver"
"github.com/pkg/errors"
"gopkg.in/yaml.v2"
)

const BuildFile = "build.yaml"
Expand Down Expand Up @@ -234,7 +235,7 @@ func (cs *LuetCompiler) unpackFs(concurrency int, keepPermissions bool, p *types
}
}

img, err := cs.Backend.ImageReference(runnerOpts.ImageName, true)
img, err := cs.Backend.ImageReference(runnerOpts.ImageName)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -301,14 +302,14 @@ func (cs *LuetCompiler) unpackDelta(concurrency int, keepPermissions bool, p *ty

cs.Options.Context.Debug(pkgTag, ":hammer: Retrieving reference for", builderOpts.ImageName)

ref, err := cs.Backend.ImageReference(builderOpts.ImageName, true)
ref, err := cs.Backend.ImageReference(builderOpts.ImageName)
if err != nil {
return nil, err
}

cs.Options.Context.Debug(pkgTag, ":hammer: Retrieving reference for", runnerOpts.ImageName)

ref2, err := cs.Backend.ImageReference(runnerOpts.ImageName, true)
ref2, err := cs.Backend.ImageReference(runnerOpts.ImageName)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1078,7 +1079,7 @@ func (cs *LuetCompiler) resolveFinalImages(concurrency int, keepPermissions bool
}
}

imgRef, err := cs.Backend.ImageReference(img, true)
imgRef, err := cs.Backend.ImageReference(img)
if err != nil {
return err
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/compiler/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import (

helpers "github.com/mudler/luet/tests/helpers"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/mudler/luet/pkg/api/core/context"
"github.com/mudler/luet/pkg/api/core/image"
"github.com/mudler/luet/pkg/api/core/types/artifact"
Expand All @@ -36,8 +39,6 @@ import (
pkg "github.com/mudler/luet/pkg/database"
fileHelper "github.com/mudler/luet/pkg/helpers/file"
"github.com/mudler/luet/pkg/tree"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("Compiler", func() {
Expand Down Expand Up @@ -898,15 +899,15 @@ var _ = Describe("Compiler", func() {
Expect(b.ImageAvailable(fmt.Sprintf("%s:%s", imageName, artifacts[1].Runtime.ImageID()))).To(BeTrue())
Expect(b.ImageAvailable(fmt.Sprintf("%s:%s", imageName, artifacts[1].Runtime.GetMetadataFilePath()))).To(BeTrue())

img, err := b.ImageReference(fmt.Sprintf("%s:%s", imageName, artifacts[0].Runtime.ImageID()), true)
img, err := b.ImageReference(fmt.Sprintf("%s:%s", imageName, artifacts[0].Runtime.ImageID()))
Expect(err).ToNot(HaveOccurred())
_, path, err := image.Extract(ctx, img, nil)
Expect(err).ToNot(HaveOccurred())
defer os.RemoveAll(path) // clean up

Expect(fileHelper.Exists(filepath.Join(path, "bin/busybox"))).To(BeTrue())

img, err = b.ImageReference(fmt.Sprintf("%s:%s", imageName, artifacts[1].Runtime.GetMetadataFilePath()), true)
img, err = b.ImageReference(fmt.Sprintf("%s:%s", imageName, artifacts[1].Runtime.GetMetadataFilePath()))
Expect(err).ToNot(HaveOccurred())
_, path, err = image.Extract(ctx, img, nil)
Expect(err).ToNot(HaveOccurred())
Expand Down
2 changes: 1 addition & 1 deletion pkg/installer/repository_docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (d *dockerRepositoryGenerator) Generate(r *LuetSystemRepository, imagePrefi
if err != nil {
return errors.Wrapf(err, "while downloading '%s'", imageRepository)
}
img, err := r.GetBackend().ImageReference(imageRepository, true)
img, err := r.GetBackend().ImageReference(imageRepository)
if err != nil {
return errors.Wrapf(err, "while downloading '%s'", imageRepository)
}
Expand Down