Skip to content

Commit b4a9522

Browse files
committed
Ensure at build time that the jni parts of the runtime-interface-client are compiled for the correct architectures
1 parent 2448acc commit b4a9522

File tree

7 files changed

+74
-13
lines changed

7 files changed

+74
-13
lines changed

.github/workflows/aws-lambda-java-runtime-interface-client.yml

+36-5
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,56 @@ on:
88
branches: [ master ]
99
paths:
1010
- 'aws-lambda-java-runtime-interface-client/**'
11+
- '.github/workflows/**'
1112
pull_request:
1213
branches: [ '*' ]
1314
paths:
1415
- 'aws-lambda-java-runtime-interface-client/**'
1516

1617
jobs:
17-
build:
1818

19+
smoke-test:
1920
runs-on: ubuntu-latest
20-
2121
steps:
2222
- uses: actions/checkout@v2
23+
2324
- name: Set up JDK 1.8
2425
uses: actions/setup-java@v1
2526
with:
2627
java-version: 1.8
27-
28-
# Test Runtime Interface Client
29-
- name: Run 'pr' target
28+
29+
- name: Runtime Interface Client smoke tests - Run 'pr' target
3030
working-directory: ./aws-lambda-java-runtime-interface-client
3131
run: make pr
3232

33+
build:
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v2
37+
38+
- name: Set up JDK 1.8
39+
uses: actions/setup-java@v1
40+
with:
41+
java-version: 1.8
42+
43+
- name: Set up QEMU
44+
uses: docker/setup-qemu-action@v1
45+
46+
- name: Set up Docker Buildx
47+
uses: docker/setup-buildx-action@v1
48+
with:
49+
install: true
50+
51+
- name: Available buildx platforms
52+
run: echo ${{ steps.buildx.outputs.platforms }}
53+
54+
- name: Test Runtime Interface Client xplatform build - Run 'build' target
55+
working-directory: ./aws-lambda-java-runtime-interface-client
56+
run: make build
57+
58+
- name: Save the built jar
59+
uses: actions/upload-artifact@v3
60+
with:
61+
name: the-jar
62+
path: ./aws-lambda-java-runtime-interface-client/target/aws-lambda-java-runtime-interface-client-2.1.0.jar
63+

aws-lambda-java-runtime-interface-client/pom.xml

+10
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,21 @@
3030
</developer>
3131
</developers>
3232

33+
3334
<properties>
3435
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3536
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
3637
<maven.compiler.source>1.8</maven.compiler.source>
3738
<maven.compiler.target>1.8</maven.compiler.target>
3839
<jacoco.maven.plugin.version>0.8.7</jacoco.maven.plugin.version>
40+
<!--
41+
The test/integration/codebuild/buildspec.*.yml files will set -DmultiArch=false
42+
as a workaround for executing within Github Actions. At time of writing (2022-04-08) the
43+
integration tests, `make pr,` do not play nice with mixed `docker build`, `docker run`,
44+
when docker buildx+qemu is configured on Linux. So we'll test the multi-platform artifact build
45+
separately from the Runtime Interface Client functionality until we figure something else out.
46+
-->
47+
<multiArch>true</multiArch>
3948
</properties>
4049

4150
<dependencies>
@@ -96,6 +105,7 @@
96105
<target name="Build JNI libraries">
97106
<exec executable="${project.basedir}/src/main/jni/build-jni-lib.sh" failonerror="true" logError="true">
98107
<arg value="${project.build.directory}"/>
108+
<arg value="${multiArch}"/>
99109
</exec>
100110
</target>
101111
</configuration>

aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/runtimeapi/NativeClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static String getArchIdentifier() {
5959
if (arch.matches(supported_x86_architectures)) {
6060
return "x86_64";
6161
} else if (arch.matches(supported_arm_architectures)) {
62-
return "arm64";
62+
return "aarch64";
6363
}
6464

6565
throw new UnknownPlatformException("architecture not supported: " + arch);

aws-lambda-java-runtime-interface-client/src/main/jni/build-jni-lib.sh

+24-4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ set -euo pipefail
55

66
SRC_DIR=$(dirname "$0")
77
DST_DIR=${1}
8+
MULTI_ARCH=${2}
89
CURL_VERSION=7.77.0
910

1011
# Not using associative arrays to maintain bash 3 compatibility with building on MacOS
1112
# MacOS ships with bash 3 and associative arrays require bash 4+
1213
# Declaring a map as an array with the column character as a separator :
1314
declare -a ARCHITECTURES_TO_PLATFORM=(
1415
"x86_64:linux/amd64"
15-
"arm64:linux/arm64/v8"
16+
"aarch64:linux/arm64/v8"
1617
)
1718

1819
declare -a TARGETS=("glibc" "musl")
@@ -21,11 +22,30 @@ for pair in "${ARCHITECTURES_TO_PLATFORM[@]}"; do
2122
arch=${pair%%:*}
2223
platform=${pair#*:}
2324

24-
mkdir -p "${DST_DIR}"/classes/"${arch}"
25+
if [[ "${MULTI_ARCH}" != "true" ]] && [[ "$(arch)" != "${arch}" ]]; then
26+
echo "multi arch build not requested and host arch is $(arch), so skipping ${arch}:${platform} ..."
27+
continue
28+
fi
29+
30+
mkdir -p "${DST_DIR}/classes/${arch}"
2531

2632
for target in "${TARGETS[@]}"; do
2733
echo "Compiling the native library for target ${target} on architecture ${arch} using Docker platform ${platform}"
28-
docker build --platform="${platform}" -f "${SRC_DIR}"/Dockerfile."${target}" --build-arg CURL_VERSION=${CURL_VERSION} -t lambda-java-jni-lib-"${target}"-"${arch}" "${SRC_DIR}"
29-
docker run --rm --entrypoint /bin/cat lambda-java-jni-lib-"${target}"-"${arch}" /src/aws-lambda-runtime-interface-client.so > "${DST_DIR}"/classes/"${arch}"/aws-lambda-runtime-interface-client."${target}".so
34+
artifact="${DST_DIR}/classes/${arch}/aws-lambda-runtime-interface-client.${target}.so"
35+
36+
if [[ "${MULTI_ARCH}" == "true" ]]; then
37+
docker build --platform="${platform}" -f "${SRC_DIR}/Dockerfile.${target}" --build-arg CURL_VERSION=${CURL_VERSION} "${SRC_DIR}" -o - | tar -xOf - src/aws-lambda-runtime-interface-client.so > "${artifact}"
38+
else
39+
echo "multi-arch not requestsed, assuming this is a workaround to goofyness when docker buildx is enabled on Linux CI environments."
40+
echo "enabling docker buildx often updates the docker api version, so assuming that docker cli is also too old to use --output type=tar, so doing alternative build-tag-run approach"
41+
docker build --platform="${platform}" -t "lambda-java-jni-lib-${target}-${arch}" -f "${SRC_DIR}/Dockerfile.${target}" --build-arg CURL_VERSION=${CURL_VERSION} "${SRC_DIR}"
42+
docker run --rm --entrypoint /bin/cat "lambda-java-jni-lib-${target}-${arch}" /src/aws-lambda-runtime-interface-client.so > "${artifact}"
43+
fi
44+
45+
[ -f "${artifact}" ]
46+
if ! file -b "${artifact}" | tr '-' '_' | tee /dev/stderr | grep -q "${arch}"; then
47+
echo "${artifact} did not appear to be the correct architecture, check that Docker buildx is enabled"
48+
exit 1
49+
fi
3050
done
3151
done

aws-lambda-java-runtime-interface-client/test/integration/codebuild-local/Dockerfile.agent

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ FROM public.ecr.aws/amazoncorretto/amazoncorretto:8
22

33
RUN amazon-linux-extras enable docker && \
44
yum clean metadata && \
5-
yum install -y docker tar maven
5+
yum install -y docker tar maven unzip file

aws-lambda-java-runtime-interface-client/test/integration/codebuild/buildspec.os.alpine.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ phases:
3939
- (cd aws-lambda-java-events && mvn install)
4040
# Install serialization (dependency of RIC)
4141
- (cd aws-lambda-java-serialization && mvn install)
42-
- (cd aws-lambda-java-runtime-interface-client && mvn install)
42+
- (cd aws-lambda-java-runtime-interface-client && mvn install -DmultiArch=false)
4343
- (cd aws-lambda-java-runtime-interface-client/test/integration/test-handler && mvn install)
4444
- export IMAGE_TAG="java-${OS_DISTRIBUTION}-${DISTRO_VERSION}:${RUNTIME_VERSION}"
4545
- echo "Extracting and including Runtime Interface Emulator"

aws-lambda-java-runtime-interface-client/test/integration/codebuild/buildspec.os.amazoncorretto.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ phases:
3737
- (cd aws-lambda-java-events && mvn install)
3838
# Install serialization (dependency of RIC)
3939
- (cd aws-lambda-java-serialization && mvn install)
40-
- (cd aws-lambda-java-runtime-interface-client && mvn install)
40+
- (cd aws-lambda-java-runtime-interface-client && mvn install -DmultiArch=false)
4141
- (cd aws-lambda-java-runtime-interface-client/test/integration/test-handler && mvn install)
4242
- export IMAGE_TAG="java-${OS_DISTRIBUTION}-${DISTRO_VERSION}:${RUNTIME_VERSION}"
4343
- echo "Extracting and including Runtime Interface Emulator"

0 commit comments

Comments
 (0)