Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Resolve nested acorn images against local registry
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Jun 27, 2022
1 parent f38780a commit 788b1f3
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 6 deletions.
11 changes: 11 additions & 0 deletions integration/build/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,20 @@ func TestBuildFailed(t *testing.T) {
}

func TestNestedBuild(t *testing.T) {
simple, err := build.Build(helper.GetCTX(t), "./testdata/simple/acorn.cue", &build.Options{
Cwd: "./testdata/simple",
Client: helper.BuilderClient(t, system.RequireUserNamespace()),
})
if err != nil {
t.Fatal(err)
}

image, err := build.Build(helper.GetCTX(t), "./testdata/nested/acorn.cue", &build.Options{
Cwd: "./testdata/nested",
Client: helper.BuilderClient(t, system.RequireUserNamespace()),
Args: map[string]interface{}{
"image": simple.ID,
},
})
if err != nil {
t.Fatal(err)
Expand Down
3 changes: 3 additions & 0 deletions integration/build/testdata/nested/acorn.cue
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
args: build: image: string

acorns: {
sub1: {
build: "./subdir"
Expand All @@ -8,6 +10,7 @@ acorns: {
acornfile: "./subdir2/test.cue"
buildArgs: {
filename: "buildfile"
image: args.build.image
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions integration/build/testdata/nested/subdir2/test.cue
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
args: build: {
filename: string
image: string
}

images: bar: build: {
context: "./bar"
dockerfile: "./bar/\(args.build.filename)"
}

// busybox is not a proper acorn image, but should work since we don't validate and we know it's an index
acorns: foo: image: "busybox"
acorns: foo: image: string
2 changes: 1 addition & 1 deletion pkg/appdefinition/appdefinition.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func AppImageFromTar(reader io.Reader) (*v1.AppImage, error) {
}

if result.Acornfile == "" {
return nil, fmt.Errorf("invalid image, empty acorn.cue")
return nil, fmt.Errorf("invalid image no acorn.cue found")
}

return result, nil
Expand Down
11 changes: 11 additions & 0 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/acorn-io/acorn/pkg/remoteopts"
"github.com/acorn-io/acorn/pkg/streams"
"github.com/acorn-io/acorn/pkg/system"
"github.com/acorn-io/acorn/pkg/tags"
"github.com/acorn-io/baaah/pkg/typed"
imagename "github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
Expand Down Expand Up @@ -193,6 +194,16 @@ func buildAcorns(ctx context.Context, c client.Client, cwd string, platforms []v
for _, entry := range typed.Sorted(acorns) {
key, acornImage := entry.Key, entry.Value
if acornImage.Image != "" {
imageDetails, err := c.ImageDetails(ctx, acornImage.Image, nil)
if err != nil {
return nil, err
}

if tags.SHAPattern.MatchString(imageDetails.AppImage.ID) {
// TODO: This is a terrible hack and should be redone once we move builder logic server side
acornImage.Image = fmt.Sprintf("127.0.0.1:%d/acorn/%s:%s", system.RegistryPort, c.GetNamespace(), imageDetails.AppImage.ID)
}

tag, err := imagename.ParseReference(acornImage.Image)
if err != nil {
return nil, err
Expand Down
5 changes: 4 additions & 1 deletion pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ type ImageProgress struct {
}

type ImageDetails struct {
AppImage v1.AppImage `json:"appImage,omitempty"`
AppImage v1.AppImage `json:"appImage,omitempty"`
AppSpec *v1.AppSpec `json:"appSpec,omitempty"`
Params *v1.ParamSpec `json:"params,omitempty"`
ParseError string `json:"parseError,omitempty"`
}

type Client interface {
Expand Down
5 changes: 4 additions & 1 deletion pkg/client/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ func (c *client) ImageDetails(ctx context.Context, imageName string, opts *Image
}

return &ImageDetails{
AppImage: detailsResult.AppImage,
AppImage: detailsResult.AppImage,
AppSpec: detailsResult.AppSpec,
Params: detailsResult.Params,
ParseError: detailsResult.ParseError,
}, nil
}

Expand Down
8 changes: 7 additions & 1 deletion pkg/pull/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ func AppImage(ctx context.Context, c client.Reader, namespace, image string) (*v
return nil, err
}

return pullIndex(tag, opts)
appImage, err := pullIndex(tag, opts)
if err != nil {
return nil, err
}

appImage.ID = image
return appImage, nil
}

func pullIndex(tag imagename.Reference, opts []remote.Option) (*v1.AppImage, error) {
Expand Down

0 comments on commit 788b1f3

Please sign in to comment.