Skip to content

Commit

Permalink
feat: add springboot buildpack/builder (#46)
Browse files Browse the repository at this point in the history
* fix: add springboot buildpack/builder

SpringBoot Buildpack and Builder for building Spring Cloud Functions

fix: #45

* removed extra spaces in stack
  • Loading branch information
kameshsampath authored Nov 24, 2020
1 parent 00c5e8b commit 141f6c5
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ 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
SPRINGBOOT_BUILDER_REPO := quay.io/boson/faas-springboot-builder

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
SPRINGBOOT_BUILDPACK_REPO := quay.io/boson/faas-springboot-bp


.PHONY: stacks buildpacks builders

Expand All @@ -28,23 +31,27 @@ stacks:
./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
./stacks/build-stack.sh -v $(VERSION_TAG) stacks/springboot

buildpacks:
$(PACK_CMD) package-buildpack $(NODEJS_BUILDPACK_REPO):$(VERSION_TAG) --config ./packages/nodejs/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
$(PACK_CMD) package-buildpack $(SPRINGBOOT_BUILDPACK_REPO):$(VERSION_TAG) --config ./packages/springboot/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-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 && \
sed "s/{{VERSION}}/$(VERSION_TAG)/g" ./builders/springboot/builder.toml > $$TMP_BLDRS/springboot.toml && \
$(PACK_CMD) create-builder $(NODEJS_BUILDER_REPO):$(VERSION_TAG) --config $$TMP_BLDRS/node.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 && \
$(PACK_CMD) create-builder $(SPRINGBOOT_BUILDER_REPO):$(VERSION_TAG) --config $$TMP_BLDRS/springboot.toml -v && \
rm -fr $$TMP_BLDRS

publish:
Expand All @@ -56,7 +63,7 @@ publish:
docker push $(BUILD_REPO):$$i-$(VERSION_TAG); \
done

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 \
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) $(SPRINGBOOT_BUILDPACK_REPO) $(SPRINGBOOT_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/springboot/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.springboot"
image = "quay.io/boson/faas-springboot-bp:{{VERSION}}"

[[order]]
[[order.group]]
id = "com.redhat.faas.springboot"

# Stack that will be used by the builder
[stack]
id = "com.redhat.faas.stacks.springboot"
# This image is used at runtime
run-image = "quay.io/boson/faas-stack-run:springboot-{{VERSION}}"
# This image is used at build-time
build-image = "quay.io/boson/faas-stack-build:springboot-{{VERSION}}"
47 changes: 47 additions & 0 deletions buildpacks/springboot/bin/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
set -e
set -o pipefail

echo "$@"

echo "---> Spring Cloud 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 "*.jar")

app_layer="${layers_dir}/app"
mkdir -p "${app_layer}"

cp -v "${runner_jar}" "${app_layer}/app.jar"

cat <<TOML > "${app_layer}.toml"
launch = true
build = false
cache = false
TOML

cp "${runner_jar}" "${app_layer}/app.jar"

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
11 changes: 11 additions & 0 deletions buildpacks/springboot/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(.,"spring-cloud-starter-function-web")]'

if ! xmllint --xpath "${dep_xpath}" pom.xml > /dev/null 2> /dev/null; then
exit 100
fi
9 changes: 9 additions & 0 deletions buildpacks/springboot/buildpack.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
api = "0.2"

[buildpack]
id = "com.redhat.faas.springboot"
version = "0.0.1"
name = "Spring Cloud Functions Buildpack"

[[stacks]]
id = "com.redhat.faas.stacks.springboot"
2 changes: 2 additions & 0 deletions packages/springboot/package.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[buildpack]
uri = "../../buildpacks/springboot"
20 changes: 20 additions & 0 deletions stacks/springboot/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/spring-cloud-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

33 changes: 33 additions & 0 deletions stacks/springboot/run/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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/spring-cloud-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


USER cnb

ENV PORT 8080

EXPOSE 8080
EXPOSE 5005

0 comments on commit 141f6c5

Please sign in to comment.