FROM opensuse/leap:16.0

# System dependent

ARG TZ
ENV TZ=${TZ}

ARG GCT_REPO=https://download.opensuse.org/repositories/home:/frank_scheiner:/gct/16.0/home:frank_scheiner:gct.repo

# MyProxy is not available in the openSUSE 16.0 GCT repository.
# Build and install MyProxy from source instead.
RUN zypper --non-interactive install -y \
    sudo \
    openssh \
    rsyslog \
    systemd \
    patch \
    rpm-build \
    wget \
    rsync \
    git \
    && systemctl enable sshd \
    && zypper --non-interactive install -y \
    libopenssl-devel \
    krb5-devel krb5-server krb5-client \
    cyrus-sasl cyrus-sasl-devel cyrus-sasl-plain cyrus-sasl-gssapi \
    go jq \
    gcc-c++ cmake sqlite-devel libcurl-devel libuuid-devel lsb-release \
    postgresql \
    postgresql-devel \
    postgresql-server \
    postgresql-server-devel \
    fuse \
    fuse-devel \
    fuse3 \
    fuse3-devel \
    autofs \
    libacl-devel \
    ruby \
    libtool \
    && zypper --non-interactive addrepo ${GCT_REPO} \
    && zypper --gpg-auto-import-keys --non-interactive refresh \
    && zypper --non-interactive install -y \
    globus-gssapi-gsi-devel \
    globus-gss-assist-devel \
    globus-gsi-sysconfig-devel \
    globus-gsi-cert-utils-devel \
    globus-gsi-cert-utils-progs \
    globus-gsi-proxy-core-devel \
    globus-gsi-credential-devel \
    globus-gsi-callback-devel \
    globus-common-devel \
    globus-simple-ca \
    globus-proxy-utils \
    && git clone https://github.com/gridcf/gct.git \
    && cd gct/myproxy/source \
    && autoreconf -fi \
    && ./configure \
    && make -j"$(nproc)" \
    && make install \
    && echo /usr/local/lib > /etc/ld.so.conf.d/myproxy.conf \
    && ldconfig \
    && myproxy-logon --help >/dev/null \
    && cd / \
    && rm -rf gct \
    && globus-version \
    && zypper --non-interactive install -y \
    python3 \
    python3-docopt \
    python3-schema \
    python3-tqdm \
    python3-flake8 \
    && zypper --non-interactive mr -e openSUSE:repo-oss-debug \
    && zypper --non-interactive refresh \
    && zypper --non-interactive install -y \
    telnet netcat-openbsd ldns iproute2 net-tools bind-utils tcpdump \
    gdb valgrind strace inotify-tools \
    man man-pages man-pages-ja \
    nano emacs-nox vim less which \
    libfuse2-debuginfo \
    && sed -i 's@^Defaults secure_path="/usr/sbin:@Defaults secure_path="/usr/local/bin:/usr/sbin:@' /usr/etc/sudoers

# System independent (see setup-univ.sh)

ARG GFDOCKER_USERNAME_PREFIX
ARG GFDOCKER_TENANTNAME_PREFIX
ARG GFDOCKER_PRIMARY_USER
ARG GFDOCKER_PRIMARY_UID
ARG GFDOCKER_TENANT_ADMIN_USER
ARG GFDOCKER_TENANT_ADMIN_UID
ARG GFDOCKER_NUM_GFMDS
ARG GFDOCKER_NUM_GFSDS
ARG GFDOCKER_NUM_USERS
ARG GFDOCKER_NUM_TENANTS
ARG GFDOCKER_HOSTNAME_PREFIX_GFMD
ARG GFDOCKER_HOSTNAME_PREFIX_GFSD
ARG GFDOCKER_HOSTNAME_SUFFIX
ARG GFDOCKER_USE_SAN_FOR_GFSD
COPY --chown=${GFDOCKER_PRIMARY_UID}:${GFDOCKER_PRIMARY_UID} . /work/gfarm
COPY --chown=${GFDOCKER_TENANT_ADMIN_UID}:${GFDOCKER_TENANT_ADMIN_UID} \
	. /work/gfarm2
RUN "/work/gfarm/docker/dev/common/setup-univ.sh"

CMD ["/sbin/init"]
