#!BuildTag: harbor/harbor-test:%%PKG_VERSION%%
#!BuildTag: harbor/harbor-test:%%PKG_VERSION%%-rev%%IMAGE_REVISION%%
#!BuildTag: harbor/harbor-test:%%PKG_VERSION%%-rev%%IMAGE_REVISION%%-build%RELEASE%

FROM suse/sle15:15.2

# labelprefix=com.suse.registry
PREFIXEDLABEL org.opencontainers.image.title="SUSE private registry, Harbor test container"
PREFIXEDLABEL org.opencontainers.image.description="Harbor test container image for SUSE private registry"
PREFIXEDLABEL org.opencontainers.image.created="%BUILDTIME%"
PREFIXEDLABEL org.opencontainers.image.vendor="SUSE LLC"
PREFIXEDLABEL org.opencontainers.image.url="https://www.suse.com/products/"
PREFIXEDLABEL org.opencontainers.image.version="%%PKG_VERSION%%-rev%%IMAGE_REVISION%%-build%RELEASE%"
PREFIXEDLABEL org.openbuildservice.disturl="%DISTURL%"
PREFIXEDLABEL org.opensuse.reference="registry.suse.com/harbor/harbor-test:%%PKG_VERSION%%-rev%%IMAGE_REVISION%%-build%RELEASE%" 

COPY ./run-harbor-tests.sh /usr/local/bin/run-harbor-tests.sh
COPY ./entrypoint.sh /usr/local/bin/entrypoint.sh

RUN groupadd -r -g 10000 harbor \
  && useradd -r -g harbor -d /var/lib/harbor -s /sbin/nologin -m -l -c "user for Harbor registry" -u 10000 harbor \
  && chmod +x /usr/local/bin/run-harbor-tests.sh /usr/local/bin/entrypoint.sh

#docker-dind
COPY ./dockerd-entrypoint.sh /usr/local/bin/
COPY ./dind /usr/local/bin/
RUN chmod +x /usr/local/bin/dockerd-entrypoint.sh /usr/local/bin/dind

RUN zypper --non-interactive install \
  harbor-test gosu \
  # docker-dind
  btrfsprogs \
  docker \
  e2fsprogs \
  gawk \
  harbor \
  hostname \
  iptables \
  openssl \
  pigz \
  wget \
  which \
  xfsprogs \
  xz

# Enable harbor user to run docker commands
RUN /usr/sbin/usermod -aG docker harbor

# Required by harbor test scripts (see https://github.com/goharbor/harbor/blob/v2.0.0/tests/e2e-image/Dockerfile#L85)
RUN ln -s /usr/bin/helm /usr/bin/helm3 && ln -s /usr/bin/python3 /usr/local/bin/python

# docker-dind: set up subuid/subgid so that "--userns-remap=default" works out-of-the-box
RUN echo 'dockremap:165536:65536' >> /etc/subuid \
  && echo 'dockremap:165536:65536' >> /etc/subgid

WORKDIR /var/lib/harbor-test
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
