FROM golang:1.19-alpine as dev-builder

ARG service

RUN go install -ldflags "-s -w -extldflags '-static'" github.com/go-delve/delve/cmd/dlv@latest

FROM alpine as development

ARG service

COPY --from=dev-builder /go/bin/dlv /go/bin/dlv
COPY .bin/${service}-debug /opt/
COPY ./src /go/src/

ENV SERVICE=${service}

EXPOSE 2345

ENTRYPOINT ['/go/bin/dlv']

CMD [ '--headless', '--listen=0.0.0.0:2345', '--api-version=2', '--log', '--accept-multiclient', '--log-output=rpc', 'exec', '/opt/${SERVICE}-debug', '--continue' ]
