# images
FROM ubuntu:20.04 

# package procedure(update&upgrade&install)
RUN apt-get update && \
    apt-get -y upgrade && \
    apt-get install -y openssh-server && \
    apt-get install -y vim net-tools && \
    apt-get install -y apt-utils && \
    apt-get install -y iputils-ping && \
    apt-get install -y wget && \
    apt-get install -y tar && \
    apt-get install -y curl && \
    apt-get install -y language-pack-ko && \
    apt-get install -y mariadb-server mariadb-client

#package clean unused
RUN apt-get clean && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Set up configuration for SSH
RUN mkdir /var/run/sshd
RUN echo 'root:!@#gds$%^' | chpasswd
RUN sed -ri 's/^#?PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config

# SSH login fix. Otherwise, user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile

# mariadb install and setting
RUN sed -ri 's/^#?bind-address\s+.*/bind-address = 0.0.0.0/' /etc/mysql/mariadb.conf.d/50-server.cnf
RUN sed -ri 's/^#?max_allowed_packet\s+.*/max_allowed_packet = 16M/' /etc/mysql/mariadb.conf.d/50-server.cnf
RUN echo lower_case_table_names=1 >> /etc/mysql/mariadb.conf.d/50-server.cnf
RUN echo default-time-zone='+9:00' >> /etc/mysql/mariadb.conf.d/50-server.cnf
RUN echo skip-character-set-client-handshake >> /etc/mysql/mariadb.conf.d/50-server.cnf

COPY make_root_remote_host.sh .
COPY setting.sql .

# Expose port
EXPOSE 22 3306

CMD ["root_remote_host.sh"]

# Run ssh,db
ENTRYPOINT  ["/bin/bash", "-c", "\
            source ~/.bashrc && \
            service mysql start && \
            service ssh start && \
            tail -f /dev/null"]
