Skip to content

Commit

Permalink
Allow JRE/JDKs to be installed from alternative archives (e.g. .zip) (#…
Browse files Browse the repository at this point in the history
…155)

* Allow JRE/JDKs to be installed from alternative archives (e.g. .zip)
  • Loading branch information
garethjevans authored Mar 22, 2022
1 parent 929ad6c commit 35338e3
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 13 deletions.
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ require (
github.com/mattn/go-shellwords v1.0.12
github.com/miekg/dns v1.1.47
github.com/onsi/gomega v1.18.1
github.com/paketo-buildpacks/libpak v1.58.0
github.com/paketo-buildpacks/libpak v1.59.0
github.com/pavel-v-chernykh/keystore-go/v4 v4.3.0
github.com/sclevine/spec v1.4.0
golang.org/x/sys v0.0.0-20220207234003-57398862261d
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8
)

require (
github.com/BurntSushi/toml v1.0.0 // indirect
github.com/creack/pty v1.1.17 // indirect
github.com/h2non/filetype v1.1.3 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mattn/go-isatty v0.0.8 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
Expand Down
20 changes: 13 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/h2non/filetype v1.1.3 h1:FKkx9QbD7HR/zjK1Ia5XiBsq9zdLi5Kf3zGyFTAFkGg=
github.com/h2non/filetype v1.1.3/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY=
github.com/heroku/color v0.0.6 h1:UTFFMrmMLFcL3OweqP1lAdp8i1y/9oHqkeHjQ/b/Ny0=
github.com/heroku/color v0.0.6/go.mod h1:ZBvOcx7cTF2QKOv4LbmoBtNl5uB17qWxGuzZrsi1wLU=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
Expand All @@ -38,10 +40,12 @@ github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo=
github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=
github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
github.com/miekg/dns v1.1.47 h1:J9bWiXbqMbnZPcY8Qi2E3EWIBsIm6MZzzJB9VRg5gL8=
Expand All @@ -61,8 +65,8 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
github.com/paketo-buildpacks/libpak v1.58.0 h1:tId115h3SZn8IY8DQxRF36PwhMob4G9TVkWWDTD9MKY=
github.com/paketo-buildpacks/libpak v1.58.0/go.mod h1:qxRaH+WrJYWEb4FZqYkMR9mdyNEsrNOq7bE7O4dXH1k=
github.com/paketo-buildpacks/libpak v1.59.0 h1:9Kt1G0IZZbnIrgsfxU9SuAqJB5EBnVwNJqMgw5qFMa0=
github.com/paketo-buildpacks/libpak v1.59.0/go.mod h1:hqdnjXrMRmt25/tw+FLC3UbT2uQXH1et2zZ8Br3ZXAo=
github.com/pavel-v-chernykh/keystore-go/v4 v4.3.0 h1:TVckDDIKzWo9/cPdsvyikdmnnKIPeWgnGoekhQM5zBc=
github.com/pavel-v-chernykh/keystore-go/v4 v4.3.0/go.mod h1:VxOBKEAW8/EJjil9qwfvVDSljDW0DCoZMD4ezsq9n8U=
github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM=
Expand All @@ -76,8 +80,9 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down Expand Up @@ -118,9 +123,10 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220207234003-57398862261d h1:Bm7BNOQt2Qv7ZqysjeLjgCBanX+88Z/OtdvsrEv1Djc=
golang.org/x/sys v0.0.0-20220207234003-57398862261d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs=
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand Down
2 changes: 1 addition & 1 deletion jdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (j JDK) Contribute(layer libcnb.Layer) (libcnb.Layer, error) {

return j.LayerContributor.Contribute(layer, func(artifact *os.File) (libcnb.Layer, error) {
j.Logger.Bodyf("Expanding to %s", layer.Path)
if err := crush.ExtractTarGz(artifact, layer.Path, 1); err != nil {
if err := crush.Extract(artifact, layer.Path, 1); err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to expand JDK\n%w", err)
}

Expand Down
27 changes: 27 additions & 0 deletions jdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,33 @@ func testJDK(t *testing.T, context spec.G, it spec.S) {
Expect(layer.BuildEnvironment["JDK_HOME.override"]).To(Equal(layer.Path))
})

it("contributes JDK from a zip file", func() {
dep := libpak.BuildpackDependency{
Version: "11.0.0",
URI: "https://localhost/stub-jdk-11.zip",
SHA256: "8138da5a0340f89b47ec4ab3fb5f12034ce793eb45af257820ec457316559a39",
}
dc := libpak.DependencyCache{CachePath: "testdata"}

j, _, err := libjvm.NewJDK(dep, dc, cl)
Expect(err).NotTo(HaveOccurred())
j.Logger = bard.NewLogger(ioutil.Discard)

Expect(j.LayerContributor.ExpectedMetadata.(map[string]interface{})["cert-dir"]).To(HaveLen(4))

layer, err := ctx.Layers.Layer("test-layer")
Expect(err).NotTo(HaveOccurred())

layer, err = j.Contribute(layer)
Expect(err).NotTo(HaveOccurred())

Expect(layer.LayerTypes.Build).To(BeTrue())
Expect(layer.LayerTypes.Cache).To(BeTrue())
Expect(filepath.Join(layer.Path, "fixture-marker")).To(BeARegularFile())
Expect(layer.BuildEnvironment["JAVA_HOME.override"]).To(Equal(layer.Path))
Expect(layer.BuildEnvironment["JDK_HOME.override"]).To(Equal(layer.Path))
})

it("updates before Java 9 certificates", func() {
dep := libpak.BuildpackDependency{
Version: "8.0.0",
Expand Down
2 changes: 1 addition & 1 deletion jre.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (j JRE) Contribute(layer libcnb.Layer) (libcnb.Layer, error) {

return j.LayerContributor.Contribute(layer, func(artifact *os.File) (libcnb.Layer, error) {
j.Logger.Bodyf("Expanding to %s", layer.Path)
if err := crush.ExtractTarGz(artifact, layer.Path, 1); err != nil {
if err := crush.Extract(artifact, layer.Path, 1); err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to expand JRE\n%w", err)
}

Expand Down
23 changes: 23 additions & 0 deletions jre_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,29 @@ func testJRE(t *testing.T, context spec.G, it spec.S) {
Expect(filepath.Join(layer.Path, "fixture-marker")).To(BeARegularFile())
})

it("contributes JRE from a zip file", func() {
dep := libpak.BuildpackDependency{
Version: "11.0.0",
URI: "https://localhost/stub-jre-11.zip",
SHA256: "e3b22e738f6e956ef576215b39d79d321157f1d3de3bddf9c4120ae0444bdba8",
}
dc := libpak.DependencyCache{CachePath: "testdata"}

j, _, err := libjvm.NewJRE(ctx.Application.Path, dep, dc, libjvm.JREType, cl, NoContribution)
Expect(err).NotTo(HaveOccurred())
j.Logger = bard.NewLogger(ioutil.Discard)

Expect(j.LayerContributor.ExpectedMetadata.(map[string]interface{})["cert-dir"]).To(HaveLen(4))

layer, err := ctx.Layers.Layer("test-layer")
Expect(err).NotTo(HaveOccurred())

layer, err = j.Contribute(layer)
Expect(err).NotTo(HaveOccurred())

Expect(filepath.Join(layer.Path, "fixture-marker")).To(BeARegularFile())
})

it("updates JRE certificates", func() {
dep := libpak.BuildpackDependency{
Version: "11.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version = "11.0.0"
uri = "https://localhost/stub-jdk-11.zip"
sha256 = "8138da5a0340f89b47ec4ab3fb5f12034ce793eb45af257820ec457316559a39"
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version = "11.0.0"
uri = "https://localhost/stub-jre-11.zip"
sha256 = "e3b22e738f6e956ef576215b39d79d321157f1d3de3bddf9c4120ae0444bdba8"
Binary file not shown.

0 comments on commit 35338e3

Please sign in to comment.