FROM centos:7

ENV container docker
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
    rm -f /lib/systemd/system/multi-user.target.wants/*;\
    rm -f /etc/systemd/system/*.wants/*;\
    rm -f /lib/systemd/system/local-fs.target.wants/*; \
    rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
    rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
    rm -f /lib/systemd/system/basic.target.wants/*;\
    rm -f /lib/systemd/system/anaconda.target.wants/*;

RUN echo "timeout=30000" >> /etc/yum.conf

RUN yum update -y && \
    yum install -y sudo mysql vim iproute tzdata haproxy
RUN yum install -y openssh openssh-server openssh-clients && \
    sed -e 's/#PermitRootLogin yes/PermitRootLogin yes/g' \
    -i /etc/ssh/sshd_config && \
    systemctl enable sshd.service

RUN yum install -y gdb && \
    debuginfo-install -y glibc libgcc
RUN yum install -y centos-release-scl-rh
RUN yum install -y devtoolset-8-build devtoolset-8-gdb
RUN yum install -y iptables ipset iproute2
RUN yum install -y sysvinit-tools

WORKDIR /root

RUN ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa <<< y
RUN cat ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys

# Set TimeZone
ENV TZ Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# See https://github.com/moby/moby/issues/4040#issuecomment-339022455
RUN sudo cp /bin/true /sbin/agetty
RUN rm -rf /lib/systemd/system/getty@.service
RUN rm -rf /usr/lib/systemd/system/getty@.service

# Install tiup
RUN curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh

EXPOSE 22
ENV PATH="/root/.tiup/bin:/opt/rh/devtoolset-8/root/usr/bin:${PATH}"
VOLUME [ "/sys/fs/cgroup" ]
CMD ["/usr/sbin/init"]

# hub.pingcap.net/qa/base-image:latest
