From ba10da7eb9d9db9c0d21d0722083fe439d282de3 Mon Sep 17 00:00:00 2001 From: Matej Vasek Date: Tue, 29 Sep 2020 17:44:51 +0200 Subject: [PATCH] feat: JVM mode builds for Quarkus --- Makefile | 22 +++++---- builders/quarkus-jvm/builder.toml | 16 +++++++ builders/quarkus-native/builder.toml | 16 +++++++ builders/quarkus/builder.toml | 16 ------- buildpacks/quarkus-jvm/bin/build | 45 +++++++++++++++++++ .../{quarkus => quarkus-jvm}/bin/detect | 0 .../{quarkus => quarkus-jvm}/buildpack.toml | 4 +- .../{quarkus => quarkus-native}/bin/build | 0 buildpacks/quarkus-native/bin/detect | 11 +++++ buildpacks/quarkus-native/buildpack.toml | 9 ++++ packages/quarkus-jvm/package.toml | 2 + packages/quarkus-native/package.toml | 2 + packages/quarkus/package.toml | 2 - stacks/quarkus-jvm/build/Dockerfile | 20 +++++++++ stacks/quarkus-jvm/run/Dockerfile | 35 +++++++++++++++ stacks/quarkus-native/build/Dockerfile | 27 +++++++++++ .../run/Dockerfile | 0 stacks/quarkus/build/Dockerfile | 25 ----------- 18 files changed, 199 insertions(+), 53 deletions(-) create mode 100644 builders/quarkus-jvm/builder.toml create mode 100644 builders/quarkus-native/builder.toml delete mode 100644 builders/quarkus/builder.toml create mode 100755 buildpacks/quarkus-jvm/bin/build rename buildpacks/{quarkus => quarkus-jvm}/bin/detect (100%) rename buildpacks/{quarkus => quarkus-jvm}/buildpack.toml (54%) rename buildpacks/{quarkus => quarkus-native}/bin/build (100%) create mode 100755 buildpacks/quarkus-native/bin/detect create mode 100644 buildpacks/quarkus-native/buildpack.toml create mode 100644 packages/quarkus-jvm/package.toml create mode 100644 packages/quarkus-native/package.toml delete mode 100644 packages/quarkus/package.toml create mode 100644 stacks/quarkus-jvm/build/Dockerfile create mode 100644 stacks/quarkus-jvm/run/Dockerfile create mode 100644 stacks/quarkus-native/build/Dockerfile rename stacks/{quarkus => quarkus-native}/run/Dockerfile (100%) delete mode 100644 stacks/quarkus/build/Dockerfile diff --git a/Makefile b/Makefile index 0867c39..aed4a5b 100644 --- a/Makefile +++ b/Makefile @@ -7,13 +7,15 @@ BASE_REPO := quay.io/boson/faas-stack-base BUILD_REPO := quay.io/boson/faas-stack-build RUN_REPO := quay.io/boson/faas-stack-run -QUARKUS_BUILDER_REPO := quay.io/boson/faas-quarkus-builder NODEJS_BUILDER_REPO := quay.io/boson/faas-nodejs-builder GO_BUILDER_REPO := quay.io/boson/faas-go-builder +QUARKUS_JVM_BUILDER_REPO := quay.io/boson/faas-quarkus-jvm-builder +QUARKUS_NATIVE_BUILDER_REPO := quay.io/boson/faas-quarkus-native-builder -QUARKUS_BUILDPACK_REPO := quay.io/boson/faas-quarkus-bp NODEJS_BUILDPACK_REPO := quay.io/boson/faas-nodejs-bp GO_BUILDPACK_REPO := quay.io/boson/faas-go-bp +QUARKUS_JVM_BUILDPACK_REPO := quay.io/boson/faas-quarkus-jvm-bp +QUARKUS_NATIVE_BUILDPACK_REPO := quay.io/boson/faas-quarkus-native-bp .PHONY: stacks buildpacks builders @@ -23,34 +25,38 @@ stacks: ./stacks/build-stack.sh -v $(VERSION_TAG) stacks/ubi8 ./stacks/build-stack.sh -v $(VERSION_TAG) stacks/ubi8-minimal ./stacks/build-stack.sh -v $(VERSION_TAG) stacks/nodejs - ./stacks/build-stack.sh -v $(VERSION_TAG) stacks/quarkus ./stacks/build-stack.sh -v $(VERSION_TAG) stacks/go + ./stacks/build-stack.sh -v $(VERSION_TAG) stacks/quarkus-jvm + ./stacks/build-stack.sh -v $(VERSION_TAG) stacks/quarkus-native buildpacks: $(PACK_CMD) package-buildpack $(NODEJS_BUILDPACK_REPO):$(VERSION_TAG) --config ./packages/nodejs/package.toml - $(PACK_CMD) package-buildpack $(QUARKUS_BUILDPACK_REPO):$(VERSION_TAG) --config ./packages/quarkus/package.toml $(PACK_CMD) package-buildpack $(GO_BUILDPACK_REPO):$(VERSION_TAG) --config ./packages/go/package.toml + $(PACK_CMD) package-buildpack $(QUARKUS_JVM_BUILDPACK_REPO):$(VERSION_TAG) --config ./packages/quarkus-jvm/package.toml + $(PACK_CMD) package-buildpack $(QUARKUS_NATIVE_BUILDPACK_REPO):$(VERSION_TAG) --config ./packages/quarkus-native/package.toml builders: TMP_BLDRS=$(shell mktemp -d) && \ sed "s/{{VERSION}}/$(VERSION_TAG)/g" ./builders/nodejs/builder.toml > $$TMP_BLDRS/node.toml && \ - sed "s/{{VERSION}}/$(VERSION_TAG)/g" ./builders/quarkus/builder.toml > $$TMP_BLDRS/quarkus.toml && \ + sed "s/{{VERSION}}/$(VERSION_TAG)/g" ./builders/quarkus-native/builder.toml > $$TMP_BLDRS/quarkus-native.toml && \ sed "s/{{VERSION}}/$(VERSION_TAG)/g" ./builders/go/builder.toml > $$TMP_BLDRS/go.toml && \ + sed "s/{{VERSION}}/$(VERSION_TAG)/g" ./builders/quarkus-jvm/builder.toml > $$TMP_BLDRS/quarkus-jvm.toml && \ $(PACK_CMD) create-builder $(NODEJS_BUILDER_REPO):$(VERSION_TAG) --config $$TMP_BLDRS/node.toml && \ - $(PACK_CMD) create-builder $(QUARKUS_BUILDER_REPO):$(VERSION_TAG) --config $$TMP_BLDRS/quarkus.toml && \ $(PACK_CMD) create-builder $(GO_BUILDER_REPO):$(VERSION_TAG) --config $$TMP_BLDRS/go.toml && \ + $(PACK_CMD) create-builder $(QUARKUS_JVM_BUILDER_REPO):$(VERSION_TAG) --config $$TMP_BLDRS/quarkus-jvm.toml && \ + $(PACK_CMD) create-builder $(QUARKUS_NATIVE_BUILDER_REPO):$(VERSION_TAG) --config $$TMP_BLDRS/quarkus-native.toml && \ rm -fr $$TMP_BLDRS publish: docker push $(BASE_REPO):ubi8-minimal-$(VERSION_TAG) docker push $(BASE_REPO):ubi8-$(VERSION_TAG) - for i in go quarkus nodejs ubi8-minimal ubi8; do \ + for i in go quarkus-native quarkus-jvm nodejs ubi8-minimal ubi8; do \ docker push $(RUN_REPO):$$i-$(VERSION_TAG); \ docker push $(BUILD_REPO):$$i-$(VERSION_TAG); \ done - for img in $(QUARKUS_BUILDPACK_REPO) $(NODEJS_BUILDPACK_REPO) $(GO_BUILDPACK_REPO) $(QUARKUS_BUILDER_REPO) $(NODEJS_BUILDER_REPO) $(GO_BUILDER_REPO); do \ + for img in $(QUARKUS_NATIVE_BUILDPACK_REPO) $(QUARKUS_JVM_BUILDPACK_REPO) $(QUARKUS_NATIVE_BUILDER_REPO) $(QUARKUS_JVM_BUILDER_REPO) $(NODEJS_BUILDPACK_REPO) $(GO_BUILDPACK_REPO) $(NODEJS_BUILDER_REPO) $(GO_BUILDER_REPO); do \ docker push $$img:$(VERSION_TAG); \ if [ "$(VERSION_TAG)" != "tip" ]; then \ docker tag $$img:$(VERSION_TAG) $$img:latest; \ diff --git a/builders/quarkus-jvm/builder.toml b/builders/quarkus-jvm/builder.toml new file mode 100644 index 0000000..5db5f5f --- /dev/null +++ b/builders/quarkus-jvm/builder.toml @@ -0,0 +1,16 @@ +# Buildpacks to include in builder +[[buildpacks]] +id = "com.redhat.faas.quarkus-jvm" +image = "quay.io/boson/faas-quarkus-jvm-bp:{{VERSION}}" + +[[order]] +[[order.group]] +id = "com.redhat.faas.quarkus-jvm" + +# Stack that will be used by the builder +[stack] + id = "com.redhat.faas.stacks.quarkus-jvm" + # This image is used at runtime + run-image = "quay.io/boson/faas-stack-run:quarkus-jvm-{{VERSION}}" + # This image is used at build-time + build-image = "quay.io/boson/faas-stack-build:quarkus-jvm-{{VERSION}}" diff --git a/builders/quarkus-native/builder.toml b/builders/quarkus-native/builder.toml new file mode 100644 index 0000000..82a26ad --- /dev/null +++ b/builders/quarkus-native/builder.toml @@ -0,0 +1,16 @@ +# Buildpacks to include in builder +[[buildpacks]] +id = "com.redhat.faas.quarkus-native" +image = "quay.io/boson/faas-quarkus-native-bp:{{VERSION}}" + +[[order]] +[[order.group]] +id = "com.redhat.faas.quarkus-native" + +# Stack that will be used by the builder +[stack] + id = "com.redhat.faas.stacks.quarkus-native" + # This image is used at runtime + run-image = "quay.io/boson/faas-stack-run:quarkus-native-{{VERSION}}" + # This image is used at build-time + build-image = "quay.io/boson/faas-stack-build:quarkus-native-{{VERSION}}" diff --git a/builders/quarkus/builder.toml b/builders/quarkus/builder.toml deleted file mode 100644 index 777e072..0000000 --- a/builders/quarkus/builder.toml +++ /dev/null @@ -1,16 +0,0 @@ -# Buildpacks to include in builder -[[buildpacks]] -id = "com.redhat.faas.quarkus" -image = "quay.io/boson/faas-quarkus-bp:{{VERSION}}" - -[[order]] -[[order.group]] -id = "com.redhat.faas.quarkus" - -# Stack that will be used by the builder -[stack] - id = "com.redhat.faas.stacks.quarkus" - # This image is used at runtime - run-image = "quay.io/boson/faas-stack-run:quarkus-{{VERSION}}" - # This image is used at build-time - build-image = "quay.io/boson/faas-stack-build:quarkus-{{VERSION}}" diff --git a/buildpacks/quarkus-jvm/bin/build b/buildpacks/quarkus-jvm/bin/build new file mode 100755 index 0000000..820c282 --- /dev/null +++ b/buildpacks/quarkus-jvm/bin/build @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +set -e +set -o pipefail + +echo "$@" + +echo "---> Quarkus Functions Buildpack" + +build_dir=$(pwd) +bp_dir=$(cd "$(dirname "$0")"/..; pwd) +layers_dir=$1 +platform_dir=$2 + + +mvn_repo_layer="${layers_dir}/mvn_repo" + +mkdir -p "${mvn_repo_layer}" +cat < "${mvn_repo_layer}.toml" +launch = false +build = true +cache = true +TOML + +mvn -B -Dmaven.repo.local="${mvn_repo_layer}" package -DskipTests +runner_jar=$(find target -maxdepth 1 -iname "*-runner.jar") +lib=$(find target -maxdepth 1 -iname "lib") + +app_layer="${layers_dir}/app" +mkdir -p "${app_layer}" +cat < "${app_layer}.toml" +launch = true +build = false +cache = false +TOML + +cp "${runner_jar}" "${app_layer}/app.jar" +cp "${lib}" "${app_layer}" -r + +rm -fr target src pom.xml + +cat < "${layers_dir}/launch.toml" +[[processes]] +type = "web" +command = "JAVA_APP_DIR=${app_layer} run-java.sh" +TOML diff --git a/buildpacks/quarkus/bin/detect b/buildpacks/quarkus-jvm/bin/detect similarity index 100% rename from buildpacks/quarkus/bin/detect rename to buildpacks/quarkus-jvm/bin/detect diff --git a/buildpacks/quarkus/buildpack.toml b/buildpacks/quarkus-jvm/buildpack.toml similarity index 54% rename from buildpacks/quarkus/buildpack.toml rename to buildpacks/quarkus-jvm/buildpack.toml index 8d7142b..2acf3f1 100644 --- a/buildpacks/quarkus/buildpack.toml +++ b/buildpacks/quarkus-jvm/buildpack.toml @@ -1,9 +1,9 @@ api = "0.2" [buildpack] -id = "com.redhat.faas.quarkus" +id = "com.redhat.faas.quarkus-jvm" version = "0.0.1" name = "Quarkus Function Buildpack" [[stacks]] -id = "com.redhat.faas.stacks.quarkus" +id = "com.redhat.faas.stacks.quarkus-jvm" diff --git a/buildpacks/quarkus/bin/build b/buildpacks/quarkus-native/bin/build similarity index 100% rename from buildpacks/quarkus/bin/build rename to buildpacks/quarkus-native/bin/build diff --git a/buildpacks/quarkus-native/bin/detect b/buildpacks/quarkus-native/bin/detect new file mode 100755 index 0000000..fcb5f66 --- /dev/null +++ b/buildpacks/quarkus-native/bin/detect @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +set -eo pipefail + +dep_xpath='/*[local-name()="project"]' +dep_xpath+='/*[local-name()="dependencies"]' +dep_xpath+='/*[local-name()="dependency"]' +dep_xpath+='/*[local-name()="artifactId" and contains(.,"quarkus-funqy")]' + +if ! xmllint --xpath "${dep_xpath}" pom.xml > /dev/null 2> /dev/null; then + exit 100 +fi diff --git a/buildpacks/quarkus-native/buildpack.toml b/buildpacks/quarkus-native/buildpack.toml new file mode 100644 index 0000000..1775b98 --- /dev/null +++ b/buildpacks/quarkus-native/buildpack.toml @@ -0,0 +1,9 @@ +api = "0.2" + +[buildpack] +id = "com.redhat.faas.quarkus-native" +version = "0.0.1" +name = "Quarkus Function Buildpack (native mode)" + +[[stacks]] +id = "com.redhat.faas.stacks.quarkus-native" diff --git a/packages/quarkus-jvm/package.toml b/packages/quarkus-jvm/package.toml new file mode 100644 index 0000000..02d871f --- /dev/null +++ b/packages/quarkus-jvm/package.toml @@ -0,0 +1,2 @@ +[buildpack] +uri = "../../buildpacks/quarkus-jvm" diff --git a/packages/quarkus-native/package.toml b/packages/quarkus-native/package.toml new file mode 100644 index 0000000..b1d6469 --- /dev/null +++ b/packages/quarkus-native/package.toml @@ -0,0 +1,2 @@ +[buildpack] +uri = "../../buildpacks/quarkus-native" diff --git a/packages/quarkus/package.toml b/packages/quarkus/package.toml deleted file mode 100644 index 8a78659..0000000 --- a/packages/quarkus/package.toml +++ /dev/null @@ -1,2 +0,0 @@ -[buildpack] -uri = "../../buildpacks/quarkus" diff --git a/stacks/quarkus-jvm/build/Dockerfile b/stacks/quarkus-jvm/build/Dockerfile new file mode 100644 index 0000000..741d6cf --- /dev/null +++ b/stacks/quarkus-jvm/build/Dockerfile @@ -0,0 +1,20 @@ +ARG version=tip +FROM quay.io/boson/faas-stack-build:ubi8-${version} + +ARG stack_id +ENV CNB_STACK_ID=${stack_id} +LABEL io.buildpacks.stack.id=${stack_id} + +ENV HOME /projects/quarkus-function +WORKDIR $HOME + +USER root + +RUN dnf module install -y maven:3.6 \ + && dnf install -y wget maven tar gzip java-11-openjdk-headless \ + && dnf update -y \ + && dnf clean all -y \ + && chown cnb:cnb $HOME + +USER cnb + diff --git a/stacks/quarkus-jvm/run/Dockerfile b/stacks/quarkus-jvm/run/Dockerfile new file mode 100644 index 0000000..fbc92f5 --- /dev/null +++ b/stacks/quarkus-jvm/run/Dockerfile @@ -0,0 +1,35 @@ +ARG version=tip +FROM quay.io/boson/faas-stack-run:ubi8-minimal-${version} + +ARG stack_id +ENV CNB_STACK_ID=${stack_id} +LABEL io.buildpacks.stack.id=${stack_id} + +ENV HOME /projects/quarkus-function +WORKDIR $HOME +USER root + +ARG JAVA_PACKAGE=java-11-openjdk-headless +ARG RUN_JAVA_VERSION=1.3.8 + +ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' + +# Install java and the run-java script +# Also set up permissions for user `1001` +RUN microdnf install curl ca-certificates ${JAVA_PACKAGE} \ + && microdnf update \ + && microdnf clean all \ + && curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION}-sh.sh -o /usr/local/bin/run-java.sh \ + && chmod "a+rx" /usr/local/bin/run-java.sh \ + && echo "securerandom.source=file:/dev/urandom" >> /etc/alternatives/jre/lib/security/java.security \ + && chown cnb:cnb $HOME + +# Configure the JAVA_OPTIONS, you can add -XshowSettings:vm to also display the heap size. +ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" + +USER cnb + +ENV PORT 8080 + +EXPOSE 8080 +EXPOSE 5005 diff --git a/stacks/quarkus-native/build/Dockerfile b/stacks/quarkus-native/build/Dockerfile new file mode 100644 index 0000000..ff16fa7 --- /dev/null +++ b/stacks/quarkus-native/build/Dockerfile @@ -0,0 +1,27 @@ +ARG version=tip +FROM quay.io/boson/faas-stack-build:ubi8-${version} + +ARG stack_id +ENV CNB_STACK_ID=${stack_id} +LABEL io.buildpacks.stack.id=${stack_id} + +ENV HOME /projects/quarkus-function +WORKDIR $HOME + +USER root +RUN dnf module install -y maven:3.6 \ + && dnf install -y wget maven tar gzip gcc glibc-devel zlib-devel \ + && dnf update -y \ + && dnf clean all -y \ + && chown cnb:cnb $HOME \ + && wget -q -O - "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-20.1.0/graalvm-ce-java11-linux-amd64-20.1.0.tar.gz" | \ + tar -xzf - -C /opt \ + && mv /opt/graalvm-ce-java11-20.1.0 /opt/graalvm \ + && /opt/graalvm/bin/gu --auto-yes install native-image + +ENV JAVA_HOME /opt/graalvm +ENV GRAALVM_HOME /opt/graalvm +ENV PATH $GRAALVM_HOME/bin:$PATH + +USER cnb + diff --git a/stacks/quarkus/run/Dockerfile b/stacks/quarkus-native/run/Dockerfile similarity index 100% rename from stacks/quarkus/run/Dockerfile rename to stacks/quarkus-native/run/Dockerfile diff --git a/stacks/quarkus/build/Dockerfile b/stacks/quarkus/build/Dockerfile deleted file mode 100644 index 0e18789..0000000 --- a/stacks/quarkus/build/Dockerfile +++ /dev/null @@ -1,25 +0,0 @@ -ARG version=tip -FROM quay.io/boson/faas-stack-build:ubi8-${version} - -ARG stack_id -ENV CNB_STACK_ID=${stack_id} -LABEL io.buildpacks.stack.id=${stack_id} - -USER root -RUN dnf module install -y maven:3.6 -RUN dnf install -y wget maven tar gzip gcc glibc-devel zlib-devel - -RUN wget -q -O - "https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-20.1.0/graalvm-ce-java11-linux-amd64-20.1.0.tar.gz" | \ - tar -xzf - -C /opt -RUN mv /opt/graalvm-ce-java11-20.1.0 /opt/graalvm -RUN /opt/graalvm/bin/gu --auto-yes install native-image - -ENV JAVA_HOME /opt/graalvm -ENV GRAALVM_HOME /opt/graalvm -ENV PATH $GRAALVM_HOME/bin:$PATH - -ENV HOME /projects/quarkus-function -WORKDIR $HOME -RUN chown cnb:cnb $HOME -USER cnb -