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 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