Skip to content

Commit

Permalink
Add Java to UBI Builder (#33)
Browse files Browse the repository at this point in the history
* Add Java to builder

Signed-off-by: Ozzy Osborne <[email protected]>

* Add java tests

Signed-off-by: Ozzy Osborne <[email protected]>

* Add Java to Readme

Signed-off-by: Ozzy Osborne <[email protected]>

---------

Signed-off-by: Ozzy Osborne <[email protected]>
  • Loading branch information
BarDweller authored Nov 7, 2023
1 parent 052030f commit 96e27f0
Show file tree
Hide file tree
Showing 17 changed files with 817 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

This builder uses the [Paketo Ubi Base
Stack](https://github.com/paketo-community/ubi-base-stack) (ubi 8
build and run images) with buildpacks for Node.js.
build and run images) with buildpacks for Node.js and Java.

To see which versions of build and run images, buildpacks, and the lifecycle
that are contained within a given builder version, see the
Expand Down
65 changes: 55 additions & 10 deletions builder.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,73 @@
description = "Ubi 8 base image with buildpacks for Node.js"
description = "Ubi 8 base image with buildpacks for Node.js and Java"

[[buildpacks]]
uri = "docker://gcr.io/paketo-buildpacks/nodejs:2.0.0"
version = "2.0.0"
[[extensions]]
id = "paketo-community/ubi-java-extension"
uri = "docker://docker.io/paketocommunity/ubi-java-extension:0.1.1"
version = "0.1.1"

[[extensions]]
id = "paketo-community/ubi-nodejs-extension"
uri = "docker://docker.io/paketocommunity/ubi-nodejs-extension:0.0.3"
version = "0.0.3"

[lifecycle]
version = "0.18.1"
[[buildpacks]]
uri = "docker://docker.io/paketocommunity/ubi-java-buildpack:0.1.0"
version = "0.1.0"

[[buildpacks]]
uri = "docker://gcr.io/paketo-buildpacks/quarkus:0.2.4"
version = "0.2.4"

[[buildpacks]]
uri = "docker://gcr.io/paketo-buildpacks/java:10.3.0"
version = "10.3.0"

[[buildpacks]]
uri = "docker://gcr.io/paketo-buildpacks/nodejs:2.0.0"
version = "2.0.0"

[[order-extensions]]
[[order-extensions.group]]
id = "paketo-community/ubi-java-extension"
version = "0.1.1"
[[order-extensions.group]]
id = "paketo-community/ubi-nodejs-extension"
version = "0.0.3"

[[order]]
[[order.group]]
id = "paketo-community/ubi-java-buildpack"
version = "0.1.0"
[[order.group]]
id = "paketo-buildpacks/quarkus"
version = "0.2.4"
optional = true
[[order.group]]
id = "paketo-buildpacks/java"
version = "10.3.0"

[[order]]
[[order.group]]
id = "paketo-buildpacks/nodejs"
version = "2.0.0"

[[order-extensions]]
[lifecycle]
version = "0.18.1"

[[order-extensions.group]]
id = "paketo-community/ubi-nodejs-extension"
version = "0.0.3"
[run]
[[run.images]]
image = "docker.io/paketocommunity/run-java-8-ubi-base"
[[run.images]]
image = "docker.io/paketocommunity/run-java-11-ubi-base"
[[run.images]]
image = "docker.io/paketocommunity/run-java-17-ubi-base"
[[run.images]]
image = "docker.io/paketocommunity/run-nodejs-16-ubi-base"
[[run.images]]
image = "docker.io/paketocommunity/run-nodejs-18-ubi-base"

[build]
image = "docker.io/paketocommunity/build-ubi-base:0.0.10"

[stack]
build-image = "docker.io/paketocommunity/build-ubi-base:0.0.12"
Expand Down
21 changes: 16 additions & 5 deletions scripts/smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ source "${PROGDIR}/.util/tools.sh"
source "${PROGDIR}/.util/print.sh"

