Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release/0.21.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Sep 15, 2021
2 parents 0aed72b + a9c294a commit 437c3f1
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 25 deletions.
32 changes: 19 additions & 13 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,25 +297,31 @@ func (c *Client) Build(ctx context.Context, opts BuildOptions) error {
return err
}

version := opts.ProjectDescriptor.Project.Version
sourceURL := opts.ProjectDescriptor.Project.SourceURL
runImageName, err = pname.TranslateRegistry(runImageName, c.registryMirrors, c.logger)
if err != nil {
return err
}

projectMetadata := platform.ProjectMetadata{}
if c.experimental {
version := opts.ProjectDescriptor.Project.Version
sourceURL := opts.ProjectDescriptor.Project.SourceURL
if version != "" || sourceURL != "" {
projectMetadata.Source = &platform.ProjectSource{
Type: "project",
Version: map[string]interface{}{"declared": version},
Metadata: map[string]interface{}{"url": sourceURL},
}
}
}

lifecycleOpts := build.LifecycleOptions{
AppPath: appPath,
Image: imageRef,
Builder: ephemeralBuilder,
LifecycleImage: ephemeralBuilder.Name(),
RunImage: runImageName,
ProjectMetadata: platform.ProjectMetadata{Source: &platform.ProjectSource{
Type: "project",
Version: map[string]interface{}{"declared": version},
Metadata: map[string]interface{}{"url": sourceURL},
}},
ProjectPath: "",
AppPath: appPath,
Image: imageRef,
Builder: ephemeralBuilder,
LifecycleImage: ephemeralBuilder.Name(),
RunImage: runImageName,
ProjectMetadata: projectMetadata,
ClearCache: opts.ClearCache,
Publish: opts.Publish,
TrustBuilder: opts.TrustBuilder,
Expand Down
66 changes: 66 additions & 0 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/buildpacks/imgutil/local"
"github.com/buildpacks/imgutil/remote"
"github.com/buildpacks/lifecycle/api"
"github.com/buildpacks/lifecycle/platform"
"github.com/docker/docker/client"
"github.com/google/go-containerregistry/pkg/name"
"github.com/heroku/color"
Expand Down Expand Up @@ -1526,6 +1527,71 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
})
})

when("ProjectDescriptor", func() {
when("project metadata", func() {
when("not experimental", func() {
it("does not set project source", func() {
err := subject.Build(context.TODO(), BuildOptions{
Image: "some/app",
Builder: defaultBuilderName,
ClearCache: true,
ProjectDescriptor: projectTypes.Descriptor{
Project: projectTypes.Project{
Version: "1.2.3",
SourceURL: "https://example.com",
},
},
})

h.AssertNil(t, err)
h.AssertNil(t, fakeLifecycle.Opts.ProjectMetadata.Source)
})
})

when("is experimental", func() {
it.Before(func() {
subject.experimental = true
})

when("missing information", func() {
it("does not set project source", func() {
err := subject.Build(context.TODO(), BuildOptions{
Image: "some/app",
Builder: defaultBuilderName,
ClearCache: true,
ProjectDescriptor: projectTypes.Descriptor{},
})

h.AssertNil(t, err)
h.AssertNil(t, fakeLifecycle.Opts.ProjectMetadata.Source)
})
})

it("sets project source", func() {
err := subject.Build(context.TODO(), BuildOptions{
Image: "some/app",
Builder: defaultBuilderName,
ClearCache: true,
ProjectDescriptor: projectTypes.Descriptor{
Project: projectTypes.Project{
Version: "1.2.3",
SourceURL: "https://example.com",
},
},
})

h.AssertNil(t, err)
h.AssertNotNil(t, fakeLifecycle.Opts.ProjectMetadata.Source)
h.AssertEq(t, fakeLifecycle.Opts.ProjectMetadata.Source, &platform.ProjectSource{
Type: "project",
Version: map[string]interface{}{"declared": "1.2.3"},
Metadata: map[string]interface{}{"url": "https://example.com"},
})
})
})
})
})

when("Env option", func() {
it("should set the env on the ephemeral builder", func() {
h.AssertNil(t, subject.Build(context.TODO(), BuildOptions{
Expand Down
1 change: 0 additions & 1 deletion internal/build/lifecycle_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ type LifecycleOptions struct {
LifecycleImage string
RunImage string
ProjectMetadata platform.ProjectMetadata
ProjectPath string
ClearCache bool
Publish bool
TrustBuilder bool
Expand Down
11 changes: 0 additions & 11 deletions internal/builder/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ type Metadata struct {
Stack StackMetadata `json:"stack"`
Lifecycle LifecycleMetadata `json:"lifecycle"`
CreatedBy CreatorMetadata `json:"createdBy"`
Project ProjectMetadata `json:"source,omitempty"`
}

type CreatorMetadata struct {
Expand All @@ -31,16 +30,6 @@ type StackMetadata struct {
RunImage RunImageMetadata `json:"runImage" toml:"run-image"`
}

type ProjectMetadata struct {
Source ProjectSource `json:"source,omitempty" toml:"source"`
}

type ProjectSource struct {
Type string `toml:"type" json:"type,omitempty"`
Version map[string]interface{} `toml:"version" json:"version,omitempty"`
Metadata map[string]interface{} `toml:"metadata" json:"metadata,omitempty"`
}

type RunImageMetadata struct {
Image string `json:"image" toml:"image"`
Mirrors []string `json:"mirrors" toml:"mirrors"`
Expand Down

0 comments on commit 437c3f1

Please sign in to comment.