diff --git a/Dockerfile b/Dockerfile index 949c8d3..fecfd9d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,28 @@ -FROM golang:1.17 AS builder -WORKDIR /source -COPY go.mod . -COPY go.sum . +ARG GO_VERSION=1.17 + +## Build container +FROM golang:${GO_VERSION}-alpine AS builder + +RUN mkdir /user && \ + echo 'nobody:x:65534:65534:nobody:/:' > /user/passwd && \ + echo 'nobody:x:65534:' > /user/group + +RUN apk add --no-cache ca-certificates git zip + +WORKDIR /src + +COPY ./go.mod ./go.sum ./ RUN go mod download -COPY . . -RUN CGO_ENABLED=0 GOOS=linux go build -a -o teledock ./cmd/teledock/main.go -FROM scratch -WORKDIR /bot/ -COPY --from=builder /source/teledock . -CMD ["./teledock"] \ No newline at end of file +COPY ./ ./ +RUN CGO_ENABLED=0 go build -installsuffix 'static' -o /teledock /src/cmd/teledock + +## Final container +FROM scratch AS final + +COPY --from=builder /user/group /user/passwd /etc/ +COPY --from=builder /teledock /teledock + +USER 65534:65534 + +ENTRYPOINT ["/teledock"] \ No newline at end of file