#
# This is the OpenShift ovn overlay network image.
# it provides an overlay network using ovs/ovn/ovn-kube
#
# The standard name for this image is ovn-kube

# Notes:
# This is for a build where the ovn-kubernetes utilities
# are built in this Dockerfile and included in the image (instead of the rpm)
#

FROM openshift/golang-builder:1.10 AS builder
ENV SOURCE_GIT_COMMIT=674977b1fdf0f966970179b9fae338f8347b2dfe SOURCE_GIT_TAG=674977b SOURCE_DATE_EPOCH=1557262292

WORKDIR /go-controller
COPY go-controller/ .

# build the binaries
RUN make

FROM openshift/ose-cli:v4.1.6.20190710.122447 AS cli
ENV SOURCE_GIT_COMMIT=674977b1fdf0f966970179b9fae338f8347b2dfe SOURCE_GIT_TAG=674977b SOURCE_DATE_EPOCH=1557262292

FROM openshift/ose-base:v4.1.6.20190710.122447
ENV SOURCE_GIT_COMMIT=674977b1fdf0f966970179b9fae338f8347b2dfe SOURCE_GIT_TAG=674977b SOURCE_DATE_EPOCH=1557262292

USER root

ENV PYTHONDONTWRITEBYTECODE yes

# install needed rpms - openvswitch must be 2.9.2 or higher
# install selinux-policy first to avoid a race
RUN yum install -y  \
	selinux-policy && \
	yum clean all

RUN yum install -y  \
	PyYAML bind-utils \
	openssl \
	numactl-libs \
	firewalld-filesystem \
	libpcap \
	hostname \
	"openvswitch2.11" \
	"openvswitch2.11-ovn-common" \
	"openvswitch2.11-ovn-central" \
	"openvswitch2.11-ovn-host" \
	"openvswitch2.11-ovn-vtep" \
	"openvswitch2.11-devel" \
	containernetworking-plugins \
	iproute strace socat && \
	yum clean all

RUN rm -rf /var/cache/yum

RUN mkdir -p /var/run/openvswitch && \
    mkdir -p /etc/cni/net.d && \
    mkdir -p /opt/cni/bin && \
    mkdir -p /usr/libexec/cni/

COPY --from=builder /go-controller/_output/go/bin/ovnkube /usr/bin/
COPY --from=builder /go-controller/_output/go/bin/ovn-kube-util /usr/bin/
COPY --from=builder /go-controller/_output/go/bin/ovn-k8s-cni-overlay /usr/libexec/cni/ovn-k8s-cni-overlay

COPY --from=cli /usr/bin/oc /usr/bin
RUN ln -s /usr/bin/oc /usr/bin/kubectl

# copy git commit number into image
COPY .git/HEAD /root/.git/HEAD
COPY .git/refs/heads/ /root/.git/refs/heads/

# ovnkube.sh is the entry point. This script examines environment
# variables to direct operation and configure ovn
COPY dist/images/ovnkube.sh /root/
COPY dist/images/ovn-debug.sh /root/
# override the rpm's ovn_k8s.conf with this local copy
COPY dist/images/ovn_k8s.conf /etc/openvswitch/ovn_k8s.conf



WORKDIR /root
ENTRYPOINT /root/ovnkube.sh

LABEL \
        io.k8s.description="This is a component of OpenShift Container Platform that provides an overlay network using ovn." \
        com.redhat.component="ose-ovn-kubernetes-container" \
        maintainer="Phil Cameron <pcameron@redhat.com>" \
        name="openshift/ose-ovn-kubernetes" \
        License="GPLv2+" \
        io.k8s.display-name="ovn kubernetes" \
        io.openshift.build.source-location="https://github.com/openshift/ovn-kubernetes" \
        summary="This is a component of OpenShift Container Platform that provides an overlay network using ovn." \
        io.openshift.build.commit.url="https://github.com/openshift/ovn-kubernetes/commit/674977b1fdf0f966970179b9fae338f8347b2dfe" \
        version="v4.1.6" \
        io.openshift.build.commit.id="674977b1fdf0f966970179b9fae338f8347b2dfe" \
        release="201907101224" \
        vendor="Red Hat" \
        io.openshift.tags="openshift"

