FROM s390x/ubuntu:focal

ARG user
ARG group=${user}
ARG uid
ARG gid

ENV JENKINS_HOME /home/${user}

# Make sure the uid/gid of the container user matches the host user
RUN groupadd -g ${gid} ${group} \
    && useradd -d "$JENKINS_HOME" -u ${uid} -g ${gid} -m -s /bin/bash ${user}
RUN chown -R ${user}:${user} /home/${user}

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update ; \
    apt-get install -y make sudo wget git docker.io shellcheck openjdk-11-jdk tar gzip zip patch ruby curl openssl diffutils file procps python3 perl || true; \
    apt-get install -y docker.io iptables ebtables ethtool ca-certificates conntrack socat git nfs-common cifs-utils apt-transport-https gnupg2 software-properties-common bridge-utils ipcalc aufs-tools kmod || true; \
    apt-get clean

# Add the jenkins user to sudoers
RUN echo "${user}    ALL=(ALL)    NOPASSWD:ALL" >> /etc/sudoers

RUN wget https://github.com/docker/buildx/releases/download/v0.6.1/buildx-v0.6.1.linux-s390x; \
    mkdir -p /home/${user}/.docker/cli-plugins; \
    mv buildx-v0.6.1.linux-s390x /home/${user}/.docker/cli-plugins/docker-buildx; \
    chmod a+x /home/${user}/.docker/cli-plugins/docker-buildx; \
    chown -R ${user}:${user} /home/${user}/.docker

RUN wget https://archive.apache.org/dist/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.tar.gz; \
    tar -zxf apache-maven-3.8.4-bin.tar.gz; \
    mv apache-maven-3.8.4 /opt/; \
    rm -f apache-maven-3.8.4-bin.tar.gz; \
    ln -s /opt/apache-maven-3.8.4/bin/mvn /usr/bin/mvn; \
    ln -s /opt/apache-maven-3.8.4/bin/mvn /usr/local/bin/mvn

VOLUME /var/lib/docker
