Skip to content

Commit

Permalink
debugging in go
Browse files Browse the repository at this point in the history
  • Loading branch information
marcel-dempers committed Jul 18, 2019
1 parent 914b6f4 commit cba88d6
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 28 deletions.
21 changes: 21 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Remote Docker",
"type": "go",
"request": "launch",
"mode": "remote",
"remotePath":"/go/src/work/",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceFolder}/golang/src/",
"args": [],
"trace" : "verbose",
"env" : {}
}
]
}
13 changes: 6 additions & 7 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@ services:
- ./c#/src/:/work/
ports:
- 5000:5000
golang: #docker run -it -v ${PWD}:/work -w /work -p 5001:5000 aimvector/golang:1.0.0 /bin/sh
golang: #docker run -it -v ${PWD}:/go/src/work -p 5001:5000 -p 2345:2345 --security-opt "seccomp:unconfined" aimvector/golang:1.0.0
container_name: golang
image: aimvector/golang:1.0.0
build:
context: ./golang
target: prod
#working_dir: /work #comment out for build.target:prod
#entrypoint: /bin/sh #comment out for build.target:prod
#stdin_open: true #comment out for build.target:prod
#tty: true #comment out for build.target:prod
target: debug
volumes:
- ./golang/src/:/work
- ./golang/src/:/go/src/work/
ports:
- 5001:5000
- 2345:2345
security_opt:
- "seccomp:unconfined"
nodejs: #docker run -it -v ${PWD}:/work -w /work -p 5002:5000 aimvector/nodejs:1.0.0 /bin/sh
container_name: nodejs
image: aimvector/nodejs:1.0.0
Expand Down
3 changes: 3 additions & 0 deletions golang/dlv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
cd /go/src/work
dlv debug --headless --log -l 0.0.0.0:2345 --api-version=2
50 changes: 32 additions & 18 deletions golang/dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
FROM golang:1.12.5-alpine3.9 as dev

# installing git
RUN apk update && apk upgrade && \
apk add --no-cache git

RUN go get github.com/sirupsen/logrus
RUN go get github.com/buaazp/fasthttprouter
RUN go get github.com/valyala/fasthttp

WORKDIR /work
COPY ./src /work/
RUN go build -o app
###########START NEW IMAGE###################

FROM alpine:3.9 as prod
COPY --from=dev /work/app /
CMD ./app
FROM golang:1.12.5-alpine3.9 as debug

# installing git
RUN apk update && apk upgrade && \
apk add --no-cache git \
dpkg \
gcc \
git \
musl-dev

ENV GOPATH /go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH

RUN go get github.com/sirupsen/logrus
RUN go get github.com/buaazp/fasthttprouter
RUN go get github.com/valyala/fasthttp
RUN go get github.com/go-delve/delve/cmd/dlv

WORKDIR /go/src/work
COPY ./src /go/src/work/

RUN go build -o app
### Run the Delve debugger ###
COPY ./dlv.sh /
RUN chmod +x /dlv.sh
ENTRYPOINT [ "/dlv.sh"]

###########START NEW IMAGE###################

FROM alpine:3.9 as prod
COPY --from=debug /go/src/work/app /
CMD ./app
4 changes: 1 addition & 3 deletions golang/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import (
"github.com/valyala/fasthttp"
)

var searchMock []byte

func Response(ctx *fasthttp.RequestCtx) {
fmt.Fprintf(ctx, "Hello")
}
func main() {

fmt.Println("starting.")
fmt.Println("starting...")

router := fasthttprouter.New()
router.GET("/", Response)
Expand Down

0 comments on commit cba88d6

Please sign in to comment.