Skip to content

Commit 8d34a72

Browse files
authored
Adding multi-arch support for node-engine (#1293)
* fix: adding os and arch while fetching new node versions * feat: Adding the generateMetadata with support for multiple platforms * fix: removing platforms transformation * chore: updating buildpack.toml to with latest node versions * fix: updating api to 0.10 on buildpack.toml * fix: upgrading packit and several go modules * fix: upgrading go version, packit and libdependency * fix: updating dependencies on the buildpack.toml * updating .gitignore
1 parent 98dc72c commit 8d34a72

7 files changed

Lines changed: 338 additions & 202 deletions

File tree

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
.DS_Store
22
.idea
3-
.bin
4-
/bin
3+
/.bin
54
/build
5+
/bin
6+
/linux
7+
/darwin
8+
/windows

buildpack.toml

Lines changed: 138 additions & 54 deletions
Large diffs are not rendered by default.

dependency/retrieval/go.mod

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
module github.com/paketo-buildpacks/node-engine/retrieval
22

3-
go 1.24.3
4-
5-
toolchain go1.24.4
3+
go 1.24.6
64

75
require (
86
github.com/Masterminds/semver/v3 v3.4.0
9-
github.com/paketo-buildpacks/libdependency v0.1.0
10-
github.com/paketo-buildpacks/packit/v2 v2.20.0
7+
github.com/paketo-buildpacks/libdependency v0.2.1
8+
github.com/paketo-buildpacks/packit/v2 v2.25.0
119
)
1210

1311
require (
@@ -21,7 +19,7 @@ require (
2119
github.com/dgryski/go-minhash v0.0.0-20190315135803-ad340ca03076 // indirect
2220
github.com/ekzhu/minhash-lsh v0.0.0-20190924033628-faac2c6342f8 // indirect
2321
github.com/emirpasic/gods v1.18.1 // indirect
24-
github.com/gabriel-vasile/mimetype v1.4.9 // indirect
22+
github.com/gabriel-vasile/mimetype v1.4.10 // indirect
2523
github.com/go-enry/go-license-detector/v4 v4.3.1 // indirect
2624
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
2725
github.com/go-git/go-billy/v5 v5.6.2 // indirect
@@ -30,22 +28,22 @@ require (
3028
github.com/hhatto/gorst v0.0.0-20181029133204-ca9f730cac5b // indirect
3129
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
3230
github.com/jdkato/prose v1.2.1 // indirect
33-
github.com/kevinburke/ssh_config v1.2.0 // indirect
34-
github.com/moby/go-archive v0.1.0 // indirect
31+
github.com/kevinburke/ssh_config v1.4.0 // indirect
32+
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
3533
github.com/montanaflynn/stats v0.7.1 // indirect
36-
github.com/pjbgf/sha1cd v0.3.2 // indirect
34+
github.com/pjbgf/sha1cd v0.5.0 // indirect
3735
github.com/pkg/errors v0.9.1 // indirect
3836
github.com/russross/blackfriday/v2 v2.1.0 // indirect
3937
github.com/sergi/go-diff v1.4.0 // indirect
4038
github.com/shogo82148/go-shuffle v1.1.1 // indirect
4139
github.com/skeema/knownhosts v1.3.1 // indirect
42-
github.com/ulikunitz/xz v0.5.14 // indirect
40+
github.com/ulikunitz/xz v0.5.15 // indirect
4341
github.com/xanzy/ssh-agent v0.3.3 // indirect
44-
golang.org/x/crypto v0.39.0 // indirect
45-
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b // indirect
46-
golang.org/x/net v0.41.0 // indirect
47-
golang.org/x/sys v0.33.0 // indirect
48-
golang.org/x/text v0.26.0 // indirect
42+
golang.org/x/crypto v0.42.0 // indirect
43+
golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b // indirect
44+
golang.org/x/net v0.44.0 // indirect
45+
golang.org/x/sys v0.36.0 // indirect
46+
golang.org/x/text v0.29.0 // indirect
4947
gonum.org/v1/gonum v0.16.0 // indirect
5048
gopkg.in/neurosnap/sentences.v1 v1.0.7 // indirect
5149
gopkg.in/warnings.v0 v0.1.2 // indirect

dependency/retrieval/go.sum

Lines changed: 94 additions & 62 deletions
Large diffs are not rendered by default.

dependency/retrieval/main.go

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ func (nodeMetadata NodeMetadata) Version() *semver.Version {
3434
}
3535

3636
func main() {
37-
retrieve.NewMetadata("node", getAllVersions, generateMetadata)
37+
retrieve.NewMetadataWithPlatforms("node", getAllVersions, generateMetadataWithPlatform)
3838
}
3939

40-
func generateMetadata(versionFetcher versionology.VersionFetcher) ([]versionology.Dependency, error) {
40+
func generateMetadataWithPlatform(versionFetcher versionology.VersionFetcher, platform retrieve.Platform) ([]versionology.Dependency, error) {
4141
version := versionFetcher.Version().String()
4242

4343
body, err := httpGet("https://nodejs.org/dist/index.json")
@@ -58,7 +58,7 @@ func generateMetadata(versionFetcher versionology.VersionFetcher) ([]versionolog
5858

5959
for _, release := range nodeReleases {
6060
if strings.TrimPrefix(release.Version, "v") == version {
61-
return createDependencyMetadata(release, releaseSchedule)
61+
return createDependencyMetadata(release, releaseSchedule, platform)
6262
}
6363
}
6464

@@ -108,11 +108,19 @@ func getReleaseSchedule() (ReleaseSchedule, error) {
108108
return releaseSchedule, nil
109109
}
110110

111-
func createDependencyMetadata(release NodeRelease, releaseSchedule ReleaseSchedule) ([]versionology.Dependency, error) {
111+
func createDependencyMetadata(release NodeRelease, releaseSchedule ReleaseSchedule, platform retrieve.Platform) ([]versionology.Dependency, error) {
112+
113+
var nodeArch string
114+
if platform.Arch == "amd64" {
115+
nodeArch = "x64"
116+
} else {
117+
nodeArch = platform.Arch
118+
}
119+
112120
version := release.Version
113-
url := fmt.Sprintf("https://nodejs.org/dist/%[1]s/node-%[1]s-linux-x64.tar.xz", version)
121+
url := fmt.Sprintf("https://nodejs.org/dist/%[1]s/node-%[1]s-%[2]s-%[3]s.tar.xz", version, platform.OS, nodeArch)
114122

115-
checksum, err := getChecksum(version)
123+
checksum, err := getChecksum(version, platform)
116124
if err != nil {
117125
return nil, err
118126
}
@@ -132,15 +140,17 @@ func createDependencyMetadata(release NodeRelease, releaseSchedule ReleaseSchedu
132140
Licenses: retrieve.LookupLicenses(url, upstream.DefaultDecompress),
133141
DeprecationDate: deprecationDate,
134142
StripComponents: 1,
135-
Stacks: []string{"io.buildpacks.stacks.jammy", "*"},
143+
Stacks: []string{"*"},
144+
OS: platform.OS,
145+
Arch: platform.Arch,
136146
}
137147

138-
jammyDependency, err := versionology.NewDependency(dep, "jammy")
148+
allStacksDependency, err := versionology.NewDependency(dep, "*")
139149
if err != nil {
140-
return nil, fmt.Errorf("could get create jammy dependency: %w", err)
150+
return nil, fmt.Errorf("could not get create * dependency: %w", err)
141151
}
142152

143-
return []versionology.Dependency{jammyDependency}, nil
153+
return []versionology.Dependency{allStacksDependency}, nil
144154
}
145155

146156
func getDeprecationDate(version string, releaseSchedule ReleaseSchedule) *time.Time {
@@ -161,20 +171,28 @@ func getDeprecationDate(version string, releaseSchedule ReleaseSchedule) *time.T
161171
return &deprecationDate
162172
}
163173

164-
func getChecksum(version string) (string, error) {
174+
func getChecksum(version string, platform retrieve.Platform) (string, error) {
175+
176+
var nodeArch string
177+
if platform.Arch == "amd64" {
178+
nodeArch = "x64"
179+
} else {
180+
nodeArch = platform.Arch
181+
}
182+
165183
body, err := httpGet(fmt.Sprintf("https://nodejs.org/dist/%s/SHASUMS256.txt", version))
166184
if err != nil {
167185
return "", fmt.Errorf("could not get SHA256 file: %w", err)
168186
}
169187

170188
var dependencySHA string
171189
for _, line := range strings.Split(string(body), "\n") {
172-
if strings.HasSuffix(line, fmt.Sprintf("node-%s-linux-x64.tar.xz", version)) {
190+
if strings.HasSuffix(line, fmt.Sprintf("node-%[1]s-%[2]s-%[3]s.tar.xz", version, platform.OS, nodeArch)) {
173191
dependencySHA = strings.Fields(line)[0]
174192
}
175193
}
176194
if dependencySHA == "" {
177-
return "", fmt.Errorf("could not find SHA256 for node-%s-linux-x64.tar.xz", version)
195+
return "", fmt.Errorf("could not find SHA256 for node-%s-%s-%s.tar.xz", version, platform.OS, nodeArch)
178196
}
179197
return dependencySHA, nil
180198
}

go.mod

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require (
2323
cloud.google.com/go/storage v1.56.1 // indirect
2424
dario.cat/mergo v1.0.2 // indirect
2525
github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 // indirect
26-
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0 // indirect
26+
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20250520111509-a70c2aa677fa // indirect
2727
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c // indirect
2828
github.com/CycloneDX/cyclonedx-go v0.9.2 // indirect
2929
github.com/DataDog/zstd v1.5.7 // indirect
@@ -41,16 +41,16 @@ require (
4141
github.com/adrg/xdg v0.5.3 // indirect
4242
github.com/agext/levenshtein v1.2.3 // indirect
4343
github.com/anchore/archiver/v3 v3.5.3-0.20241210171143-5b1d8d1c7c51 // indirect
44-
github.com/anchore/clio v0.0.0-20250319180342-2cfe4b0cb716 // indirect
45-
github.com/anchore/fangs v0.0.0-20250319222917-446a1e748ec2 // indirect
46-
github.com/anchore/go-collections v0.0.0-20240216171411-9321230ce537 // indirect
44+
github.com/anchore/clio v0.0.0-20250908162139-4390b5d3d46e // indirect
45+
github.com/anchore/fangs v0.0.0-20250908220736-f686ade3235a // indirect
46+
github.com/anchore/go-collections v0.0.0-20250717130425-e4a173a279ef // indirect
4747
github.com/anchore/go-homedir v0.0.0-20250319154043-c29668562e4d // indirect
48-
github.com/anchore/go-logger v0.0.0-20250318195838-07ae343dd722 // indirect
48+
github.com/anchore/go-logger v0.0.0-20250813181427-74728f89a619 // indirect
4949
github.com/anchore/go-lzo v0.1.0 // indirect
50-
github.com/anchore/go-macholibre v0.0.0-20220308212642-53e6d0aaf6fb // indirect
50+
github.com/anchore/go-macholibre v0.0.0-20250826193721-3cd206ca93aa // indirect
5151
github.com/anchore/go-rpmdb v0.0.0-20250516171929-f77691e1faec // indirect
52-
github.com/anchore/go-struct-converter v0.0.0-20221221214134-65614c61201e // indirect
53-
github.com/anchore/go-sync v0.0.0-20250326131806-4eda43a485b6 // indirect
52+
github.com/anchore/go-struct-converter v0.0.0-20250211213226-cce56d595160 // indirect
53+
github.com/anchore/go-sync v0.0.0-20250826180238-74d8443d8ac6 // indirect
5454
github.com/anchore/go-version v1.2.2-0.20200701162849-18adb9c92b9b // indirect
5555
github.com/anchore/packageurl-go v0.1.1-0.20250220190351-d62adb6e1115 // indirect
5656
github.com/anchore/stereoscope v0.1.9 // indirect
@@ -80,7 +80,7 @@ require (
8080
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
8181
github.com/becheran/wildmatch-go v1.0.0 // indirect
8282
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
83-
github.com/bitnami/go-version v0.0.0-20250131085805-b1f57a8634ef // indirect
83+
github.com/bitnami/go-version v0.0.0-20250826054534-3a75c1206244 // indirect
8484
github.com/blakesmith/ar v0.0.0-20190502131153-809d4375e1fb // indirect
8585
github.com/bmatcuk/doublestar/v4 v4.9.1 // indirect
8686
github.com/bodgit/plumbing v1.3.0 // indirect
@@ -110,15 +110,15 @@ require (
110110
github.com/cpuguy83/dockercfg v0.3.2 // indirect
111111
github.com/cyphar/filepath-securejoin v0.4.1 // indirect
112112
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
113-
github.com/deitch/magic v0.0.0-20230404182410-1ff89d7342da // indirect
113+
github.com/deitch/magic v0.0.0-20240306090643-c67ab88f10cb // indirect
114114
github.com/diskfs/go-diskfs v1.7.0 // indirect
115115
github.com/distribution/reference v0.6.0 // indirect
116116
github.com/docker/cli v28.4.0+incompatible // indirect
117117
github.com/docker/distribution v2.8.3+incompatible // indirect
118118
github.com/docker/docker v28.4.0+incompatible // indirect
119119
github.com/docker/docker-credential-helpers v0.9.3 // indirect
120120
github.com/docker/go-connections v0.6.0 // indirect
121-
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect
121+
github.com/docker/go-events v0.0.0-20250808211157-605354379745 // indirect
122122
github.com/docker/go-units v0.5.0 // indirect
123123
github.com/dsnet/compress v0.0.2-0.20230904184137-39efe44ab707 // indirect
124124
github.com/dustin/go-humanize v1.0.1 // indirect
@@ -151,7 +151,7 @@ require (
151151
github.com/google/go-cmp v0.7.0 // indirect
152152
github.com/google/go-containerregistry v0.20.6 // indirect
153153
github.com/google/licensecheck v0.3.1 // indirect
154-
github.com/google/pprof v0.0.0-20250820193118-f64d9cf942d6 // indirect
154+
github.com/google/pprof v0.0.0-20250903194437-c28834ac2320 // indirect
155155
github.com/google/s2a-go v0.1.9 // indirect
156156
github.com/google/uuid v1.6.0 // indirect
157157
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
@@ -208,7 +208,7 @@ require (
208208
github.com/nwaples/rardecode/v2 v2.1.1 // indirect
209209
github.com/oklog/ulid v1.3.1 // indirect
210210
github.com/oklog/ulid/v2 v2.1.1 // indirect
211-
github.com/olekukonko/cat v0.0.0-20250808191157-46fba99501f3 // indirect
211+
github.com/olekukonko/cat v0.0.0-20250908003013-b0de306c343b // indirect
212212
github.com/olekukonko/errors v1.1.0 // indirect
213213
github.com/olekukonko/ll v0.1.1 // indirect
214214
github.com/olekukonko/tablewriter v1.0.9 // indirect
@@ -242,7 +242,7 @@ require (
242242
github.com/skeema/knownhosts v1.3.1 // indirect
243243
github.com/sorairolake/lzip-go v0.3.8 // indirect
244244
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
245-
github.com/spdx/gordf v0.0.0-20201111095634-7098f93598fb // indirect
245+
github.com/spdx/gordf v0.0.0-20250128162952-000978ccd6fb // indirect
246246
github.com/spdx/tools-golang v0.5.5 // indirect
247247
github.com/spf13/afero v1.15.0 // indirect
248248
github.com/spf13/cast v1.10.0 // indirect
@@ -282,7 +282,7 @@ require (
282282
go.yaml.in/yaml/v3 v3.0.4 // indirect
283283
go4.org v0.0.0-20230225012048-214862532bf5 // indirect
284284
golang.org/x/crypto v0.42.0 // indirect
285-
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b // indirect
285+
golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b // indirect
286286
golang.org/x/mod v0.28.0 // indirect
287287
golang.org/x/net v0.44.0 // indirect
288288
golang.org/x/oauth2 v0.31.0 // indirect
@@ -292,11 +292,11 @@ require (
292292
golang.org/x/text v0.29.0 // indirect
293293
golang.org/x/time v0.13.0 // indirect
294294
golang.org/x/tools v0.36.0 // indirect
295-
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
295+
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
296296
google.golang.org/api v0.249.0 // indirect
297-
google.golang.org/genproto v0.0.0-20250603155806-513f23925822 // indirect
298-
google.golang.org/genproto/googleapis/api v0.0.0-20250818200422-3122310a409c // indirect
299-
google.golang.org/genproto/googleapis/rpc v0.0.0-20250825161204-c5933d9347a5 // indirect
297+
google.golang.org/genproto v0.0.0-20250908214217-97024824d090 // indirect
298+
google.golang.org/genproto/googleapis/api v0.0.0-20250908214217-97024824d090 // indirect
299+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250908214217-97024824d090 // indirect
300300
google.golang.org/grpc v1.75.1 // indirect
301301
google.golang.org/protobuf v1.36.9 // indirect
302302
gopkg.in/warnings.v0 v0.1.2 // indirect

0 commit comments

Comments
 (0)