Suggestion to improve a dockerfile for using a VSCode debugger

There is a dockerfile sample Heroic Labs Documentation | Using VSCode Debugger where copying and building the go library (backend.so) is before installing the delve package. Maybe it will be better to change the order to install the delve package first? This change will prevent installing delve package every time we change our source files. In my environment rebuilding sources takes ~10 sec and installing delve takes ~30-60 sec, so this changes allowed me to save my time when debugging.
So I guess the dockerfile in the document would be:

FROM registry.heroiclabs.com/heroiclabs/nakama-pluginbuilder:3.15.0 AS go-builder
ENV GO111MODULE on
ENV CGO_ENABLED 1
WORKDIR /backend

RUN apt-get update && \
    apt-get -y upgrade && \
    apt-get install -y --no-install-recommends gcc libc6-dev

RUN go install github.com/go-delve/delve/cmd/dlv@latest

COPY go.mod .
COPY vendor/ vendor/
COPY *.go .

RUN go build --trimpath --gcflags "all=-N -l" --mod=vendor --buildmode=plugin -o ./backend.so

FROM registry.heroiclabs.com/heroiclabs/nakama-dsym:3.15.0

COPY --from=go-builder /go/bin/dlv /nakama
COPY --from=go-builder /backend/backend.so /nakama/data/modules/
COPY local.yml /nakama/data/

Good catch, thanks for that @Andrey. We’ll update the docs to reflect the improvement.

1 Like