ARG FROM=docker.io/ubuntu:focal
FROM ${FROM}

LABEL org.opencontainers.image.authors='airship-discuss@lists.airshipit.org, irc://#airshipit@freenode' \
      org.opencontainers.image.url='https://airshipit.org' \
      org.opencontainers.image.documentation='https://opendev.org/airship/porthole' \
      org.opencontainers.image.source='https://opendev.org/airship/porthole' \
      org.opencontainers.image.vendor='The Airship Authors' \
      org.opencontainers.image.licenses='Apache-2.0'

ARG KUBE_VERSION=1.31.0

ARG DEBIAN_FRONTEND=noninteractive

RUN set -xe \
    && sed -i '/nobody/d' /etc/passwd \
    && echo "nobody:x:65534:65534:nobody:/nonexistent:/bin/bash" >> /etc/passwd \
    && apt-get update && apt-get upgrade -y \
    && apt-get install -y --no-install-recommends \
         bash \
         ca-certificates \
         openvswitch-switch \
         curl \
         gnupg \
         hexedit \
         iperf \
         iproute2 \
         jq \
         moreutils \
         radosgw \
         rsyslog \
         s3cmd \
         rsync \
         sudo \
         xz-utils \
         python3.8 \
         python3-pip \
    && pip3 install --no-cache-dir --upgrade pip \
    && pip3 install --no-cache-dir \
        oslo.rootwrap==7.0.1 \
    && curl --silent -L https://dl.k8s.io/v${KUBE_VERSION}/kubernetes-client-linux-amd64.tar.gz \
       | tar -zC /usr/bin --strip-components=3 --wildcards -x "*/*/*/kubectl" \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

RUN PYTHON_LOCATION=$(pip3 show oslo.rootwrap|grep Location|awk '{print $2}') \
    && sed -i "/rootwrap_logger.setLevel/s/.*/#&/" $PYTHON_LOCATION/oslo_rootwrap/wrapper.py \
    && sed -i "/handler.setFormatter/s/.*/#&/" $PYTHON_LOCATION/oslo_rootwrap/wrapper.py \
    && sed -i "/os.path.basename/s/.*/#&/" $PYTHON_LOCATION/oslo_rootwrap/wrapper.py \
    && sed -i "/rootwrap_logger.addHandler/s/.*/#&/" $PYTHON_LOCATION/oslo_rootwrap/wrapper.py

CMD ["/bin/bash"]