FROM golang:latest as builder

WORKDIR /app

COPY go.mod go.sum ./

ARG PAT
RUN if [ -n "$PAT" ] ; then echo "[url \"https://$PAT:x-oauth-basic@github.com/\"] insteadOf = https://github.com/" >> /root/.gitconfig ; fi

ENV GOPRIVATE=github.com/AlchemyTelcoSolutions/*
RUN go mod download

COPY . .

RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o callisto-so-bff ./cmd/server/main.go

FROM 267696732420.dkr.ecr.eu-west-1.amazonaws.com/ags/alpine-base:latest
LABEL service="callisto-so-bff"

RUN apk --no-cache add make tzdata git ca-certificates

COPY --from=builder /app/callisto-so-bff /
COPY version.json .

USER 10000:10000
EXPOSE 3001

ENTRYPOINT ["/callisto-so-bff"]
