#@follow_tag(openshift-golang-builder:1.13)
FROM openshift-golang-builder:v1.13.4-100 AS builder

ENV GOPATH=/go

ARG upstream_version=7c7ee93
ARG upstream_commit=7c7ee939380d04e5dd5d49b13d8f03068087c0e8
ARG archive=performance-addon-operator-7c7ee939380d04e5dd5d49b13d8f03068087c0e8.tar.gz

ARG project_dir=${GOPATH}/src/github.com/openshift-kni/performance-addon-operators
ARG upstream_version_number=4.5.2
ARG upstream_manifests=${project_dir}/deploy/olm-catalog/performance-addon-operator/${upstream_version_number}
ARG upstream_csv=${upstream_manifests}/performance-addon-operator.v${upstream_version_number}.clusterserviceversion.yaml
ARG downstream_version_number=4.5.2
ARG manifests_dir=/usr/local/manifests/performance-addon-operator

RUN mkdir -p /customizations
RUN mkdir -p ${manifests_dir}

COPY ${archive} /
COPY customizations/* /customizations/

RUN mkdir -p ${project_dir} && tar -xzf /${archive} --strip-components 1 -C ${project_dir}
WORKDIR ${project_dir}

RUN make dist

RUN make dist-tools
RUN ${project_dir}/build/_output/bin/csv-generator \
	--operator-image "REPLACE_IMAGE" \
	--csv-version "${downstream_version_number}" \
	--operator-csv-template-file "${upstream_csv}" \
	--olm-bundle-directory "${manifests_dir}" \
	--description-from "/customizations/description.txt" \
	--maintainers-from "/customizations/maintainers.json" \
	--annotations-from "/customizations/annotations.json"
RUN cp ${upstream_manifests}/performance.openshift.io_performanceprofiles_crd.yaml ${manifests_dir}

#@follow_tag(ubi8-minimal:8.2)
FROM ubi8-minimal:8.2-349

# TODO: remove this duplication
ENV GOPATH=/go
ARG project_dir=${GOPATH}/src/github.com/openshift-kni/performance-addon-operators
ARG manifests_dir=/usr/local/manifests/performance-addon-operator
ARG zversion=2

RUN mkdir -p ${manifests_dir}
COPY --from=builder ${project_dir}/build/assets /assets
COPY --from=builder ${project_dir}/build/_output/bin/performance-addon-operators /bin/performance-operator
COPY --from=builder ${manifests_dir} ${manifests_dir}
COPY --from=builder ${project_dir}/build/_output/bin/csv-replace-imageref /usr/local/bin
COPY scripts /usr/local/bin

ENTRYPOINT ["/bin/performance-operator"]

LABEL com.redhat.component="performance-addon-operator-container" \
      name="openshift4/performance-addon-rhel8-operator" \
      version="v4.5.${zversion}" \
      upstream-version="7c7ee93" \
      upstream-vcs-ref="7c7ee939380d04e5dd5d49b13d8f03068087c0e8" \
      upstream-vcs-type="git" \
      summary="performance-addon-operator" \
      io.openshift.expose-services="" \
      io.openshift.tags="operator" \
      io.k8s.display-name="performance-addon-operator" \
      maintainer="openshift-operators@redhat.com" \
      description="performance-addon-operator"
