ARG VERSION=franela/docker:ubuntu-19.03ee
#ARG VERSION=franela/docker:18.09.2-ee-dind

FROM ${VERSION}

RUN apt-get update \ 
    && apt-get install -y git tmux python-pip apache2-utils vim curl jq bash-completion screen tree zip \
    && rm -rf /var/lib/apt/lists/*

# Add kubectl client
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.11.7/bin/linux/amd64/kubectl \
    && chmod +x ./kubectl \
    && mv ./kubectl /usr/local/bin/kubectl 

ENV COMPOSE_VERSION=1.22.0

RUN pip install docker-compose==${COMPOSE_VERSION}
RUN curl -L https://github.com/docker/machine/releases/download/${MACHINE_VERSION}/docker-machine-Linux-x86_64 \
    -o /usr/bin/docker-machine && chmod +x /usr/bin/docker-machine
 

# Install a nice vimrc file and prompt (by soulshake)
COPY ["docker-prompt", "sudo", "ucp-beta.sh", "/usr/local/bin/"]
COPY [".vimrc",".profile", ".inputrc", ".gitconfig", "workshop_beta.lic", "ucp-config.toml", "./root/"]
COPY ["motd", "/etc/motd"]
COPY ["ee/daemon.json", "/etc/docker/"]
COPY ["ee/cert.pem", "ee/key.pem", "/opt/pwd/certs/"]
COPY ["ee/ucp-key.pem", "./root/key.pem"]
COPY ["ee/ucp-cert.pem", "./root/cert.pem"]

# Move to our home
WORKDIR /root

# Setup certs and uploads folders
RUN mkdir -p /opt/pwd/certs /opt/pwd/uploads

VOLUME ["/var/lib/kubelet"]

# Remove IPv6 alias for localhost and start docker in the background ...
CMD cat /etc/hosts >/etc/hosts.bak && \
    sed 's/^::1.*//' /etc/hosts.bak > /etc/hosts && \
    sed -i "s/\PWD_IP_ADDRESS/$PWD_IP_ADDRESS/" /etc/docker/daemon.json && \
    sed -i "s/\DOCKER_TLSENABLE/$DOCKER_TLSENABLE/" /etc/docker/daemon.json && \
    sed -i "s/\DOCKER_TLSCACERT/$DOCKER_TLSCACERT/" /etc/docker/daemon.json && \
    sed -i "s/\DOCKER_TLSCERT/$DOCKER_TLSCERT/" /etc/docker/daemon.json && \
    sed -i "s/\DOCKER_TLSKEY/$DOCKER_TLSKEY/" /etc/docker/daemon.json && \
    mount -t securityfs none /sys/kernel/security && \
    mount --make-rshared / && \
    #mount --make-rshared -t tmpfs tmpfs /run && \
    #mount --make-rshared /var/lib/kubelet && \
    #mount --make-rshared /var/lib/docker && \
    dockerd > /docker.log 2>&1 & \
    while true ; do script -q -c "/bin/bash -l" /dev/null ; done
# ... and then put a shell in the foreground, restarting it if it exits
