Skip to content

Commit

Permalink
Merge pull request #7 from rancherlabs/empty-platform
Browse files Browse the repository at this point in the history
Add support for single arch images
  • Loading branch information
pjbgf authored Nov 14, 2024
2 parents 2d63d83 + 0aa7c09 commit 72fc0f6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
1 change: 1 addition & 0 deletions buildtypes/buildkit-gha/v1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ All internal parameters are REQUIRED.

| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `platform` | string | The platform used to run BuildKit. This is equivalent to `environment.platform` from `buildkit@v1`. |
| `trigger` | string | The GitHub Action event that caused the build to be executed. |
| `invocationUri` | string | Resource URI for the GitHub action workflow instance. |

Expand Down
14 changes: 6 additions & 8 deletions cmd/provenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,12 @@ func provenanceCmd(img, format, platform string) error {
}

var predicate *v02.ProvenancePredicate
if strings.EqualFold(platform, "linux/amd64") {
if buildKit.LinuxAmd64 != nil {
predicate = &buildKit.LinuxAmd64.SLSA
}
} else if strings.EqualFold(platform, "linux/arm64") {
if buildKit.LinuxArm64 != nil {
predicate = &buildKit.LinuxArm64.SLSA
}
if strings.EqualFold(platform, "linux/amd64") && buildKit.LinuxAmd64 != nil {
predicate = &buildKit.LinuxAmd64.SLSA
} else if strings.EqualFold(platform, "linux/arm64") && buildKit.LinuxArm64 != nil {
predicate = &buildKit.LinuxArm64.SLSA
} else if buildKit.SLSA != nil {
predicate = buildKit.SLSA
} else {
return fmt.Errorf("platform not supported: %q", platform)
}
Expand Down
15 changes: 6 additions & 9 deletions cmd/sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,12 @@ func sbomCmd(img, outformat, platform string) error {
}

var spdx json.RawMessage
if strings.EqualFold(platform, "linux/amd64") {
if data.LinuxAmd64 != nil {
spdx = data.LinuxAmd64.SPDX
}

} else if strings.EqualFold(platform, "linux/arm64") {
if data.LinuxArm64 != nil {
spdx = data.LinuxArm64.SPDX
}
if strings.EqualFold(platform, "linux/amd64") && data.LinuxAmd64 != nil {
spdx = data.LinuxAmd64.SPDX
} else if strings.EqualFold(platform, "linux/arm64") && data.LinuxArm64 != nil {
spdx = data.LinuxArm64.SPDX
} else if data.SPDX != nil {
spdx = *data.SPDX
} else {
return fmt.Errorf("platform not supported: %q", platform)
}
Expand Down
13 changes: 10 additions & 3 deletions internal/provenance/provenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ type InternalParameters struct {
}

type BuildKitProvenance02 struct {
LinuxAmd64 *ArchProvenance `json:"linux/amd64,omitempty"`
LinuxArm64 *ArchProvenance `json:"linux/arm64,omitempty"`
LinuxAmd64 *ArchProvenance `json:"linux/amd64,omitempty"`
LinuxArm64 *ArchProvenance `json:"linux/arm64,omitempty"`
SLSA *v02.ProvenancePredicate `json:"SLSA,omitempty"`
}

type ArchProvenance struct {
Expand Down Expand Up @@ -69,7 +70,13 @@ func ConvertV02ToV1(v02Prov v02.ProvenancePredicate, override *v1.ProvenancePred
override.BuildDefinition.ResolvedDependencies...)
}
if override.BuildDefinition.InternalParameters != nil {
prov.BuildDefinition.InternalParameters = override.BuildDefinition.InternalParameters
v := override.BuildDefinition.InternalParameters.(InternalParameters)
env, ok := v02Prov.Invocation.Environment.(map[string]interface{})
if ok && len(env) > 0 {
v.Platform = env["platform"].(string)
}

prov.BuildDefinition.InternalParameters = v
}
}

Expand Down
5 changes: 3 additions & 2 deletions internal/sbom/sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import (
)

type BuildKitSBOM struct {
LinuxAmd64 *archSBOM `json:"linux/amd64,omitempty"`
LinuxArm64 *archSBOM `json:"linux/arm64,omitempty"`
LinuxAmd64 *archSBOM `json:"linux/amd64,omitempty"`
LinuxArm64 *archSBOM `json:"linux/arm64,omitempty"`
SPDX *json.RawMessage `json:"SPDX,omitempty"`
}

type archSBOM struct {
Expand Down

0 comments on commit 72fc0f6

Please sign in to comment.