Skip to content

Commit

Permalink
feat: improve docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMarble committed Dec 29, 2021
1 parent d26542b commit 78beddf
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
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"]

0 comments on commit 78beddf

Please sign in to comment.