From 9e41b707bfc0e5df62963426289148c7a1c69d64 Mon Sep 17 00:00:00 2001 From: Caj Larsson Date: Thu, 5 May 2022 08:42:18 +0800 Subject: [PATCH] Dockerfile solves #10 --- .dockerignore | 1 + Dockerfile | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9414382 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b893b1c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +FROM golang:alpine as builder + +ENV GO111MODULE=on + +# Create the user and group files to run unprivileged +RUN mkdir /user && \ + echo 'nobody:x:65534:65534:nobody:/:' > /user/passwd && \ + echo 'nobody:x:65534:' > /user/group + +RUN apk update && apk add --no-cache git ca-certificates tzdata sqlite build-base +RUN mkdir /build +COPY . /build/ +WORKDIR /build + +COPY ./ ./ +RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o bog . + +FROM golang:alpine AS final +LABEL author="Cajually " + +COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo +COPY --from=builder /user/group /user/passwd /etc/ +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=builder /build/bog / +COPY --from=builder /build/default.toml / + +WORKDIR / + +USER nobody:nobody +ENTRYPOINT ["/bog"] + +EXPOSE 8002