diff --git a/Dockerfile b/Dockerfile index 0e37eb2..eeb186c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,18 @@ -FROM ubuntu:latest +FROM golang:1.18 as builder -RUN apt-get update -RUN apt-get install -y wget git gcc bash - -RUN wget -P /tmp https://dl.google.com/go/go1.18.linux-amd64.tar.gz +WORKDIR /app +COPY . /app -RUN tar -C /usr/local -xzf /tmp/go1.18.linux-amd64.tar.gz -RUN rm /tmp/go1.18.linux-amd64.tar.gz +RUN go get -d -v -ENV GOPATH /go -ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH -RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH" +# Statically compile our app for use in a distroless container +RUN CGO_ENABLED=0 go build -ldflags="-w -s" -v -o app . -RUN go version +FROM debian:buster-slim +RUN set -x && apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ + ca-certificates git bash && \ + rm -rf /var/lib/apt/lists/* -WORKDIR /app -COPY . /app/ +COPY --from=builder /app/app /app -# Start app -ENTRYPOINT ["go", "run", "/app/main.go"] \ No newline at end of file +ENTRYPOINT ["/app"] \ No newline at end of file