Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker: statically build CLI #3942

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 29 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
ARG TAG=22.04

FROM ubuntu:${TAG} AS build

### Build stage

# Install curl and git and simplex-chat dependencies
RUN apt-get update && apt-get install -y curl git build-essential libgmp3-dev zlib1g-dev llvm-12 llvm-12-dev libnuma-dev libssl-dev
FROM alpine:latest AS build-stage

# Alpine Linux doesn't provide libtinfow.so.6 library, so we need to symlink it.
# Add essential packages for ghc/cabal to work.
RUN apk add --no-cache \
curl \
git \
xz \
grep \
ghc-dev \
gmp-dev \
zlib-static \
zlib-dev \
openssl-libs-static \
openssl-dev \
alpine-sdk &&\
ln -s /usr/lib/libncursesw.so.6 /usr/lib/libtinfow.so.6

# Specify bootstrap Haskell versions
ENV BOOTSTRAP_HASKELL_GHC_VERSION=9.6.3
Expand All @@ -21,21 +30,30 @@ ENV PATH="/root/.cabal/bin:/root/.ghcup/bin:$PATH"
RUN ghcup set ghc "${BOOTSTRAP_HASKELL_GHC_VERSION}" && \
ghcup set cabal "${BOOTSTRAP_HASKELL_CABAL_VERSION}"

# Install hpack
RUN cabal install --install-method=copy --installdir=/usr/local/bin hpack-0.36.0

# Copy project in PWD to dontainer
COPY . /project
WORKDIR /project

# Adjust build
RUN cp ./scripts/cabal.project.local.linux ./cabal.project.local

# Add optimization flags and build statically
RUN sed -i '/- -Wunused-type-patterns/a\ - -O2\n\ - -split-sections\n\ - -with-rtsopts=-N\n\ - -static\n\cc-options: -static\n\ld-options: -static -pthread' package.yaml

# Reconfigure cabal project
RUN hpack

# Compile simplex-chat
RUN cabal update
RUN cabal build exe:simplex-chat
RUN cabal build -j exe:simplex-chat

# Strip the binary from debug symbols to reduce size
RUN bin=$(find /project/dist-newstyle -name "simplex-chat" -type f -executable) && \
mv "$bin" ./ && \
strip ./simplex-chat

# Copy compiled app from build stage
FROM scratch AS export-stage
COPY --from=build /project/simplex-chat /
COPY --from=build-stage /project/simplex-chat /
Loading