Skip to content

Commit 6b9f672

Browse files
committed
initial commit
0 parents  commit 6b9f672

File tree

8 files changed

+162
-0
lines changed

8 files changed

+162
-0
lines changed

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.gradle/
2+
.idea/*
3+
!.idea/codeStyles/
4+
build/
5+
*~
6+
*.swp
7+
*.iml
8+
local.properties
9+
.classpath
10+
.project
11+
.settings/
12+
out/
13+
.DS_Store
14+
/bin/
15+
/test-config/

Dockerfile

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
FROM public.ecr.aws/lambda/nodejs:14.2022.10.11.10-x86_64
2+
3+
ENV SIGNAL_CLI_VERSION=0.11.3
4+
ENV LIB_SIGNAL_VERSION=0.20.0
5+
6+
# install dependancies
7+
RUN yum -y update \
8+
&& yum install -y tar zip gzip bzip2-devel ed gcc gcc-c++ gcc-gfortran \
9+
less libcurl-devel openssl openssl-devel readline-devel xz-devel \
10+
zlib-devel glibc-static libcxx libcxx-devel llvm-toolset-7 zlib-static \
11+
findutils wget unzip protobuf-compiler cmake3 clang
12+
13+
# install java
14+
RUN wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm && \
15+
rpm -Uvh jdk-17_linux-x64_bin.rpm
16+
17+
# copy in pre-built libsignal_jni.so
18+
COPY ./libsignal-builds/libsignal_jni-${LIB_SIGNAL_VERSION}-x86_64.so /var/task/libsignal_jni.so
19+
20+
# setup signal-cli
21+
RUN wget https://github.com/AsamK/signal-cli/releases/download/v${SIGNAL_CLI_VERSION}/signal-cli-${SIGNAL_CLI_VERSION}-Linux.tar.gz && \
22+
tar xf signal-cli-${SIGNAL_CLI_VERSION}-Linux.tar.gz && \
23+
rm signal-cli-${SIGNAL_CLI_VERSION}-Linux.tar.gz && \
24+
zip -d signal-cli-${SIGNAL_CLI_VERSION}/lib/libsignal-client-*.jar libsignal_jni.so && \
25+
zip signal-cli-${SIGNAL_CLI_VERSION}/lib/libsignal-client-*.jar libsignal_jni.so
26+
27+
## move signal-cli
28+
RUN cp -R /var/task/signal-cli-$SIGNAL_CLI_VERSION/bin /opt && \
29+
cp -R /var/task/signal-cli-$SIGNAL_CLI_VERSION/lib /opt
30+
31+
# setup minimum JRE
32+
RUN jlink --add-modules "$(java --list-modules | cut -f1 -d'@' | tr '\n' ',')" --compress 0 --no-man-pages --no-header-files --strip-debug --output /opt/jre17
33+
RUN find /opt/jre17/lib -name *.so -exec strip -p --strip-unneeded {} \;
34+
RUN java -Xshare:dump -version
35+
RUN rm /opt/jre17/lib/classlist && \
36+
cp /usr/java/jdk-17.*/lib/server/classes.jsa /opt/jre17/lib/server/classes.jsa
37+
38+
# dependancies for signal-cli
39+
RUN cp /usr/bin/xargs /opt/bin && \
40+
cp /usr/bin/sed /opt/bin && \
41+
cp /usr/bin/uname /opt/bin && \
42+
cp /usr/bin/tr /opt/bin
43+
44+
# boostrap for lambda layer
45+
RUN touch /opt/bootstrap && \
46+
printf '#!/bin/sh\n\n/opt/jre17/bin/java --add-opens java.base/java.util=ALL-UNNAMED -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Xshare:on -cp "/opt/aws-lambda-java-runtime-interface-client-1.1.0.jar:/opt/aws-lambda-java-core-1.2.1.jar:/opt/aws-lambda-java-serialization-1.0.0.jar:$LAMBDA_TASK_ROOT:$LAMBDA_TASK_ROOT/*:$LAMBDA_TASK_ROOT/lib/*" com.amazonaws.services.lambda.runtime.api.client.AWSLambda "$_HANDLER"' > /opt/bootstrap && \
47+
chmod 755 /opt/bootstrap
48+
RUN curl -4 -L https://repo.maven.apache.org/maven2/com/amazonaws/aws-lambda-java-runtime-interface-client/1.1.0/aws-lambda-java-runtime-interface-client-1.1.0.jar -o /opt/aws-lambda-java-runtime-interface-client-1.1.0.jar && \
49+
curl -4 -L https://repo.maven.apache.org/maven2/com/amazonaws/aws-lambda-java-core/1.2.1/aws-lambda-java-core-1.2.1.jar -o /opt/aws-lambda-java-core-1.2.1.jar && \
50+
curl -4 -L https://repo.maven.apache.org/maven2/com/amazonaws/aws-lambda-java-serialization/1.0.0/aws-lambda-java-serialization-1.0.0.jar -o /opt/aws-lambda-java-serialization-1.0.0.jar
51+
52+
# zip up layer
53+
RUN cd /opt/ && \
54+
find . -type f -exec zip layer.zip {} +
55+
56+
# you can now export layer with following command:
57+
# docker cp <container id>:/opt/layer.zip <output folder>

