Add debug mode

You can specify an environment variable DEBUG 1/0 to enable/disable
debug mode. Debug mode assumes delve dependency for remote debugging,
and debugging symbols for go build.
This commit is contained in:
Dmitrii Dolgov 2018-02-02 10:39:39 +01:00
parent 4cbb86ea13
commit bf7df5d5b5
2 changed files with 22 additions and 2 deletions

View File

@ -8,9 +8,19 @@ ifeq ($(RACE),1)
CGO_ENABLED=1
endif
ifeq ($(DEBUG),1)
BUILD_FLAGS += -gcflags "-N -l"
endif
LOCAL_BUILD_FLAGS ?= $(BUILD_FLAGS)
LDFLAGS ?= -X=main.version=$(VERSION)
DOCKERFILE = docker/Dockerfile
ifeq ($(DEBUG),1)
DOCKERFILE = docker/DebugDockerfile
else
DOCKERFILE = docker/Dockerfile
endif
IMAGE ?= registry.opensource.zalan.do/acid/$(BINARY)
TAG ?= $(VERSION)
GITHEAD = $(shell git rev-parse --short HEAD)
@ -43,7 +53,7 @@ docker-context: scm-source.json linux
cp build/linux/${BINARY} scm-source.json docker/build/
docker: ${DOCKERFILE} docker-context
cd docker && docker build --rm -t "$(IMAGE):$(TAG)" .
docker build --rm -t "$(IMAGE):$(TAG)" -f "${DOCKERFILE}" .
indocker-race:
docker run --rm -v "${GOPATH}":"${GOPATH}" -e GOPATH="${GOPATH}" -e RACE=1 -w ${PWD} golang:1.8.1 bash -c "make linux"

10
docker/DebugDockerfile Normal file
View File

@ -0,0 +1,10 @@
FROM alpine
MAINTAINER Team ACID @ Zalando <team-acid@zalando.de>
# We need root certificates to deal with teams api over https
RUN apk --no-cache add ca-certificates go git musl-dev
RUN go get github.com/derekparker/delve/cmd/dlv
COPY build/* /
CMD ["/root/go/bin/dlv", "--listen=:777", "--headless=true", "--api-version=2", "exec", "/postgres-operator"]