From 2ee33b57126925a8ab4f584952c033adcb82fa3b Mon Sep 17 00:00:00 2001 From: Michael Hart Date: Wed, 12 Aug 2020 15:39:57 -0400 Subject: [PATCH] Add java8.al2 runtime --- .gitignore | 2 + README.md | 2 + .../org.eclipse.buildship.core.prefs | 2 +- base/dump-java8al2/.classpath | 12 +++ base/dump-java8al2/.project | 23 +++++ .../org.eclipse.buildship.core.prefs | 13 +++ .../org.eclipse.core.resources.prefs | 2 + .../.settings/org.eclipse.jdt.core.prefs | 8 ++ base/dump-java8al2/build.gradle | 28 ++++++ .../java/org/lambci/lambda/DumpJava8.java | 88 +++++++++++++++++++ base/publish-all.sh | 2 +- base/tag-all.sh | 2 +- base/test-all.sh | 1 + docker-lambda.code-workspace | 3 + .../org.eclipse.buildship.core.prefs | 2 +- java8.al2/build/Dockerfile | 20 +++++ java8.al2/run/Dockerfile | 21 +++++ 17 files changed, 227 insertions(+), 4 deletions(-) create mode 100644 base/dump-java8al2/.classpath create mode 100644 base/dump-java8al2/.project create mode 100644 base/dump-java8al2/.settings/org.eclipse.buildship.core.prefs create mode 100644 base/dump-java8al2/.settings/org.eclipse.core.resources.prefs create mode 100644 base/dump-java8al2/.settings/org.eclipse.jdt.core.prefs create mode 100644 base/dump-java8al2/build.gradle create mode 100644 base/dump-java8al2/src/main/java/org/lambci/lambda/DumpJava8.java create mode 100644 java8.al2/build/Dockerfile create mode 100644 java8.al2/run/Dockerfile diff --git a/.gitignore b/.gitignore index 4525d854..4a897231 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,8 @@ base/diff-2 base/tar-find-layer/layer.zip base/dump-java8/bin base/dump-java8/build +base/dump-java8al2/bin +base/dump-java8al2/build base/dump-java11/bin base/dump-java11/build base/dump-dotnetcore20/bin diff --git a/README.md b/README.md index ce2b5d1a..5e0dc318 100644 --- a/README.md +++ b/README.md @@ -310,6 +310,7 @@ These follow the Lambda runtime names: - `ruby2.5` - `ruby2.7` - `java8` + - `java8.al2` - `java11` - `go1.x` - `dotnetcore2.0` @@ -328,6 +329,7 @@ These follow the Lambda runtime names: - `build-ruby2.5` - `build-ruby2.7` - `build-java8` + - `build-java8.al2` - `build-java11` - `build-go1.x` - `build-dotnetcore2.0` diff --git a/base/dump-java8/.settings/org.eclipse.buildship.core.prefs b/base/dump-java8/.settings/org.eclipse.buildship.core.prefs index 39c6821c..90865998 100644 --- a/base/dump-java8/.settings/org.eclipse.buildship.core.prefs +++ b/base/dump-java8/.settings/org.eclipse.buildship.core.prefs @@ -1,7 +1,7 @@ arguments= auto.sync=false build.scans.enabled=false -connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.0-20191016123526+0000)) +connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.3)) connection.project.dir= eclipse.preferences.version=1 gradle.user.home= diff --git a/base/dump-java8al2/.classpath b/base/dump-java8al2/.classpath new file mode 100644 index 00000000..4857be40 --- /dev/null +++ b/base/dump-java8al2/.classpath @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/base/dump-java8al2/.project b/base/dump-java8al2/.project new file mode 100644 index 00000000..0e30deb7 --- /dev/null +++ b/base/dump-java8al2/.project @@ -0,0 +1,23 @@ + + + dump-java8 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.buildship.core.gradleprojectbuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.buildship.core.gradleprojectnature + + diff --git a/base/dump-java8al2/.settings/org.eclipse.buildship.core.prefs b/base/dump-java8al2/.settings/org.eclipse.buildship.core.prefs new file mode 100644 index 00000000..90865998 --- /dev/null +++ b/base/dump-java8al2/.settings/org.eclipse.buildship.core.prefs @@ -0,0 +1,13 @@ +arguments= +auto.sync=false +build.scans.enabled=false +connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.3)) +connection.project.dir= +eclipse.preferences.version=1 +gradle.user.home= +java.home= +jvm.arguments= +offline.mode=false +override.workspace.settings=true +show.console.view=true +show.executions.view=true diff --git a/base/dump-java8al2/.settings/org.eclipse.core.resources.prefs b/base/dump-java8al2/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000..2b763404 --- /dev/null +++ b/base/dump-java8al2/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 diff --git a/base/dump-java8al2/.settings/org.eclipse.jdt.core.prefs b/base/dump-java8al2/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..2f5cc74c --- /dev/null +++ b/base/dump-java8al2/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/base/dump-java8al2/build.gradle b/base/dump-java8al2/build.gradle new file mode 100644 index 00000000..77e5fb16 --- /dev/null +++ b/base/dump-java8al2/build.gradle @@ -0,0 +1,28 @@ +apply plugin: 'java' + +sourceCompatibility = '1.8' +targetCompatibility = '1.8' + +repositories { + mavenCentral() +} + +dependencies { + implementation ( + 'com.amazonaws:aws-lambda-java-core:1.2.0', + 'com.amazonaws:aws-lambda-java-events:2.2.7', + 'com.amazonaws:aws-java-sdk-s3:1.11.681' + ) +} + +task buildZip(type: Zip) { + from compileJava + from processResources + into('lib') { + from configurations.runtimeClasspath + } +} + +build.dependsOn buildZip + +// docker run --rm -v "$PWD":/app -w /app gradle:jdk8 gradle build diff --git a/base/dump-java8al2/src/main/java/org/lambci/lambda/DumpJava8.java b/base/dump-java8al2/src/main/java/org/lambci/lambda/DumpJava8.java new file mode 100644 index 00000000..f842aa4a --- /dev/null +++ b/base/dump-java8al2/src/main/java/org/lambci/lambda/DumpJava8.java @@ -0,0 +1,88 @@ +package org.lambci.lambda; + +import java.io.File; +import java.io.IOException; +import java.lang.InterruptedException; +import java.lang.management.ManagementFactory; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Map; +import java.util.Scanner; + +import com.amazonaws.services.lambda.runtime.Context; +import com.amazonaws.services.lambda.runtime.RequestHandler; +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.AmazonS3ClientBuilder; +import com.amazonaws.services.s3.model.CannedAccessControlList; +import com.amazonaws.services.s3.model.PutObjectRequest; +import com.amazonaws.services.s3.model.PutObjectResult; + +public class DumpJava8 implements RequestHandler { + + @Override + public PutObjectResult handleRequest(Object input, Context context) { + String filename = "java8.al2.tgz"; + String cmd = "tar -cpzf /tmp/" + filename + " --numeric-owner --ignore-failed-read /var/runtime /var/lang"; + AmazonS3 s3client = AmazonS3ClientBuilder.standard().withRegion("us-east-1").build(); + + System.out.println(ManagementFactory.getRuntimeMXBean().getInputArguments().toString()); + System.out.println(System.getProperty("sun.java.command")); + System.out.println(System.getProperty("java.home")); + System.out.println(System.getProperty("java.library.path")); + System.out.println(System.getProperty("java.class.path")); + System.out.println(System.getProperty("user.dir")); + System.out.println(System.getProperty("user.home")); + System.out.println(System.getProperty("user.name")); + System.out.println(new File(".").getAbsolutePath()); + Map env = System.getenv(); + for (String envName : env.keySet()) { + System.out.println(envName + "=" + env.get(envName)); + } + + try { + int pid = Integer.parseInt(new File("/proc/self").getCanonicalFile().getName()); + + System.out.println("Parent cmdline:"); + System.out.println(new String(Files.readAllBytes(Paths.get("/proc/1/cmdline"))).replace("\0", " ")); + + System.out.println("Parent env:"); + runShell("xargs --null --max-args=1 < /proc/1/environ"); + + System.out.println("This cmdline:"); + System.out.println(new String(Files.readAllBytes(Paths.get("/proc/" + pid + "/cmdline"))).replace("\0", " ")); + + System.out.println("This env:"); + runShell("xargs --null --max-args=1 < /proc/" + pid + "/environ"); + + if (runShell(cmd) != 0) { + return null; + } + + System.out.println("Zipping done! Uploading..."); + + return s3client.putObject(new PutObjectRequest("lambci", "fs/" + filename, new File("/tmp/" + filename)) + .withCannedAcl(CannedAccessControlList.PublicRead)); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public static int runShell(String cmd) throws IOException, InterruptedException { + Process process = Runtime.getRuntime().exec(new String[] { "sh", "-c", cmd }); + + try (Scanner stdoutScanner = new Scanner(process.getInputStream()); + Scanner stderrScanner = new Scanner(process.getErrorStream())) { + // Echo all stdout first + while (stdoutScanner.hasNextLine()) { + System.out.println(stdoutScanner.nextLine()); + } + // Then echo stderr + while (stderrScanner.hasNextLine()) { + System.err.println(stderrScanner.nextLine()); + } + } + + process.waitFor(); + return process.exitValue(); + } +} diff --git a/base/publish-all.sh b/base/publish-all.sh index 53bfce6b..e1580b82 100755 --- a/base/publish-all.sh +++ b/base/publish-all.sh @@ -1,6 +1,6 @@ #!/bin/bash -RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 python2.7 python3.6 python3.7 ruby2.5 java8 dotnetcore2.0 dotnetcore2.1 nodejs10.x nodejs12.x python3.8 ruby2.7 java11 dotnetcore3.1" +RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 python2.7 python3.6 python3.7 ruby2.5 java8 dotnetcore2.0 dotnetcore2.1 nodejs10.x nodejs12.x python3.8 ruby2.7 java8.al2 java11 dotnetcore3.1" echo -n "Enter repository passphrase: " read -s DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE diff --git a/base/tag-all.sh b/base/tag-all.sh index 8b9c0827..c68f7292 100755 --- a/base/tag-all.sh +++ b/base/tag-all.sh @@ -1,6 +1,6 @@ #!/bin/bash -RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 python2.7 python3.6 python3.7 ruby2.5 java8 dotnetcore2.0 dotnetcore2.1 nodejs10.x nodejs12.x python3.8 ruby2.7 java11 dotnetcore3.1" +RUNTIMES="provided go1.x nodejs4.3 nodejs6.10 nodejs8.10 python2.7 python3.6 python3.7 ruby2.5 java8 dotnetcore2.0 dotnetcore2.1 nodejs10.x nodejs12.x python3.8 ruby2.7 java8.al2 java11 dotnetcore3.1" git tag -f latest diff --git a/base/test-all.sh b/base/test-all.sh index aa0e1a8c..044cd6ee 100755 --- a/base/test-all.sh +++ b/base/test-all.sh @@ -36,6 +36,7 @@ docker run --rm -v "$PWD":/var/task lambci/lambda:ruby2.7 lambda_function.lambda cd ${EXAMPLES_DIR}/java docker run --rm -v "$PWD":/app -w /app lambci/lambda:build-java8 gradle build docker run --rm -v "$PWD/build/docker":/var/task lambci/lambda:java8 org.lambci.lambda.ExampleHandler '{"some": "event"}' +docker run --rm -v "$PWD/build/docker":/var/task lambci/lambda:java8.al2 org.lambci.lambda.ExampleHandler '{"some": "event"}' docker run --rm -v "$PWD/build/docker":/var/task lambci/lambda:java11 org.lambci.lambda.ExampleHandler '{"some": "event"}' cd ${EXAMPLES_DIR}/dotnetcore2.0 diff --git a/docker-lambda.code-workspace b/docker-lambda.code-workspace index 32ca28b3..975aee7f 100644 --- a/docker-lambda.code-workspace +++ b/docker-lambda.code-workspace @@ -21,6 +21,9 @@ { "path": "base/dump-java8" }, + { + "path": "base/dump-java8al2" + }, { "path": "examples/java" }, diff --git a/examples/java/.settings/org.eclipse.buildship.core.prefs b/examples/java/.settings/org.eclipse.buildship.core.prefs index 39c6821c..90865998 100644 --- a/examples/java/.settings/org.eclipse.buildship.core.prefs +++ b/examples/java/.settings/org.eclipse.buildship.core.prefs @@ -1,7 +1,7 @@ arguments= auto.sync=false build.scans.enabled=false -connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.0-20191016123526+0000)) +connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.3)) connection.project.dir= eclipse.preferences.version=1 gradle.user.home= diff --git a/java8.al2/build/Dockerfile b/java8.al2/build/Dockerfile new file mode 100644 index 00000000..df669031 --- /dev/null +++ b/java8.al2/build/Dockerfile @@ -0,0 +1,20 @@ +FROM lambci/lambda-base-2:build + +ENV AWS_EXECUTION_ENV=AWS_Lambda_rapid + +WORKDIR / + +RUN rm -rf /var/runtime /var/lang && \ + curl https://lambci.s3.amazonaws.com/fs/java8.tgz | tar -zx -C / && \ + yum install -y java-1.8.0-openjdk-devel && \ + mkdir /usr/local/gradle && curl -L -o gradle.zip https://services.gradle.org/distributions/gradle-6.6-bin.zip && \ + unzip -d /usr/local/gradle gradle.zip && rm gradle.zip && mkdir /usr/local/maven && \ + curl -L http://mirror.cc.columbia.edu/pub/software/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz | \ + tar -zx -C /usr/local/maven + +ENV PATH="/usr/local/gradle/gradle-6.6/bin:/usr/local/maven/apache-maven-3.6.3/bin:${PATH}" + +# Add these as a separate layer as they get updated frequently +RUN pipx install awscli==1.* && \ + pipx install aws-lambda-builders==1.0.0 && \ + pipx install aws-sam-cli==1.0.0 diff --git a/java8.al2/run/Dockerfile b/java8.al2/run/Dockerfile new file mode 100644 index 00000000..7c912988 --- /dev/null +++ b/java8.al2/run/Dockerfile @@ -0,0 +1,21 @@ +FROM lambci/lambda-base + +RUN curl https://lambci.s3.amazonaws.com/fs/java8.al2.tgz | tar -zx -C /opt + + +FROM lambci/lambda:provided + + +FROM lambci/lambda-base-2 + +ENV PATH=/var/lang/bin:$PATH \ + LD_LIBRARY_PATH=/var/lang/lib:$LD_LIBRARY_PATH \ + AWS_EXECUTION_ENV=AWS_Lambda_rapid + +COPY --from=0 /opt/* /var/ + +COPY --from=1 /var/runtime/init /var/rapid/init + +USER sbx_user1051 + +ENTRYPOINT ["/var/rapid/init", "--bootstrap", "/var/runtime/bootstrap", "--enable-msg-logs"]