#
# 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:rhel_8_golang_1.15 AS builder
ENV __doozer=update BUILD_RELEASE=202112031823.p0.g35fe274.assembly.stream 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-202112031823.p0.g35fe274.assembly.stream SOURCE_GIT_TREE_STATE=clean 
ENV __doozer=merge OS_GIT_COMMIT=35fe274 OS_GIT_VERSION=4.6.0-202112031823.p0.g35fe274.assembly.stream-35fe274 SOURCE_DATE_EPOCH=1631881550 SOURCE_GIT_COMMIT=35fe2741b33c82c31013368463a4f85d454827fe SOURCE_GIT_TAG=v0.3.11-2268-g35fe2741 SOURCE_GIT_URL=https://github.com/openshift/ovn-kubernetes 

WORKDIR /go/src/github.com/openshift/ovn-kubernetes
COPY . .

# build the binaries
RUN cd go-controller; CGO_ENABLED=0 make
RUN cd go-controller; CGO_ENABLED=0 make windows

FROM openshift/ose-cli:v4.6.0.20211203.190447 AS cli
ENV __doozer=update BUILD_RELEASE=202112031823.p0.g35fe274.assembly.stream 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-202112031823.p0.g35fe274.assembly.stream SOURCE_GIT_TREE_STATE=clean 
ENV __doozer=merge OS_GIT_COMMIT=35fe274 OS_GIT_VERSION=4.6.0-202112031823.p0.g35fe274.assembly.stream-35fe274 SOURCE_DATE_EPOCH=1631881550 SOURCE_GIT_COMMIT=35fe2741b33c82c31013368463a4f85d454827fe SOURCE_GIT_TAG=v0.3.11-2268-g35fe2741 SOURCE_GIT_URL=https://github.com/openshift/ovn-kubernetes 

FROM openshift/ose-base:v4.6.0-202111301700.p0.g618b71d.assembly.stream
ENV __doozer=update BUILD_RELEASE=202112031823.p0.g35fe274.assembly.stream 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-202112031823.p0.g35fe274.assembly.stream SOURCE_GIT_TREE_STATE=clean 
ENV __doozer=merge OS_GIT_COMMIT=35fe274 OS_GIT_VERSION=4.6.0-202112031823.p0.g35fe274.assembly.stream-35fe274 SOURCE_DATE_EPOCH=1631881550 SOURCE_GIT_COMMIT=35fe2741b33c82c31013368463a4f85d454827fe SOURCE_GIT_TAG=v0.3.11-2268-g35fe2741 SOURCE_GIT_URL=https://github.com/openshift/ovn-kubernetes 

USER root

ENV PYTHONDONTWRITEBYTECODE yes

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

ARG ovsver=2.13.0-72.el8fdp
ARG ovnver=20.12.0-24.el8fdp

RUN INSTALL_PKGS=" \
	openssl firewalld-filesystem \
	libpcap iproute strace \
	containernetworking-plugins \
	tcpdump iputils \
	" && \
	yum install -y --setopt=tsflags=nodocs --setopt=skip_missing_names_on_install=False $INSTALL_PKGS && \
	yum install -y --setopt=tsflags=nodocs --setopt=skip_missing_names_on_install=False "openvswitch2.13 == $ovsver" "openvswitch2.13-devel == $ovsver" && \
	yum install -y --setopt=tsflags=nodocs --setopt=skip_missing_names_on_install=False "ovn2.13 == $ovnver" "ovn2.13-central == $ovnver" "ovn2.13-host == $ovnver" "ovn2.13-vtep == $ovnver" && \
	yum clean all && rm -rf /var/cache/*

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

COPY --from=builder /go/src/github.com/openshift/ovn-kubernetes/go-controller/_output/go/bin/ovnkube /usr/bin/
COPY --from=builder /go/src/github.com/openshift/ovn-kubernetes/go-controller/_output/go/bin/ovn-kube-util /usr/bin/
COPY --from=builder /go/src/github.com/openshift/ovn-kubernetes/go-controller/_output/go/bin/ovn-k8s-cni-overlay /usr/libexec/cni/
COPY --from=builder /go/src/github.com/openshift/ovn-kubernetes/go-controller/_output/go/bin/windows/hybrid-overlay-node.exe /root/windows/
COPY --from=builder /go/src/github.com/openshift/ovn-kubernetes/go-controller/_output/go/bin/ovndbchecker /usr/bin/

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

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

# iptables wrappers
COPY ./dist/images/iptables-scripts/iptables /usr/sbin/
COPY ./dist/images/iptables-scripts/iptables-save /usr/sbin/
COPY ./dist/images/iptables-scripts/iptables-restore /usr/sbin/
COPY ./dist/images/iptables-scripts/ip6tables /usr/sbin/
COPY ./dist/images/iptables-scripts/ip6tables-save /usr/sbin/
COPY ./dist/images/iptables-scripts/ip6tables-restore /usr/sbin/
COPY ./dist/images/iptables-scripts/iptables /usr/sbin/


WORKDIR /root
ENTRYPOINT /root/ovnkube.sh

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." \
        summary="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>" \
        License="GPLv2+" \
        vendor="Red Hat" \
        name="openshift/ose-ovn-kubernetes" \
        com.redhat.component="ose-ovn-kubernetes-container" \
        io.openshift.maintainer.product="OpenShift Container Platform" \
        io.openshift.maintainer.component="Networking" \
        io.openshift.maintainer.subcomponent="ovn-kubernetes" \
        release="202112031823.p0.g35fe274.assembly.stream" \
        io.openshift.build.commit.id="35fe2741b33c82c31013368463a4f85d454827fe" \
        io.openshift.build.source-location="https://github.com/openshift/ovn-kubernetes" \
        io.openshift.build.commit.url="https://github.com/openshift/ovn-kubernetes/commit/35fe2741b33c82c31013368463a4f85d454827fe" \
        version="v4.6.0"

