FROM openshift/golang-builder:rhel_8_golang_1.15 AS builder
ENV __doozer=update BUILD_RELEASE=202101051539.p0 BUILD_VERSION=v4.6.0 OS_GIT_MAJOR=4 OS_GIT_MINOR=6 OS_GIT_PATCH=0 OS_GIT_TREE_STATE=clean OS_GIT_VERSION=4.6.0-202101051539.p0 SOURCE_GIT_TREE_STATE=clean 
ENV __doozer=merge KUBE_GIT_COMMIT=b0859eb3dd83152f0bcea61f368a64c76f7364a7 KUBE_GIT_MAJOR=1 KUBE_GIT_MINOR=18+ KUBE_GIT_TREE_STATE=clean KUBE_GIT_VERSION=v1.18.0+b0859eb OS_GIT_COMMIT=b0859eb OS_GIT_VERSION=4.6.0-202101051539.p0-b0859eb SOURCE_DATE_EPOCH=1606299160 SOURCE_GIT_COMMIT=b0859eb3dd83152f0bcea61f368a64c76f7364a7 SOURCE_GIT_TAG=b0859eb3 SOURCE_GIT_URL=https://github.com/openshift/cluster-node-tuning-operator 
WORKDIR /go/src/github.com/openshift/cluster-node-tuning-operator
COPY . .
RUN make build

FROM openshift/ose-base:rhel8.2.els.rhel AS tuned
ENV __doozer=update BUILD_RELEASE=202101051539.p0 BUILD_VERSION=v4.6.0 OS_GIT_MAJOR=4 OS_GIT_MINOR=6 OS_GIT_PATCH=0 OS_GIT_TREE_STATE=clean OS_GIT_VERSION=4.6.0-202101051539.p0 SOURCE_GIT_TREE_STATE=clean 
ENV __doozer=merge KUBE_GIT_COMMIT=b0859eb3dd83152f0bcea61f368a64c76f7364a7 KUBE_GIT_MAJOR=1 KUBE_GIT_MINOR=18+ KUBE_GIT_TREE_STATE=clean KUBE_GIT_VERSION=v1.18.0+b0859eb OS_GIT_COMMIT=b0859eb OS_GIT_VERSION=4.6.0-202101051539.p0-b0859eb SOURCE_DATE_EPOCH=1606299160 SOURCE_GIT_COMMIT=b0859eb3dd83152f0bcea61f368a64c76f7364a7 SOURCE_GIT_TAG=b0859eb3 SOURCE_GIT_URL=https://github.com/openshift/cluster-node-tuning-operator 
WORKDIR /root
COPY assets /root/assets
RUN INSTALL_PKGS=" \
      gcc git rpm-build make desktop-file-utils patch \
      python3 python3-configobj python3-pyudev \
      " && \
    yum install --setopt=tsflags=nodocs -y $INSTALL_PKGS && \
    cd assets/tuned/daemon && \
    LC_COLLATE=C cat ../patches/*.diff | patch -Np1 && \
    make rpm PYTHON=/usr/bin/python3 && \
    rm -rf /root/rpmbuild/RPMS/noarch/{tuned-gtk*,tuned-utils*,tuned-profiles-compat*} && \
    cd ../stalld && \
    make

FROM openshift/ose-base:v4.6.0.20210105.161320
ENV __doozer=update BUILD_RELEASE=202101051539.p0 BUILD_VERSION=v4.6.0 OS_GIT_MAJOR=4 OS_GIT_MINOR=6 OS_GIT_PATCH=0 OS_GIT_TREE_STATE=clean OS_GIT_VERSION=4.6.0-202101051539.p0 SOURCE_GIT_TREE_STATE=clean 
ENV __doozer=merge KUBE_GIT_COMMIT=b0859eb3dd83152f0bcea61f368a64c76f7364a7 KUBE_GIT_MAJOR=1 KUBE_GIT_MINOR=18+ KUBE_GIT_TREE_STATE=clean KUBE_GIT_VERSION=v1.18.0+b0859eb OS_GIT_COMMIT=b0859eb OS_GIT_VERSION=4.6.0-202101051539.p0-b0859eb SOURCE_DATE_EPOCH=1606299160 SOURCE_GIT_COMMIT=b0859eb3dd83152f0bcea61f368a64c76f7364a7 SOURCE_GIT_TAG=b0859eb3 SOURCE_GIT_URL=https://github.com/openshift/cluster-node-tuning-operator 
COPY --from=builder /go/src/github.com/openshift/cluster-node-tuning-operator/_output/cluster-node-tuning-operator /usr/bin/
COPY manifests /manifests
ENV APP_ROOT=/var/lib/tuned
ENV PATH=${APP_ROOT}/bin:${PATH}
ENV HOME=${APP_ROOT}
WORKDIR ${APP_ROOT}
COPY --from=builder /go/src/github.com/openshift/cluster-node-tuning-operator/_output/openshift-tuned /usr/bin/
COPY --from=tuned   /root/assets ${APP_ROOT}
COPY --from=tuned   /root/rpmbuild/RPMS/noarch /root/rpms
RUN INSTALL_PKGS=" \
      socat procps-ng \
      " && \
    mkdir -p /etc/grub.d/ /boot && \
    yum install --setopt=tsflags=nodocs -y $INSTALL_PKGS && \
    rpm -V $INSTALL_PKGS && \
    yum --setopt=tsflags=nodocs -y install /root/rpms/*.rpm && \
    find /root/rpms -name \*.rpm -exec basename {} .rpm \; | xargs rpm -e --justdb && \
    cp -a /var/lib/tuned/tuned/stalld/stalld /usr/local/bin && \
    rm -rf /var/lib/tuned/tuned && \
    touch /etc/sysctl.conf && \
    yum clean all && \
    rm -rf /var/cache/yum ~/patches /root/rpms && \
    useradd -r -u 499 cluster-node-tuning-operator
ENTRYPOINT ["/usr/bin/cluster-node-tuning-operator"]

LABEL \
        io.k8s.display-name="OpenShift cluster-node-tuning-operator" \
        io.k8s.description="This is a component of OpenShift and manages the lifecycle of node-level tuning." \
        io.openshift.release.operator="true" \
        name="openshift/ose-cluster-node-tuning-operator" \
        com.redhat.component="cluster-node-tuning-operator-container" \
        io.openshift.maintainer.product="OpenShift Container Platform" \
        io.openshift.maintainer.component="Node Tuning Operator" \
        release="202101051539.p0" \
        io.openshift.build.commit.id="b0859eb3dd83152f0bcea61f368a64c76f7364a7" \
        io.openshift.build.source-location="https://github.com/openshift/cluster-node-tuning-operator" \
        io.openshift.build.commit.url="https://github.com/openshift/cluster-node-tuning-operator/commit/b0859eb3dd83152f0bcea61f368a64c76f7364a7" \
        version="v4.6.0"

