Skip to content

Commit

Permalink
Add java8.al2 runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
mhart committed Aug 12, 2020
1 parent 9b895e3 commit 2ee33b5
Show file tree
Hide file tree
Showing 17 changed files with 227 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ These follow the Lambda runtime names:
- `ruby2.5`
- `ruby2.7`
- `java8`
- `java8.al2`
- `java11`
- `go1.x`
- `dotnetcore2.0`
Expand All @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion base/dump-java8/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
12 changes: 12 additions & 0 deletions base/dump-java8al2/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="bin/main" path="src/main/java">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>
23 changes: 23 additions & 0 deletions base/dump-java8al2/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>dump-java8</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
13 changes: 13 additions & 0 deletions base/dump-java8al2/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions base/dump-java8al2/.settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
8 changes: 8 additions & 0 deletions base/dump-java8al2/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions base/dump-java8al2/build.gradle
Original file line number Diff line number Diff line change
@@ -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
88 changes: 88 additions & 0 deletions base/dump-java8al2/src/main/java/org/lambci/lambda/DumpJava8.java
Original file line number Diff line number Diff line change
@@ -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<Object, PutObjectResult> {

@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<String, String> 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();
}
}
2 changes: 1 addition & 1 deletion base/publish-all.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion base/tag-all.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 1 addition & 0 deletions base/test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions docker-lambda.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
{
"path": "base/dump-java8"
},
{
"path": "base/dump-java8al2"
},
{
"path": "examples/java"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/java/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
20 changes: 20 additions & 0 deletions java8.al2/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions java8.al2/run/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 2ee33b5

Please sign in to comment.