function main() {
local name token
local name token regport
token=""
regport=""

while [[ "${#}" != 0 ]]; do
case "${1}" in
Expand All @@ -34,6 +35,11 @@ function main() {
shift 2
;;

--regport|-p)
regport="${2}"
shift 2
;;

"")
# skip if the argument is empty
shift 1
Expand All @@ -52,12 +58,16 @@ function main() {
name="testbuilder"
fi

if [[ -z "${regport:-}" ]]; then
regport="5000"
fi

tools::install "${token}"

reg=$(docker run -d -p5000:5000 registry:2)
builder::create "localhost:5000/${name}"
docker push "localhost:5000/${name}"
tests::run "localhost:5000/${name}" $reg
reg=$(docker run -d -p$regport:5000 registry:2)
builder::create "localhost:$regport/${name}"
docker push "localhost:$regport/${name}"
tests::run "localhost:$regport/${name}" $reg
}

function usage() {
Expand All @@ -70,6 +80,7 @@ OPTIONS
--help -h prints the command usage
--name <name> -n <name> sets the name of the builder that is built for testing
--token <token> Token used to download assets from GitHub (e.g. jam, pack, etc) (optional)
--regport <port> Local port to use for registry during tests
USAGE
}

Expand Down
1 change: 1 addition & 0 deletions smoke/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ func TestSmoke(t *testing.T) {

suite := spec.New("Smoke", spec.Parallel(), spec.Report(report.Terminal{}))
suite("Node.js", testNodejs)
suite("Java", testJava)
suite.Run(t)
}
78 changes: 78 additions & 0 deletions smoke/java_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package smoke_test

import (
"fmt"
"os"
"path/filepath"
"testing"

"github.com/paketo-buildpacks/occam"
"github.com/sclevine/spec"

. "github.com/onsi/gomega"
. "github.com/paketo-buildpacks/occam/matchers"
)

func testJava(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
Eventually = NewWithT(t).Eventually

pack occam.Pack
docker occam.Docker
)

it.Before(func() {
pack = occam.NewPack().WithVerbose().WithNoColor()
docker = occam.NewDocker()
})

context("detects a Java app", func() {
var (
image occam.Image
container occam.Container

name string
source string
)

it.Before(func() {
var err error
name, err = occam.RandomName()
Expect(err).NotTo(HaveOccurred())
})

it.After(func() {
Expect(docker.Container.Remove.Execute(container.ID)).To(Succeed())
Expect(docker.Volume.Remove.Execute(occam.CacheVolumeNames(name))).To(Succeed())
Expect(docker.Image.Remove.Execute(image.ID)).To(Succeed())
Expect(os.RemoveAll(source)).To(Succeed())
})

it("builds successfully", func() {
var err error
source, err = occam.Source(filepath.Join("testdata", "java"))
Expect(err).NotTo(HaveOccurred())

var logs fmt.Stringer
image, logs, err = pack.Build.
WithNetwork("host").
WithPullPolicy("always").
WithBuilder(Builder).
Execute(name, source)
Expect(err).ToNot(HaveOccurred(), logs.String)

Expect(logs).To(ContainLines(ContainSubstring("Paketo UBI Java Extension")))
Expect(logs).To(ContainLines(ContainSubstring("Paketo UBI Java Helper Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("[extender (build)] Enabling module streams")))
Expect(logs).To(ContainLines(ContainSubstring("javapackages-runtime")))

container, err = docker.Container.Run.
WithPublishAll().
Execute(image.ID)
Expect(err).NotTo(HaveOccurred())

Eventually(container).Should(BeAvailable())
})
})
}
33 changes: 33 additions & 0 deletions smoke/testdata/java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
Binary file not shown.
2 changes: 2 additions & 0 deletions smoke/testdata/java/.mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar
1 change: 1 addition & 0 deletions smoke/testdata/java/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Simple example app for testing buildpack
Loading

0 comments on commit 96e27f0

Please sign in to comment.