Skip to content

Commit

Permalink
Allow debug build & remote debugging (#13)
Browse files Browse the repository at this point in the history
* Allow debug build & remote debugging

* Allow debug image to wait for connection
  • Loading branch information
AndrewFerr authored Nov 14, 2023
1 parent 7f91fea commit edf04da
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ WORKDIR /build
COPY pkg/libsignalgo/libsignal/. pkg/libsignalgo/libsignal/.
COPY Makefile .

ARG DBG=0
RUN make build_rust
RUN make copy_library

# -- 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'

WORKDIR /build
# Copy all files needed for Go build, and no Rust files
COPY *.go go.* *.yaml ./
Expand All @@ -40,6 +44,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates
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"]
16 changes: 13 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,24 @@ LIBRARY_FILENAME=libsignal_ffi.a
RUST_DIR=pkg/libsignalgo/libsignal
GO_BINARY=mautrix-signal

ifneq ($(DBG),1)
RUST_PROFILE=release
RUST_TARGET_SUBDIR=release
GO_GCFLAGS=
else
RUST_PROFILE=dev
RUST_TARGET_SUBDIR=debug
GO_GCFLAGS=all=-N -l
endif

build_rust:
cd $(RUST_DIR) && cargo build -p $(LIBRARY_NAME) --release
cd $(RUST_DIR) && cargo build -p $(LIBRARY_NAME) --profile=$(RUST_PROFILE)

copy_library:
cp $(RUST_DIR)/target/release/$(LIBRARY_FILENAME) .
cp $(RUST_DIR)/target/$(RUST_TARGET_SUBDIR)/$(LIBRARY_FILENAME) .

build_go:
LIBRARY_PATH="$${LIBRARY_PATH}:." go build -ldflags "-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'`'"
LIBRARY_PATH="$${LIBRARY_PATH}:." go build -gcflags "$(GO_GCFLAGS)" -ldflags "-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'`'"

clean:
rm -f ./$(LIBRARY_FILENAME)
Expand Down
12 changes: 11 additions & 1 deletion docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,14 @@ fi

cd /data
fixperms
exec gosu $UID:$GID /usr/bin/mautrix-signal

EXE=/usr/bin/mautrix-signal
DLV=/usr/bin/dlv
if [[ -x $DLV ]]; then
if [[ $DBGWAIT -ne 1 ]]; then
NOWAIT=1
fi
EXE="${DLV} exec ${EXE} ${NOWAIT:+--continue --accept-multiclient} --api-version 2 --headless -l :4040"
fi

exec gosu $UID:$GID $EXE

0 comments on commit edf04da

Please sign in to comment.