FROM openshift/golang-builder:1.10 AS builder
ENV SOURCE_GIT_COMMIT=b580cb6f52a0e352aebbe0e368d5ec020230c532 SOURCE_GIT_TAG=v0.0.1-9-gb580cb6
WORKDIR /go/src/github.com/openshift/openshift-tuned
COPY . .
RUN make build

FROM ubi7:7.6-159
ENV SOURCE_GIT_COMMIT=b580cb6f52a0e352aebbe0e368d5ec020230c532 SOURCE_GIT_TAG=v0.0.1-9-gb580cb6
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/openshift-tuned/openshift-tuned /usr/bin/
COPY --from=builder /go/src/github.com/openshift/openshift-tuned/assets ${APP_ROOT}
RUN INSTALL_PKGS=" \
      tuned hdparm kernel-tools patch \
      " && \
    yum install --setopt=tsflags=nodocs -y $INSTALL_PKGS && \
    rpm -V $INSTALL_PKGS && \
    (patch -p1 -d /usr/lib/python*/site-packages/tuned/daemon/ < patches/tuned.diff || :) && \ 
    sed -i 's/^\s*daemon.*$/daemon = 0/' /etc/tuned/tuned-main.conf && \
    touch /etc/sysctl.conf && \
    yum -y remove patch && \
    yum clean all && \
    rm -rf /var/cache/yum ~/patches
ENTRYPOINT [ "/var/lib/tuned/bin/run" ]

LABEL \
        com.redhat.component="tuned-container" \
        io.openshift.build.commit.url="https://github.com/openshift/openshift-tuned/commit/b580cb6f52a0e352aebbe0e368d5ec020230c532" \
        version="v4.1.0" \
        name="openshift/ose-cluster-node-tuned" \
        io.openshift.build.commit.id="b580cb6f52a0e352aebbe0e368d5ec020230c532" \
        release="201905191700" \
        io.openshift.build.source-location="https://github.com/openshift/openshift-tuned"

