###############################################################################
# Copyright (c) 2020 Red Hat, Inc.
###############################################################################

FROM openshift/origin-release:golang-1.15 as builder

ARG REMOTE_SOURCE
ARG REMOTE_SOURCE_DIR
ARG GITHUB_TOKEN

ENV USE_VENDORIZED_BUILD_HARNESS=true
ENV COMPONENT_NAME=klusterlet-addon-lease-controller
ENV COMPONENT_VERSION=1.0
#RUN yum install -y tar gzip make which

COPY $REMOTE_SOURCE $REMOTE_SOURCE_DIR/app/
WORKDIR $REMOTE_SOURCE_DIR/app
RUN git config --global url."https://${GITHUB_TOKEN}:x-oauth-basic@github.com/".insteadOf "https://github.com/"
RUN GOFLAGS="" go test -covermode=atomic \
-coverpkg=github.com/open-cluster-management/klusterlet-addon-lease-controller/pkg/...,\
github.com/open-cluster-management/klusterlet-addon-lease-controller/controllers/... \
-c -tags testrunmain . -o manager

FROM registry.access.redhat.com/ubi8/ubi-minimal:latest
RUN microdnf update

ARG VCS_REF
ARG VCS_URL
ARG IMAGE_NAME
ARG IMAGE_DESCRIPTION
ARG ARCH_TYPE
ARG REMOTE_SOURCE_DIR

ENV OPERATOR=/usr/local/bin/klusterlet-addon-lease-controller \
    USER_UID=1001 \
    USER_NAME=klusterlet-addon-lease-controller

# install operator binary
COPY --from=builder $REMOTE_SOURCE_DIR/app/manager ${OPERATOR}
COPY --from=builder $REMOTE_SOURCE_DIR/app/build/bin /usr/local/bin
# COPY --from=builder $REMOTE_SOURCE_DIR/app/build/resources /usr/local/resources
RUN  /usr/local/bin/user_setup

ENTRYPOINT ["/usr/local/bin/entrypoint-coverage"]

USER ${USER_UID}

LABEL com.redhat.component="klusterlet-addon-lease-controller-container" \
      name="rhacm1-tech-preview/klusterlet-addon-lease-controller-rhel8" \
      version="${CI_CONTAINER_VERSION}" \
      release="${CI_CONTAINER_RELEASE}" \
      summary="klusterlet-addon-lease-controller" \
      io.openshift.expose-services="" \
      io.openshift.tags="data,images" \
      io.k8s.display-name="klusterlet-addon-lease-controller" \
      maintainer="['eisraeli@redhat.com', 'jbieren@redhat.com']" \
      description="klusterlet-addon-lease-controller"
