From 5d06dde757ff9866dfed4d712a313f9f0c75becd Mon Sep 17 00:00:00 2001 From: sh <37271604+shumvgolove@users.noreply.github.com> Date: Fri, 22 Jul 2022 13:26:20 +0300 Subject: [PATCH] docker: add selfhosted version (#481) * docker: add selfhosted version * switch to ghcup * readme * master -> stable * delete git checkout * rename docker files Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> --- scripts/docker/README.md | 11 ++-- scripts/docker/smp-server-build.Dockerfile | 53 +++++++++++++++++++ ...kerfile => smp-server-download.Dockerfile} | 2 +- 3 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 scripts/docker/smp-server-build.Dockerfile rename scripts/docker/{Dockerfile => smp-server-download.Dockerfile} (97%) diff --git a/scripts/docker/README.md b/scripts/docker/README.md index cc2e4b5ce..bc1c89065 100644 --- a/scripts/docker/README.md +++ b/scripts/docker/README.md @@ -2,9 +2,14 @@ 0. Install `docker` to your host. 1. Build your `smp-server` image: -```sh -DOCKER_BUILDKIT=1 docker build -t smp-server . -``` + - **Option 1** - Compile `smp-server` from source (stable branch): + ```sh + DOCKER_BUILDKIT=1 docker build -t smp-server -f smp-server-build.Dockerfile . + ``` + - **Option 2** - Download latest `smp-server` from [latest Github release](https://github.com/simplex-chat/simplexmq/releases/latest): + ```sh + DOCKER_BUILDKIT=1 docker build -t smp-server -f smp-server-download.Dockerfile . + ``` 2. Run new docker container: ```sh diff --git a/scripts/docker/smp-server-build.Dockerfile b/scripts/docker/smp-server-build.Dockerfile new file mode 100644 index 000000000..6cf1b4adc --- /dev/null +++ b/scripts/docker/smp-server-build.Dockerfile @@ -0,0 +1,53 @@ +FROM ubuntu:focal AS final +FROM ubuntu:focal AS build + +### Build stage + +# Install curl and git and smp-related dependencies +RUN apt-get update && apt-get install -y curl git build-essential libgmp3-dev zlib1g-dev + +# Install ghcup +RUN curl https://downloads.haskell.org/~ghcup/x86_64-linux-ghcup -o /usr/bin/ghcup && \ + chmod +x /usr/bin/ghcup + +# Install ghc +RUN ghcup install ghc +# Install cabal +RUN ghcup install cabal +# Set both as default +RUN ghcup set ghc && \ + ghcup set cabal + +# Clone simplexmq repository +RUN git clone https://github.com/simplex-chat/simplexmq +# and cd to it +WORKDIR ./simplexmq + +# Adjust PATH +ENV PATH="/root/.cabal/bin:/root/.ghcup/bin:$PATH" + +# Compile smp-server +RUN cabal update +RUN cabal install + +### Final stage + +FROM final + +# Install OpenSSL dependency +RUN apt-get update && apt-get install -y openssl + +# Copy compiled smp-server from build stage +COPY --from=build /root/.cabal/bin/smp-server /usr/bin/smp-server + +# Copy our helper script +COPY ./entrypoint /usr/bin/entrypoint + +# Open smp-server listening port +EXPOSE 5223 + +# SimpleX requires using SIGINT to correctly preserve undelivered messages and restore them on restart +STOPSIGNAL SIGINT + +# Finally, execute helper script +ENTRYPOINT [ "/usr/bin/entrypoint" ] diff --git a/scripts/docker/Dockerfile b/scripts/docker/smp-server-download.Dockerfile similarity index 97% rename from scripts/docker/Dockerfile rename to scripts/docker/smp-server-download.Dockerfile index 21eeb001f..a87d45d40 100644 --- a/scripts/docker/Dockerfile +++ b/scripts/docker/smp-server-download.Dockerfile @@ -1,6 +1,6 @@ FROM ubuntu:focal -# Install curl +# Install curl RUN apt-get update && apt-get install -y curl # Download latest smp-server release and assign executable permission