# Builder
FROM golang:alpine AS builder

ARG BIN_OUTPUT=/go/bin/server
ARG GO_MAIN=cmd/server/main.go

WORKDIR /go/src/app
COPY src ./

RUN go mod download && \
    export CGO_ENABLED=0 ; export GOOS=linux ; export GOARCH=amd64 && \
    go build -ldflags="-w -s" -o $BIN_OUTPUT $GO_MAIN


# Destination image - server
FROM gcr.io/distroless/base-debian10

ARG BIN_OUTPUT=/go/bin/server

LABEL author="Piotr Biernat"
LABEL service="basket-svc"
LABEL vendor="Egommerce"
LABEL version="1.0"

WORKDIR /
COPY --from=builder $BIN_OUTPUT /
COPY .env.dist /.env

EXPOSE 80
ENTRYPOINT ["/server"]