From 604c3f5f1c3c6ab57924f0a66b43428e0676b620 Mon Sep 17 00:00:00 2001 From: gnuxie Date: Tue, 25 Oct 2022 18:15:23 +0100 Subject: [PATCH] Change entrypoint in Dockerfile so that we can start the appservice. We could have used another Dockerfile for the appservice, extending the exising one but we decided not to because there would have been lots of fiddling around the entrypoint and logistics involved around adding a tag for it via github actions. Not to mention that this would be duplicating the image just to run it with a different binary. This solution is much simpler, backwards compatible, and conscious about the future. --- Dockerfile | 7 +++++-- mjolnir-entrypoint.sh | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100755 mjolnir-entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 02b650d..d0891b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,18 @@ -FROM node:16-alpine +# We can't use alpine anymore because crypto has rust deps. +FROM node:16-slim COPY . /tmp/src RUN cd /tmp/src \ && yarn install \ && yarn build \ && mv lib/ /mjolnir/ \ && mv node_modules / \ + && mv mjolnir-entrypoint.sh / \ && cd / \ && rm -rf /tmp/* ENV NODE_ENV=production ENV NODE_CONFIG_DIR=/data/config -CMD node /mjolnir/index.js +CMD ["bot"] +ENTRYPOINT ["./mjolnir-entrypoint.sh"] VOLUME ["/data"] diff --git a/mjolnir-entrypoint.sh b/mjolnir-entrypoint.sh new file mode 100755 index 0000000..3f90255 --- /dev/null +++ b/mjolnir-entrypoint.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +# This is used as the entrypoint in the mjolnir Dockerfile. +# We want to transition away form people running the image without specifying `bot` or `appservice`. +# So if eventually cli arguments are provided for the bot version, we want this to be the opportunity to move to `bot`. +# Therefore using arguments without specifying `bot` (or appservice) is unsupported. +# We maintain the behaviour where if it looks like someone is providing an executable to `docker run`, then we will execute that instead. +# This aids configuration and debugging of the image if for example node needed to be started via another method. +case "$1" in + bot) shift; set -- node /mjolnir/index.js "$@";; + appservice) shift; set -- node /mjolnir/appservice/cli.js "$@";; +esac + +exec "$@";