FROM golang:alpine AS deps

ARG MONITORD_IMAGE

WORKDIR /app
COPY go.mod go.sum ./
RUN sed -i '/replace/d' go.mod
RUN go mod download -x

#----------------------------------------------------------------------------------------------

FROM golang:alpine AS builder

WORKDIR /app

COPY --from=deps /go/pkg /go/pkg
COPY --from=deps /app/go.mod /app/go.sum ./

COPY . .

RUN go build

#----------------------------------------------------------------------------------------------
FROM ${MONITORD_IMAGE:-oc-monitord}:latest AS monitord

FROM scratch

WORKDIR /app

COPY docker_schedulerd.json /etc/oc/schedulerd.json

COPY --from=monitord /app/oc-monitord /usr/bin/oc-monitord
COPY --from=builder /app/oc-schedulerd /usr/bin/oc-schedulerd

COPY docker_schedulerd.json /etc/oc/schedulerd.json

# COPY argo_workflows .

EXPOSE 8080

ENTRYPOINT ["oc-schedulerd"]
