#
# 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 rhel7

USER root

ENV PYTHONDONTWRITEBYTECODE yes

# install golang and build tools
RUN yum install -y  \
	make which golang  && \
	yum clean all

# copy git commit number into image
RUN mkdir -p go-controller /root/.git/ /root/.git/refs/heads/
COPY .git/HEAD /root/.git/HEAD
COPY .git/refs/heads/ /root/.git/refs/heads/

# build the binaries
COPY go-controller/ go-controller/
RUN cd go-controller && make

# remove build tools
RUN yum remove -y  \
	gmake which golang \
	cpp gcc glibc-devel glibc-headers golang-bin \
	golang-src.noarch kernel-headers \
	libgomp libmpc mpfr && \
	yum clean all

# install needed rpms - openvswitch must be 2.9.0 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 \
	"openvswitch-2.9*" \
	"openvswitch-ovn-common-2.9*" \
	"openvswitch-ovn-central-2.9*" \
	"openvswitch-ovn-host-2.9*" \
	"openvswitch-ovn-vtep-2.9*" \
	"openvswitch-devel-2.9*" \
	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/ && \
    cp go-controller/_output/go/bin/ovnkube /usr/bin/ && \
    cp go-controller/_output/go/bin/ovn-kube-util /usr/bin/ && \
    cp go-controller/_output/go/bin/ovn-k8s-cni-overlay /usr/libexec/cni/ovn-k8s-cni-overlay && \
    rm -rf go-controller

# 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


LABEL io.k8s.display-name="ovn kubernetes" \
      io.k8s.description="This is a component of OpenShift Container Platform that provides an overlay network using ovn." \
      io.openshift.tags="openshift" \
      maintainer="Phil Cameron <pcameron@redhat.com>"

WORKDIR /root
ENTRYPOINT /root/ovnkube.sh
