# os with ssh
# images
FROM centos:6.10

# clear yum cache
RUN rm -f /var/lib/rpm/__*
RUN yum clean all
RUN rm -rf /var/cache/yum

# make new repo with vault.centos
RUN mkdir -p /var/cache/yum/x86_64/6/base/
RUN mkdir -p /var/cache/yum/x86_64/6/extras/
RUN mkdir -p /var/cache/yum/x86_64/6/updates/

RUN echo "http://vault.centos.org/6.10/os/x86_64/" > /var/cache/yum/x86_64/6/base/mirrorlist.txt
RUN echo "http://vault.centos.org/6.10/extras/x86_64/" > /var/cache/yum/x86_64/6/extras/mirrorlist.txt
RUN echo "http://vault.centos.org/6.10/updates/x86_64/" > /var/cache/yum/x86_64/6/updates/mirrorlist.txt

#makecache
RUN yum makecache

# Update the system
RUN yum -y update

# Setting Utils
RUN yum install -y vim net-tools iputils wget tar curl glibc libstdc++ zip unzip scp

# Setting locale ko
RUN yum install -y glibc && \
    localedef -i ko_KR -f UTF-8 ko_KR.UTF-8 && \
    echo -e "# Setting Language(ko_KR.UTF-8)\nexport LANGUAGE=ko_KR.UTF-8\nexport LANG=ko_KR.UTF-8" >> /etc/profile

# Install OpenSSH Server
RUN yum install -y openssh-server openssh-clients

# Set up configuration for SSH
RUN mkdir /var/run/sshd
RUN echo 'root:!@#gds$%^' | chpasswd
RUN echo "    StrictHostKeyChecking no" >> /etc/ssh/ssh_config

# SSH login fix. Otherwise, the 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

# mySQL install
RUN yum install -y mysql-server

# mySQL setting
RUN sed -ri 's/^#?bind-address\s+.*/bind-address = 0.0.0.0/' /etc/my.cnf
RUN echo default-character-set=utf8 >> /etc/my.cnf
RUN echo lower_case_table_names=1 >> /etc/my.cnf
RUN echo default-time-zone='+9:00' >> /etc/my.cnf
RUN echo skip-character-set-client-handshake >> /etc/my.cnf

#apache install
RUN yum install -y httpd

#php install
RUN yum install -y php php-mbstring php-pdo php-xml php-mysql

# run script folder and copy script
RUN mkdir /service_script
COPY start_service.sh /service_script
RUN rm /etc/httpd/conf/httpd.conf
RUN rm /etc/ssh/sshd_config
RUN rm /etc/php.ini
RUN rm /etc/my.cnf
COPY httpd.conf /etc/httpd/conf
COPY sshd_config /etc/ssh/
COPY php.ini /etc
COPY my.cnf /etc
COPY setting.sql /service_script
COPY dump.sql /service_script
RUN chmod +x /service_script/start_service.sh

# Expose port
EXPOSE 22 3306 80

# Run SSH, DB, APACHE
CMD ["/service_script/start_service.sh"]
