-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad7c444
commit 5121910
Showing
5 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
amazonlinux-java-graal-community-lambda-runtime/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# install base linux + tools | ||
ARG AWS_LINUX_VERSION=2.0.20230119.1 | ||
FROM amazonlinux:$AWS_LINUX_VERSION | ||
|
||
RUN yum install -y gcc gcc-c++ libc6-dev binutils zlib1g-dev curl bash zlib zlib-devel tar zip gzip | ||
|
||
# get graal... | ||
ARG JAVA_VERSION=jdk-21.0.0 | ||
ENV LANG=en_US.UTF-8 | ||
ENV GRAAL_FILENAME=graalvm-community-${JAVA_VERSION}_linux-x64_bin.tar.gz | ||
ENV GRAAL_URL=https://github.com/graalvm/graalvm-ce-builds/releases/download/${JAVA_VERSION}/${GRAAL_FILENAME} | ||
RUN echo $GRAAL_URL | ||
RUN curl -4 -L $GRAAL_URL -o /tmp/${GRAAL_FILENAME} | ||
|
||
RUN tar -zxvf /tmp/${GRAAL_FILENAME} -C /tmp && mv /tmp/${GRAAL_FILENAME} /usr/lib/graalvm | ||
RUN rm -rf /tmp/* | ||
|
||
# add lambda runtime bootstrap script | ||
COPY bootstrap . | ||
RUN chmod 777 bootstrap | ||
|
||
# add script to create native executable and zip it | ||
COPY packageZip . | ||
RUN chmod 777 packageZip | ||
|
||
# set entry point script - this takes 2 args: | ||
# 1. the input UberJar | ||
# 2. the path to the output ZIP (optional, defaults to function.zip) | ||
ENTRYPOINT ["./packageZip"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# http4k/amazonlinux-java-graal-ce-lambda-runtime | ||
|
||
This image builds a runtime ZIP file containing a Java GraalVM binary for Amazon Linux. It is designed to work with a ShadowJar containing an http4k AWS Lambda function and, given a tasteful selection of technologies, should not require any customisation of the GraalVM configuration. | ||
|
||
Basic usage for an example project. Arguments to the docker run command: | ||
1. UBERJAR_PATH = path the UberJar. This is loaded from inside the container at source/<UBERJAR_PATH> | ||
2. OUTPUT_ZIP_PATH (optional) = path to the output Zipfile. Defaults to source/function.zip | ||
|
||
```shell | ||
./gradlew shadowJar | ||
docker run -v $(pwd):/source \ | ||
http4k/amazonlinux-java-graal-ce-lambda-runtime:latest <UBERJAR_PATH> <OUTPUT_ZIP_PATH?> | ||
``` | ||
|
||
The Docker image itself includes 2 script files loaded from this repo: | ||
- **bootstrap** - the standard bootstrap file used by the Aws Lambda runner. Detects and passes the lambda memory settings to the JVM. | ||
- **packageZip** - takes the input ShadowJar (renamed to function.jar), uses `native-image` to create a native binary, and creates the function.zip package. | ||
|
||
Images are hosted in [DockerHub](https://hub.docker.com/r/http4k) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
set -euo pipefail | ||
./function -Xmx"$AWS_LAMBDA_FUNCTION_MEMORY_SIZE"m -Djava.library.path=$(pwd) |
12 changes: 12 additions & 0 deletions
12
amazonlinux-java-graal-community-lambda-runtime/build-and-push.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
set -eu | ||
export AWS_LINUX_VERSION=2.0.20230119.1 | ||
export JAVA_VERSION=$1 | ||
|
||
docker build --build-arg AWS_LINUX_VERSION=$AWS_LINUX_VERSION \ | ||
--build-arg JAVA_VERSION="$JAVA_VERSION" \ | ||
-t http4k/amazonlinux-java-graal-community-lambda-runtime \ | ||
-t http4k/amazonlinux-java-graal-community-lambda-runtime:latest \ | ||
-t http4k/amazonlinux-java-graal-community-lambda-runtime:amazonlinux$AWS_LINUX_VERSION-"$JAVA_VERSION" . | ||
|
||
docker push -a http4k/amazonlinux-java-graal-community-lambda-runtime |
15 changes: 15 additions & 0 deletions
15
amazonlinux-java-graal-community-lambda-runtime/packageZip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/sh | ||
set -euo pipefail | ||
|
||
cp source/"$1" ./function.jar | ||
FUNCTION_ZIP="${2:-function.zip}" | ||
|
||
echo Creating native-image... | ||
/usr/lib/graalvm/bin/native-image --enable-url-protocols=https -H:+ReportExceptionStackTraces --no-server -jar function.jar function | ||
chmod 777 function | ||
|
||
echo Building ZIP... | ||
mkdir -p $(dirname source/"$FUNCTION_ZIP") | ||
zip -j source/"$FUNCTION_ZIP" bootstrap function | ||
|
||
echo Done! |