FROM golang:1.14 as builder
RUN mkdir -p /app
WORKDIR /app
COPY . .
RUN go get -d ./cmd/calendar/.
RUN GOOS=linux GOARCH=amd64 go build -a -o calendar ./cmd/calendar/.

FROM alpine:latest
ENV APP_GRPC_ADDRESS=0.0.0.0
ENV APP_GRPC_PORT=50051
ENV APP_HTTP_ADDRESS=0.0.0.0
ENV APP_HTTP_PORT=8888
ENV APP_API_ADDRESS=0.0.0.0
ENV APP_API_PORT=50053
ENV APP_LOGGER_FILE=/calendar.log
ENV APP_LOGGER_LEVEL=INFO
ENV APP_STORAGE_INMEMORY=true
ENV APP_STORAGE_SQLHOST=psql
ENV APP_STORAGE_SQLPORT=5432
ENV APP_STORAGE_SQLDBASE=calendar
ENV APP_STORAGE_SQLUSER=calendar
ENV APP_STORAGE_SQLPASS=12345678
WORKDIR /
COPY --from=builder /app/calendar ./sbin
EXPOSE ${APP_GRPC_PORT}
EXPOSE ${APP_HTTP_PORT}
EXPOSE ${APP_API_PORT}
CMD ["calendar"]