generate-libsignal/Dockerfile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
## This script generates the libsignal_jni.so required to run signal-cli for lambda
2+
## It will out put the file libsignal_jni.so in the root (/root/libsignal_jni.so).
3+
4+
FROM public.ecr.aws/lambda/nodejs:14.2022.10.11.10-x86_64
5+
6+
ENV LIB_SIGNAL_VERSION=0.20.0
7+
8+
# install dependancies
9+
RUN yum -y update \
10+
&& yum install -y tar zip gzip bzip2-devel ed gcc gcc-c++ gcc-gfortran \
11+
less libcurl-devel openssl openssl-devel readline-devel xz-devel \
12+
zlib-devel glibc-static libcxx libcxx-devel llvm-toolset-7 zlib-static \
13+
findutils wget unzip protobuf-compiler cmake3 clang
14+
15+
# map cmake to cmake3
16+
RUN ln -s /usr/bin/cmake3 /usr/bin/cmake
17+
18+
# install java
19+
RUN wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm && \
20+
rpm -Uvh jdk-17_linux-x64_bin.rpm && \
21+
export JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::") && \
22+
export PATH=$JAVA_HOME/bin:$PATH
23+
24+
# install gradle
25+
RUN wget https://services.gradle.org/distributions/gradle-5.0-bin.zip && \
26+
unzip -d /opt/gradle gradle-*.zip && \
27+
export GRADLE_HOME=/opt/gradle/gradle-5.0 && \
28+
export PATH=${GRADLE_HOME}/bin:${PATH}
29+
30+
# install rust
31+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | bash -s -- -y
32+
RUN source "$HOME/.cargo/env" && \
33+
rustup default nightly
34+
35+
# get libsignal
36+
RUN wget https://github.com/signalapp/libsignal/archive/refs/tags/v${LIB_SIGNAL_VERSION}.zip -O ./libsignal-${LIB_SIGNAL_VERSION}.zip && \
37+
unzip libsignal-${LIB_SIGNAL_VERSION}.zip
38+
39+
# build libsignal
40+
RUN source "$HOME/.cargo/env" && \
41+
cd libsignal-${LIB_SIGNAL_VERSION}/java && \
42+
sed -i "s/include ':android'//" settings.gradle && \
43+
cp ../target/release/libsignal_jni.so ~/

generate-libsignal/readme.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Create libsignal_jni.so
2+
3+
This script generates the libsignal_jni.so required to run signal-cli for lambda.
4+
5+
It will out put the file libsignal_jni.so in the root (/root/libsignal_jni.so).
6+
7+
8+
## Build libsignal
9+
Each version of signal-cli requires its own version of libsignal. This needs to be built in the same architecture as the lambda base.
10+
11+
1. Setup the correct lambda runtime, libsignal versions inside the Dockerfile
12+
2. Update the [JRE version](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html) for the correct architecture e.g. [x86_64](https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm), [aarch64/arm64](https://download.oracle.com/java/17/archive/jdk-17.0.5_linux-aarch64_bin.rpm)
13+
3. Build using docker: `docker build -t libsignal`
14+
4. Copy the layer.zip to the host `docker cp <instance id>:/root/libsignal_jni.so <output destination>`
18.3 MB
Binary file not shown.
17.9 MB
Binary file not shown.

libsignal-builds/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Previous build libsignal builds

readme.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Signal CLI lambda layer
2+
3+
A lambda layer that allows use of the [Signal CLI](https://github.com/AsamK/signal-cli) with lambda.
4+
5+
## Use prebuilt
6+
| Lambda Runtime | Architecture | Signal CLI | Libsignal | &nbsp;
7+
| - | - | - | - | - |
8+
| Node.js 14.x | x86_64 | 0.11.3 | 0.20.0 | [Download](https://github.com/dtaylor7/signal-cli-lambda-layer/releases/download/0.11.3/node14-86_64-signalcli_0.11.3.zip)
9+
10+
## Usage
11+
12+
Upload the layer zip to S3 and create a lambda layer. Add the following environment variables the lambda function using the layer:
13+
14+
| Name | Value | Note |
15+
| - | - | - |
16+
| JAVA_HOME | /opt/jre17 | Set JAVA_HOME
17+
| HOME | /tmp | Set directory for signal cli. Suggest you change this for each invocation of lambda
18+
| XDG_DATA_HOME | /tmp | Set directory for signal cli. Suggest you change this for each invocation of lambda
19+
20+
The cli will be globally available within the lambda layer .eg `signal-cli -a ACCOUNT register`
21+
22+
## Build
23+
24+
1. Setup the correct lambda runtime, signal cli, libsignal versions inside the Dockerfile
25+
2. Update the [JRE version](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html) for the correct architecture e.g. [x86_64](https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm), [aarch64/arm64](https://download.oracle.com/java/17/archive/jdk-17.0.5_linux-aarch64_bin.rpm)
26+
3. Build using docker: `docker build -t signal-cli-lambda-layer`
27+
4. Copy the layer.zip to the host `docker cp <instance id>:/opt/layer.zip <output destination>`
28+
29+
## Build libsignal
30+
Each version of signal-cli requires its own version of libsignal. This needs to be built in the same architecture as the lambda base.
31+
32+
Follow instructions in /generate-libsignal

0 commit comments

Comments
 (0)