Skip to content

Commit

Permalink
Add support for architecture selection during updating of buildpack d…
Browse files Browse the repository at this point in the history
…ependencies

Signed-off-by: Daniel Mikusa <[email protected]>
  • Loading branch information
dmikusa committed Jan 19, 2024
1 parent 37fc400 commit de0f329
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
19 changes: 18 additions & 1 deletion carton/buildpack_dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
type BuildpackDependency struct {
BuildpackPath string
ID string
Arch string
SHA256 string
URI string
Version string
Expand All @@ -58,6 +59,7 @@ func (b BuildpackDependency) Update(options ...Option) {

logger := bard.NewLogger(os.Stdout)
_, _ = fmt.Fprintf(logger.TitleWriter(), "\n%s\n", bard.FormatIdentity(b.ID, b.VersionPattern))
logger.Headerf("Arch: %s", b.Arch)
logger.Headerf("Version: %s", b.Version)
logger.Headerf("PURL: %s", b.PURL)
logger.Headerf("CPEs: %s", b.CPE)
Expand Down Expand Up @@ -141,7 +143,21 @@ func (b BuildpackDependency) Update(options ...Option) {
continue
}

if depId == b.ID {
// extract the arch from the PURL, it's the only place it lives consistently at the moment
var depArch string
purlUnwrapped, found := dep["purl"]
if found {
purl, ok := purlUnwrapped.(string)
if ok {
purlArchExp := regexp.MustCompile(`arch=(.*)`)
purlArchMatches := purlArchExp.FindStringSubmatch(purl)
if len(purlArchMatches) == 2 {
depArch = purlArchMatches[1]
}
}
}

if depId == b.ID && depArch == b.Arch {
depVersionUnwrapped, found := dep["version"]
if !found {
continue
Expand All @@ -151,6 +167,7 @@ func (b BuildpackDependency) Update(options ...Option) {
if !ok {
continue
}

if versionExp.MatchString(depVersion) {
dep["version"] = b.Version
dep["uri"] = b.URI
Expand Down
5 changes: 5 additions & 0 deletions cmd/update-buildpack-dependency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func main() {
flagSet := pflag.NewFlagSet("Update Buildpack Dependency", pflag.ExitOnError)
flagSet.StringVar(&b.BuildpackPath, "buildpack-toml", "", "path to buildpack.toml")
flagSet.StringVar(&b.ID, "id", "", "the id of the dependency")
flagSet.StringVar(&b.Arch, "arch", "", "the arch of the dependency")
flagSet.StringVar(&b.SHA256, "sha256", "", "the new sha256 of the dependency")
flagSet.StringVar(&b.URI, "uri", "", "the new uri of the dependency")
flagSet.StringVar(&b.Version, "version", "", "the new version of the dependency")
Expand All @@ -55,6 +56,10 @@ func main() {
log.Fatal("id must be set")
}

if b.Arch == "" {
b.Arch = "amd64"
}

if b.SHA256 == "" {
log.Fatal("sha256 must be set")
}
Expand Down

0 comments on commit de0f329

Please sign in to comment.