Skip to content

Commit

Permalink
fixed dockerfile for arm64 builds
Browse files Browse the repository at this point in the history
* build native extension BEFORE replacing platform specific
  zkgroup + libsignal-client, otherwise shared objects are overwritten
  by the x86-64 one.
  • Loading branch information
Bernhard B committed Feb 26, 2021
1 parent a1c2cd1 commit a862046
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ COPY ext/libraries/libsignal-client/v${LIBSIGNAL_CLIENT_VERSION} /tmp/libsignal-
# use architecture specific libzkgroup.so
RUN arch="$(uname -m)"; \
case "$arch" in \
aarch64) cp /tmp/zkgroup-libraries/arm64/libzkgroup.so /tmp/libzkgroup.so ;; \
armv7l) cp /tmp/zkgroup-libraries/armv7/libzkgroup.so /tmp/libzkgroup.so ;; \
x86_64) cp /tmp/zkgroup-libraries/x86-64/libzkgroup.so /tmp/libzkgroup.so ;; \
aarch64) echo "[DEBUG] Using arm64 zkgroup" && cp /tmp/zkgroup-libraries/arm64/libzkgroup.so /tmp/libzkgroup.so ;; \
armv7l) echo "[DEBUG] Using armv7 zkgroup" && cp /tmp/zkgroup-libraries/armv7/libzkgroup.so /tmp/libzkgroup.so ;; \
x86_64) echo "[DEBUG] Using x86-64 zkgroup" && cp /tmp/zkgroup-libraries/x86-64/libzkgroup.so /tmp/libzkgroup.so ;; \
*) echo "Unknown architecture" && exit 1 ;; \
esac;

# use architecture specific libsignal_jni.so
Expand All @@ -32,6 +33,7 @@ RUN arch="$(uname -m)"; \
aarch64) cp /tmp/libsignal-client-libraries/arm64/libsignal_jni.so /tmp/libsignal_jni.so ;; \
armv7l) cp /tmp/libsignal-client-libraries/armv7/libsignal_jni.so /tmp/libsignal_jni.so ;; \
x86_64) cp /tmp/libsignal-client-libraries/x86-64/libsignal_jni.so /tmp/libsignal_jni.so ;; \
*) echo "Unknown architecture" && exit 1 ;; \
esac;

RUN apt-get update \
Expand Down Expand Up @@ -62,6 +64,31 @@ RUN cd /tmp/ \
&& ./gradlew installDist \
&& ./gradlew distTar

# build native image with graalvm

RUN arch="$(uname -m)"; \
case "$arch" in \
aarch64) wget https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${GRAALVM_VERSION}/graalvm-ce-java${GRAALVM_JAVA_VERSION}-linux-aarch64-${GRAALVM_VERSION}.tar.gz -O /tmp/gvm.tar.gz ;; \
armv7l) echo "GRAALVM doesn't support 32bit" ;; \
x86_64) wget https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${GRAALVM_VERSION}/graalvm-ce-java${GRAALVM_JAVA_VERSION}-linux-amd64-${GRAALVM_VERSION}.tar.gz -O /tmp/gvm.tar.gz ;; \
esac;

RUN if [ "$(uname -m)" = "aarch64" ] || [ "$(uname -m)" = "x86_64" ]; then \
cd /tmp && tar xvf gvm.tar.gz \
&& export GRAALVM_HOME=/tmp/graalvm-ce-java${GRAALVM_JAVA_VERSION}-${GRAALVM_VERSION} \
&& cd /tmp/signal-cli-${SIGNAL_CLI_VERSION} \
&& chmod +x /tmp/graalvm-ce-java${GRAALVM_JAVA_VERSION}-${GRAALVM_VERSION}/bin/gu \
&& /tmp/graalvm-ce-java${GRAALVM_JAVA_VERSION}-${GRAALVM_VERSION}/bin/gu install native-image \
&& ./gradlew assembleNativeImage; \
elif [ "$(uname -m)" = "armv7l" ]; then \
echo "GRAALVM doesn't support 32bit" \
&& echo "Creating temporary file, otherwise the below copy doesn't work for armv7" \
&& mkdir -p /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/native-image \
&& touch /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/native-image/signal-cli; \
else \
echo "Unknown architecture"; \
fi;

# replace zkgroup

RUN ls /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/install/signal-cli/lib/zkgroup-java-${ZKGROUP_VERSION}.jar || (echo "\n\nzkgroup jar file with version ${ZKGROUP_VERSION} not found. Maybe the version needs to be bumped in the signal-cli-rest-api Dockerfile?\n\n" && echo "Available version: \n" && ls /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/install/signal-cli/lib/zkgroup-java-* && echo "\n\n" && exit 1)
Expand Down Expand Up @@ -95,31 +122,6 @@ RUN cd /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/distributions/ \
&& tar --owner='' --group='' -rvPf /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/distributions/signal-cli-${SIGNAL_CLI_VERSION}.tar signal-cli-${SIGNAL_CLI_VERSION}/lib/signal-client-java-${LIBSIGNAL_CLIENT_VERSION}.jar


# build native image with graalvm

RUN arch="$(uname -m)"; \
case "$arch" in \
aarch64) wget https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${GRAALVM_VERSION}/graalvm-ce-java${GRAALVM_JAVA_VERSION}-linux-aarch64-${GRAALVM_VERSION}.tar.gz -O /tmp/gvm.tar.gz ;; \
armv7l) echo "GRAALVM doesn't support 32bit" ;; \
x86_64) wget https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${GRAALVM_VERSION}/graalvm-ce-java${GRAALVM_JAVA_VERSION}-linux-amd64-${GRAALVM_VERSION}.tar.gz -O /tmp/gvm.tar.gz ;; \
esac;

RUN if [ "$(uname -m)" = "aarch64" ] || [ "$(uname -m)" = "x86_64" ]; then \
cd /tmp && tar xvf gvm.tar.gz \
&& export GRAALVM_HOME=/tmp/graalvm-ce-java${GRAALVM_JAVA_VERSION}-${GRAALVM_VERSION} \
&& cd /tmp/signal-cli-${SIGNAL_CLI_VERSION} \
&& chmod +x /tmp/graalvm-ce-java${GRAALVM_JAVA_VERSION}-${GRAALVM_VERSION}/bin/gu \
&& /tmp/graalvm-ce-java${GRAALVM_JAVA_VERSION}-${GRAALVM_VERSION}/bin/gu install native-image \
&& ./gradlew assembleNativeImage; \
elif [ "$(uname -m)" = "armv7l" ]; then \
echo "GRAALVM doesn't support 32bit" \
&& echo "Creating temporary file, otherwise the below copy doesn't work for armv7" \
&& mkdir -p /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/native-image \
&& touch /tmp/signal-cli-${SIGNAL_CLI_VERSION}/build/native-image/signal-cli; \
else \
echo "Unknown architecture"; \
fi;

COPY src/api /tmp/signal-cli-rest-api-src/api
COPY src/utils /tmp/signal-cli-rest-api-src/utils
COPY src/main.go /tmp/signal-cli-rest-api-src/
Expand Down

0 comments on commit a862046

Please sign in to comment.