From 5d9810e885ab071643c71830a00bc3196cc7072d Mon Sep 17 00:00:00 2001 From: Caner Basaran Date: Sun, 29 Mar 2020 16:20:36 +0300 Subject: [PATCH 1/2] added vendor dir to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e660fd9..be22bde 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ bin/ +vendor/ \ No newline at end of file From e093b178a8c3dc9ce158e719934a1419a1a1900c Mon Sep 17 00:00:00 2001 From: Caner Basaran Date: Sun, 29 Mar 2020 16:37:01 +0300 Subject: [PATCH 2/2] added Dockerfile and updated Makefile for run&build docker --- Dockerfile | 43 +++++++++++++++++++++++++++++++++++++++++++ Makefile | 8 ++++++++ 2 files changed, 51 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9db937e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,43 @@ +FROM golang:alpine AS builder + +RUN apk update && apk add --no-cache git ca-certificates tzdata && update-ca-certificates + +ENV USER=appuser +ENV UID=10001 + +RUN adduser \ + --disabled-password \ + --gecos "" \ + --home "/nonexistent" \ + --shell "/sbin/nologin" \ + --no-create-home \ + --uid "${UID}" \ + "${USER}" + +WORKDIR $GOPATH/src/sample/gin/ +COPY . . + +RUN go mod download +RUN go mod verify + +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /go/bin/sample-gin + + + + +FROM scratch + +COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=builder /etc/passwd /etc/passwd +COPY --from=builder /etc/group /etc/group + +COPY --from=builder /go/bin/sample-gin /go/bin/sample-gin +COPY ./templates/ /templates/ +COPY ./data/ /data/ + +USER appuser:appuser + +EXPOSE 3300 + +ENTRYPOINT ["/go/bin/sample-gin"] \ No newline at end of file diff --git a/Makefile b/Makefile index 0c2615f..1d01004 100644 --- a/Makefile +++ b/Makefile @@ -10,3 +10,11 @@ test: .PHONY: clean clean: rm -f bin/* + +.PHONY: build-docker +build-docker: + docker build -t sample-gin . + +.PHONY: run-docker +run-docker: + docker run -it -p 3300:3300 sample-gin \ No newline at end of file