Skip to content

Commit

Permalink
add java builder
Browse files Browse the repository at this point in the history
Signed-off-by: wanjunlei <[email protected]>
  • Loading branch information
wanjunlei committed Jul 8, 2022
1 parent b280a48 commit 85370c7
Show file tree
Hide file tree
Showing 34 changed files with 650 additions and 479 deletions.
7 changes: 7 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,10 @@ go_repository(
sum = "h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=",
version = "v1.23.0",
)

go_repository(
name = "com_github_beevik_etree",
importpath = "github.com/beevik/etree",
sum = "h1:T0xke/WvNtMoCqgzPhkX2r4rjY3GDZFi+FjpRZY2Jbs=",
version = "v1.1.0",
)
5 changes: 1 addition & 4 deletions builders/java11/BUILD.bazel → builders/java/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@ licenses(["notice"])
builder(
name = "builder",
buildpacks = [
"//cmd/config/entrypoint:entrypoint.tgz",
"//cmd/utils/label:label.tgz",
],
groups = {
"java": [
"//cmd/java/clear_source:clear_source.tgz",
"//cmd/java/entrypoint:entrypoint.tgz",
"//cmd/java/exploded_jar:exploded_jar.tgz",
"//cmd/java/functions_framework:functions_framework.tgz",
"//cmd/java/gradle:gradle.tgz",
"//cmd/java/maven:maven.tgz",
],
},
image = "of/java11",
image = "< REGISTRY >/builder-java:v2-< JAVA_VERSION >",
visibility = [
"//builders/java11/acceptance:__pkg__",
],
Expand Down
26 changes: 26 additions & 0 deletions builders/java/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## Build builder of java

Use the follow command to build a java builder.

```shell
hack/build.sh --with-stack --java-version < java_version > --docker-registry < registry >
```

This command will create three image:

```shell
< REGISTRY >/buildpacks-java< java_version >-run:v1
< REGISTRY >/buildpacks-java< java_version >-build:v1
< REGISTRY >/builder-java:v2-< java_version >
```

Parameters

- `with-stack` - If specified, it will also build the build image and run image too.
- `java-version` - The version of java, known value are 11, 16, 17, 18.
- `docker-registry` - The docker registry where the image pushed to, default is `openfunction`.
- `create-builder-only` - Only create the builder directory, and do not build image. The builder directory will be under `builders/java`.
- `build-image` - The image used to build builder.
- `run-image` - The image used to run the function.
- `out-image` - The name of generated builder image.
- `push-image` - If specified, it will push the image to the registry.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ const (
javaClearSource = "google.java.clear_source"
javaEntrypoint = "google.java.entrypoint"
javaExplodedJar = "google.java.exploded-jar"
javaGradle = "google.java.gradle"
javaMaven = "google.java.maven"
javaRuntime = "google.java.runtime"
javaGradle = "openfunction.java.gradle"
javaMaven = "openfunction.java.maven"
javaRuntime = "openfunction.java.runtime"
nodeFF = "openfunction.nodejs.functions-framework"
nodeNPM = "openfunction.nodejs.npm"
nodeRuntime = "openfunction.nodejs.runtime"
Expand Down
File renamed without changes.
File renamed without changes.
64 changes: 64 additions & 0 deletions builders/java/builder.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
description = "Ubuntu 18 base image with buildpacks for Nodejs"

[[buildpacks]]
id = "openfunction.java.functions-framework"
uri = "java/functions_framework.tgz"

[[buildpacks]]
id = "openfunction.java.gradle"
uri = "java/gradle.tgz"

[[buildpacks]]
id = "openfunction.java.maven"
uri = "java/maven.tgz"

[[buildpacks]]
id = "google.java.clear_source"
uri = "java/clear_source.tgz"

[[buildpacks]]
id = "google.utils.label"
uri = "label.tgz"

########
# Java #
########

# Functions have separate groups because entrypoint not supported.
[[order]]
[[order.group]]
id = "openfunction.java.maven"

[[order.group]]
id = "openfunction.java.functions-framework"

[[order.group]]
id = "google.java.clear_source"
optional = true

[[order.group]]
id = "google.utils.label"

[[order]]
[[order.group]]
id = "openfunction.java.gradle"
optional = true

[[order.group]]
id = "openfunction.java.functions-framework"

[[order.group]]
id = "google.java.clear_source"
optional = true

[[order.group]]
id = "google.utils.label"

# Currently built with //builders/java/stack/stack:build.
[stack]
id = "openfunction.java< JAVA_VERSION >"
build-image = "< REGISTRY >/buildpacks-java< JAVA_VERSION >-build:v1"
run-image = "< REGISTRY >/buildpacks-java< JAVA_VERSION >-run:v1"

[lifecycle]
version = "0.13.2"
File renamed without changes.
49 changes: 49 additions & 0 deletions builders/java/stack/build.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

ARG from_image
FROM ${from_image}

ARG cnb_uid=${CNB_USER_ID}
ENV cnb_gid=${CNB_GROUP_ID}

ARG maven_version=3.8.6
ARG gradle_version=7.4.2

COPY licenses/ /usr/local/share/licenses/buildpacks/

# unzip is required to extract gradle.
RUN apt-get update && apt-get install -y --no-install-recommends \
zip \
unzip \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

ADD https://downloads.apache.org/maven/maven-3/${maven_version}/binaries/apache-maven-${maven_version}-bin.tar.gz /
ADD https://services.gradle.org/distributions/gradle-${gradle_version}-bin.zip /

RUN mkdir /usr/local/maven && \
tar xzf apache-maven-${maven_version}-bin.tar.gz -C /usr/local/maven && \
rm -rf apache-maven-${maven_version}-bin.tar.gz && \
ln -s /usr/local/maven/apache-maven-${maven_version} /usr/local/maven/current && \
chown -R ${cnb_uid}:${cnb_gid} /usr/local/maven && \
mkdir /usr/local/gradle && \
unzip -q gradle-${gradle_version}-bin.zip -d /usr/local/gradle && \
rm -rf gradle-${gradle_version}-bin.zip && \
ln -s /usr/local/gradle/gradle-${gradle_version} /usr/local/gradle/current && \
chown -R ${cnb_uid}:${cnb_gid} /usr/local/gradle

ENV PATH=$PATH:/usr/local/maven/current/bin:/usr/local/gradle/current/bin

USER cnb

16 changes: 10 additions & 6 deletions builders/java11/stack/build.sh → builders/java/stack/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ echo "> Extracting licenses tar"
mkdir -p "$TEMP/licenses"
tar xf "$LICENSES" -C "$TEMP/licenses"

echo "> Building base java11common image"
docker build -t "java11common" - < "${DIR}/parent.Dockerfile"
echo "> Building openfunctiondev/buildpacks-java11-run:$TAG"
docker build --build-arg "from_image=java11common" -t "openfunctiondev/buildpacks-java11-run:$TAG" - < "${DIR}/run.Dockerfile"
echo "> Building openfunctiondev/buildpacks-java11-build:$TAG"
docker build --build-arg "from_image=java11common" -t "openfunctiondev/buildpacks-java11-build:$TAG" -f "${DIR}/build.Dockerfile" "${TEMP}"
echo "> Building base run image"
docker build --build-arg "from_image=ibm-semeru-runtimes:open-< JAVA_VERSION >-jre" -t "java< JAVA_VERSION >-run" - < "${DIR}/parent.Dockerfile"
echo "> Building base build image"
docker build --build-arg "from_image=ibm-semeru-runtimes:open-< JAVA_VERSION >-jdk" -t "java< JAVA_VERSION >-build" - < "${DIR}/parent.Dockerfile"
echo "> Building run imager"
docker build --build-arg "from_image=java< JAVA_VERSION >-run" -t "< REGISTRY >/buildpacks-java< JAVA_VERSION >-run:$TAG" - < "${DIR}/run.Dockerfile"
#docker push < REGISTRY >/buildpacks-java< JAVA_VERSION >-run:$TAG
echo "> Building build imager"
docker build --build-arg "from_image=java< JAVA_VERSION >-build" -t "< REGISTRY >/buildpacks-java< JAVA_VERSION >-build:$TAG" -f "${DIR}/build.Dockerfile" "${TEMP}"
#docker push < REGISTRY >/buildpacks-java< JAVA_VERSION >-build:$TAG
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM openfunctiondev/ubuntu_18_0_4
ARG from_image
FROM ${from_image}

ARG cnb_uid=1000
ARG cnb_gid=1000
ARG stack_id="google"

# Required by python/runtime: libexpat1, libffi6, libmpdecc2.
# Required by dotnet/runtime: libicu60
# Required by go/runtime: tzdata (Go may panic without /usr/share/zoneinfo)
RUN apt-get update && apt-get install -y --no-install-recommends \
libexpat1 \
libffi6 \
libmpdec2 \
libicu60 \
libc++1-9 \
tzdata \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
ARG stack_id="openfunction.java< JAVA_VERSION >"

LABEL io.buildpacks.stack.id=${stack_id}

RUN groupadd cnb --gid ${cnb_gid} && \
useradd --uid ${cnb_uid} --gid ${cnb_gid} -m -s /bin/bash cnb

RUN curl --fail --show-error --silent --location --retry 3 https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.11%2B9/OpenJDK11U-jdk_x64_linux_hotspot_11.0.11_9.tar.gz | tar xz --directory /usr/local --strip-components=1

ENV CNB_USER_ID=${cnb_uid}
ENV CNB_GROUP_ID=${cnb_gid}
ENV CNB_STACK_ID=${stack_id}
File renamed without changes.
116 changes: 0 additions & 116 deletions builders/java11/README.md

This file was deleted.

Loading

0 comments on commit 85370c7

Please sign in to comment.