Skip to content

Commit

Permalink
feat: JVM mode builds for Quarkus
Browse files Browse the repository at this point in the history
  • Loading branch information
matejvasek authored Sep 29, 2020
1 parent 955ada8 commit ba10da7
Show file tree
Hide file tree
Showing 18 changed files with 199 additions and 53 deletions.
22 changes: 14 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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; \
Expand Down
16 changes: 16 additions & 0 deletions builders/quarkus-jvm/builder.toml
Original file line number Diff line number Diff line change
@@ -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}}"
16 changes: 16 additions & 0 deletions builders/quarkus-native/builder.toml
Original file line number Diff line number Diff line change
@@ -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}}"
16 changes: 0 additions & 16 deletions builders/quarkus/builder.toml

This file was deleted.

45 changes: 45 additions & 0 deletions buildpacks/quarkus-jvm/bin/build
Original file line number Diff line number Diff line change
@@ -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 <<TOML > "${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 <<TOML > "${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 <<TOML > "${layers_dir}/launch.toml"
[[processes]]
type = "web"
command = "JAVA_APP_DIR=${app_layer} run-java.sh"
TOML
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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"
File renamed without changes.
11 changes: 11 additions & 0 deletions buildpacks/quarkus-native/bin/detect
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions buildpacks/quarkus-native/buildpack.toml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 2 additions & 0 deletions packages/quarkus-jvm/package.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[buildpack]
uri = "../../buildpacks/quarkus-jvm"
2 changes: 2 additions & 0 deletions packages/quarkus-native/package.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[buildpack]
uri = "../../buildpacks/quarkus-native"
2 changes: 0 additions & 2 deletions packages/quarkus/package.toml

This file was deleted.

20 changes: 20 additions & 0 deletions stacks/quarkus-jvm/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

35 changes: 35 additions & 0 deletions stacks/quarkus-jvm/run/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions stacks/quarkus-native/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

File renamed without changes.
25 changes: 0 additions & 25 deletions stacks/quarkus/build/Dockerfile

This file was deleted.

0 comments on commit ba10da7

Please sign in to comment.