From 6e7faa2a6583ab324826e1c1d9e34794abfafb9f Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 18 Dec 2023 13:11:32 +0200 Subject: [PATCH] Fix standalone dockerfile --- Dockerfile | 34 +++++++++++++--------------------- build-go.sh | 4 ++++ 2 files changed, 17 insertions(+), 21 deletions(-) create mode 100755 build-go.sh diff --git a/Dockerfile b/Dockerfile index f201deb5..6e6b20db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,52 +1,44 @@ # -- Build libsignal (with Rust) -- -FROM rust:1.70.0-slim as rust-builder -RUN apt-get update && apt-get install -y --no-install-recommends make cmake clang llvm protobuf-compiler +FROM rust:1-alpine as rust-builder +RUN apk add --no-cache git make cmake protoc musl-dev g++ clang-dev WORKDIR /build # Copy all files needed for Rust build, and no Go files COPY pkg/libsignalgo/libsignal/. pkg/libsignalgo/libsignal/. -COPY Makefile . -ARG DBG=0 -RUN make build_rust -RUN make copy_library +ENV RUSTFLAGS="-Ctarget-feature=-crt-static" RUSTC_WRAPPER="" +RUN cd pkg/libsignalgo/libsignal/ && cargo build -p libsignal-ffi --release # -- Build mautrix-signal (with Go) -- -FROM golang:1.20-bookworm AS go-builder -RUN apt-get update && apt-get install -y --no-install-recommends git ca-certificates libolm-dev - -ARG DBG=0 -RUN /bin/bash -c 'if [[ $DBG -eq 1 ]]; then go install github.com/go-delve/delve/cmd/dlv@latest; else touch /go/bin/dlv; fi' +FROM golang:1-alpine3.19 AS go-builder +RUN apk add --no-cache git ca-certificates build-base olm-dev WORKDIR /build # Copy all files needed for Go build, and no Rust files -COPY *.go go.* *.yaml ./ +COPY *.go go.* *.yaml *.sh ./ COPY pkg/signalmeow/. pkg/signalmeow/. COPY pkg/libsignalgo/* pkg/libsignalgo/ COPY pkg/libsignalgo/resources/. pkg/libsignalgo/resources/. COPY config/. config/. COPY database/. database/. +COPY msgconv/. msgconv/. COPY .git .git -COPY Makefile . -COPY docker-run.sh . -COPY --from=rust-builder /build/libsignal_ffi.a /build/libsignal_ffi.a -RUN make build_go +ENV LIBRARY_PATH=. +COPY --from=rust-builder /build/pkg/libsignalgo/libsignal/target/release/libsignal_ffi.a /build/libsignal_ffi.a +RUN ./build-go.sh # -- Run mautrix-signal -- -FROM debian:12-slim +FROM alpine:3.19 ENV UID=1337 \ GID=1337 -RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates libolm-dev bash jq yq curl gosu && rm -rf /var/li/apt/lists/* +RUN apk add --no-cache ffmpeg su-exec ca-certificates bash jq curl yq olm COPY --from=go-builder /build/mautrix-signal /usr/bin/mautrix-signal COPY --from=go-builder /build/example-config.yaml /opt/mautrix-signal/example-config.yaml COPY --from=go-builder /build/docker-run.sh /docker-run.sh -COPY --from=go-builder /go/bin/dlv /usr/bin/dlv VOLUME /data -ARG DBGWAIT=0 -ENV DBGWAIT=${DBGWAIT} CMD ["/docker-run.sh"] diff --git a/build-go.sh b/build-go.sh new file mode 100755 index 00000000..91123ec1 --- /dev/null +++ b/build-go.sh @@ -0,0 +1,4 @@ +#!/bin/sh +export MAUTRIX_VERSION=$(cat go.mod | grep 'maunium.net/go/mautrix ' | awk '{ print $2 }') +export GO_LDFLAGS="-s -w -X main.Tag=$(git describe --exact-match --tags 2>/dev/null) -X main.Commit=$(git rev-parse HEAD) -X 'main.BuildTime=`date '+%b %_d %Y, %H:%M:%S'`' -X 'maunium.net/go/mautrix.GoModVersion=$MAUTRIX_VERSION'" +go build -ldflags "$GO_LDFLAGS" -o mautrix-signal