From b50b5aea174079934f5c658fa3432b7b3918fee2 Mon Sep 17 00:00:00 2001 From: Ruidy Date: Thu, 2 Jun 2022 18:19:37 +0200 Subject: [PATCH] add Dockerfile --- Dockerfile | 20 ++++++++++++++++++++ Makefile | 4 ++-- go.mod | 2 +- 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bb4db75 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM golang:1.17-alpine AS builder + +ENV GOOS linux +RUN apk update --no-cache + +WORKDIR /app + +COPY go.* . +RUN go mod download + +COPY . . +RUN go build -ldflags="-s -w" -o dist + + +FROM gcr.io/distroless/static + +WORKDIR /app +COPY --from=builder /app/dist /app/dist + +CMD ["./dist"] \ No newline at end of file diff --git a/Makefile b/Makefile index 8e9b671..41a5d3d 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ dev: air build: - go build -o $(EXECPATH) . + go build -ldflags="-s -w" -o $(EXECPATH) . run: build $(EXECPATH) new @@ -19,6 +19,6 @@ web: cd client && npm run start test: - go test -json -count=1 ./... -coverpkg=./... -coverprofile coverage.out -covermode=atomic | gotestfmt # && go tool cover -html coverage.out && rm coverage.out + go test -json -count=1 ./... -coverpkg=./... -coverprofile coverage.out -covermode=atomic | gotestfmt && go tool cover -html coverage.out && rm coverage.out .PHONY: lint run dev run-web test build diff --git a/go.mod b/go.mod index 052b5be..ccbabaf 100644 --- a/go.mod +++ b/go.mod @@ -5,12 +5,12 @@ go 1.17 require ( github.com/fatih/color v1.13.0 github.com/go-chi/chi/v5 v5.0.4 + github.com/go-chi/cors v1.2.0 github.com/go-chi/render v1.0.1 github.com/spf13/cobra v1.2.1 ) require ( - github.com/go-chi/cors v1.2.0 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/mattn/go-colorable v0.1.9 // indirect github.com/mattn/go-isatty v0.0.14 // indirect