diff --git a/Makefile b/Makefile index 947975676..0fc384f9a 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,9 @@ imports: $(GOCMD) install -mod=vendor golang.org/x/tools/cmd/goimports test -z $$(goimports -l -w -local github.com/buildpack/lifecycle $$(find . -type f -name '*.go' -not -path "./vendor/*")) +tools: + $(GOCMD) install -mod=vendor github.com/sclevine/yj + format: test -z $$($(GOCMD) fmt ./...) @@ -32,10 +35,10 @@ vet: test: unit acceptance -unit: format imports vet +unit: format imports tools vet $(GOTEST) -v -count=1 ./... -acceptance: format imports vet +acceptance: format imports tools vet $(GOTEST) -v -count=1 -tags=acceptance ./acceptance/... clean: diff --git a/builder.go b/builder.go index 94c47b975..80ad2b01b 100644 --- a/builder.go +++ b/builder.go @@ -39,7 +39,7 @@ type LaunchTOML struct { type BOMEntry struct { Require - Buildpack Buildpack `toml:"buildpack"` + Buildpack Buildpack `toml:"buildpack" json:"buildpack"` } type BuildMetadata struct { diff --git a/detector.go b/detector.go index 04b35b902..57d20be21 100644 --- a/detector.go +++ b/detector.go @@ -22,9 +22,9 @@ const ( var ErrFail = errors.New("detection failed") type Buildpack struct { - ID string `toml:"id"` - Version string `toml:"version"` - Optional bool `toml:"optional,omitempty"` + ID string `toml:"id" json:"id"` + Version string `toml:"version" json:"version"` + Optional bool `toml:"optional,omitempty" json:"optional,omitempty"` } func (bp Buildpack) dir() string { @@ -59,9 +59,9 @@ func (be BuildPlanEntry) noOpt() BuildPlanEntry { } type Require struct { - Name string `toml:"name"` - Version string `toml:"version"` - Metadata map[string]interface{} `toml:"metadata"` + Name string `toml:"name" json:"name"` + Version string `toml:"version" json:"version"` + Metadata map[string]interface{} `toml:"metadata" json:"metadata"` } type Provide struct { diff --git a/exporter.go b/exporter.go index 91f5ae982..5c211f94a 100644 --- a/exporter.go +++ b/exporter.go @@ -179,17 +179,16 @@ func (e *Exporter) addBuildMetadataLabel(image imgutil.Image, plan []BOMEntry, l }) } - buildJson, err := json.Marshal(metadata.BuildMetadata{ + buildJSON, err := json.Marshal(metadata.BuildMetadata{ BOM: plan, Buildpacks: bps, Launcher: launcherMD, }) - if err != nil { return errors.Wrap(err, "parse build metadata") } - if err := image.SetLabel(metadata.BuildMetadataLabel, string(buildJson)); err != nil { + if err := image.SetLabel(metadata.BuildMetadataLabel, string(buildJSON)); err != nil { return errors.Wrap(err, "set build image metadata label") } diff --git a/exporter_test.go b/exporter_test.go index 237d91015..4beb35d16 100644 --- a/exporter_test.go +++ b/exporter_test.go @@ -383,19 +383,22 @@ func testExporter(t *testing.T, when spec.G, it spec.S) { it.Before(func() { err := ioutil.WriteFile(filepath.Join(layersDir, "config", "metadata.toml"), []byte(` [[processes]] - type = "web" - command = "npm start" -[bom] - [bom.auto-reconfiguration] - version = "2.7.0" - [bom.auto-reconfiguration.metadata] - name = "Spring Auto-reconfiguration" - sha256 = "0d524877db7344ec34620f7e46254053568292f5ce514f74e3a0e9b2dbfc338b" - stacks = ["io.buildpacks.stacks.bionic", "org.cloudfoundry.stacks.cflinuxfs3"] - uri = "https://example.com" - - [[bom.auto-reconfiguration.metadata.licenses]] - type = "Apache-2.0" +type = "web" +command = "npm start" + +[[bom]] +name = "Spring Auto-reconfiguration" +version = "2.7.0" +[bom.metadata] +sha256 = "0d524877db7344ec34620f7e46254053568292f5ce514f74e3a0e9b2dbfc338b" +stacks = ["io.buildpacks.stacks.bionic", "org.cloudfoundry.stacks.cflinuxfs3"] +uri = "https://example.com" +[bom.buildpack] +id = "buildpack.id" +version = "1.2.3" + +[[bom.metadata.licenses]] +type = "Apache-2.0" `), os.ModePerm, ) @@ -410,25 +413,29 @@ func testExporter(t *testing.T, when spec.G, it spec.S) { expectedJSON := ` { - "bom": { - "auto-reconfiguration": { + "bom": [ + { + "name": "Spring Auto-reconfiguration", + "version": "2.7.0", + "buildpack": { + "id": "buildpack.id", + "version": "1.2.3" + }, "metadata": { "licenses": [ { "type": "Apache-2.0" } ], - "name": "Spring Auto-reconfiguration", "sha256": "0d524877db7344ec34620f7e46254053568292f5ce514f74e3a0e9b2dbfc338b", "stacks": [ "io.buildpacks.stacks.bionic", "org.cloudfoundry.stacks.cflinuxfs3" ], "uri": "https://example.com" - }, - "version": "2.7.0" + } } - }, + ], "buildpacks": [ { "id": "buildpack.id",