diff options
author | Matthew Lemon <y@yulqen.org> | 2024-05-29 15:23:15 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-05-30 20:23:12 +0100 |
commit | dce2b495b931f82fbb8d1ff71ef661d77817307c (patch) | |
tree | 4783784b98ffe1602d668eed37bf634737acded5 | |
parent | b77dec0049ea1d23fc75e73866f2bdf305ad3433 (diff) |
Some tidying
Configured to run dlv in the container
See https://golangforall.com/en/post/go-docker-delve-remote-debug.html
Haven't actually go the interactive dlv working - need to explore docker
attach to do that, maybe.
Slimmed down image in play
- Also adds a new make rule to run debug container
-rw-r--r-- | .dockerignore | 3 | ||||
-rw-r--r-- | Dockerfile | 16 | ||||
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | compose.yaml | 7 | ||||
-rw-r--r-- | debug/docker-compose-debug.yaml | 26 | ||||
-rw-r--r-- | debug/dockerfile-debug | 14 |
6 files changed, 58 insertions, 11 deletions
diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5d6bfcf --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.git +Dockerfile +Dockerfile_postgres @@ -1,10 +1,12 @@ -FROM golang:alpine +FROM golang:alpine as build -WORKDIR /app +WORKDIR / -COPY go.mod ./ -RUN go mod download && go mod verify COPY . . -RUN go build -v -o /usr/local/bin/app ./cmd/dbasik-api -CMD ["app"] -EXPOSE 5000 + +RUN go build -o ./app ./cmd/dbasik-api + +FROM scratch +COPY --from=build /app /app +COPY --from=build /.env /.env +CMD ["/app"] @@ -4,6 +4,9 @@ build: run-container: @docker run -it --rm -p 4000:4000 dbasik:latest +debug: + @docker compose -f ./debug/dockerfile-debug up + run: @docker compose up -d diff --git a/compose.yaml b/compose.yaml index d1544a0..38a3ba9 100644 --- a/compose.yaml +++ b/compose.yaml @@ -13,11 +13,10 @@ services: app: build: context: . - volumes: - - .:/app + # volumes: + # - .:/app restart: "unless-stopped" - command: > - sh -c "go run ./cmd/dbasik-api" + command: "./app" ports: - 5000:5000 depends_on: diff --git a/debug/docker-compose-debug.yaml b/debug/docker-compose-debug.yaml new file mode 100644 index 0000000..fe81fc7 --- /dev/null +++ b/debug/docker-compose-debug.yaml @@ -0,0 +1,26 @@ +services: + db: + build: + context: . + dockerfile: Dockerfile.postgres + ports: + - 5432:5432 + environment: + - POSTGRES_PASSWORD=secret + volumes: + - dbasik_data:/var/lib/postgresql/data + - ./migrations:/dbasik + app: + build: + context: . + dockerfile: Dockerfile + # volumes: + # - .:/app + restart: "unless-stopped" + command: "/dlv --listen=:2345 --headless=true --log=true --log-output=debugger,debuglineerr,gdbwire,lldbout,rpc --accept-multiclient --api-version=2 exec ./app" + ports: + - 2345:2345 + depends_on: + - db +volumes: + dbasik_data: diff --git a/debug/dockerfile-debug b/debug/dockerfile-debug new file mode 100644 index 0000000..296ab31 --- /dev/null +++ b/debug/dockerfile-debug @@ -0,0 +1,14 @@ +FROM golang:alpine as build + +WORKDIR / + +COPY . . + +RUN CGO_ENABLED=0 go install github.com/go-delve/delve/cmd/dlv@latest +#RUN CGO_ENABLED=0 go get -ldflags "-s -w -extldflags '-static'" github.com/go-delve/delve/cmd/dlv +RUN CGO_ENABLED=0 go build -gcflags "all=-N -l" -o ./app ./cmd/dbasik-api + +FROM scratch +COPY --from=build /go/bin/dlv /dlv +COPY --from=build /app /app +CMD ["/dlv"] |