# 设置基础镜像
FROM ubuntu:20.04

# 作者信息
MAINTAINER GrayZhao "gray.zhao@qq.com"

# 设置上海时区
ENV TZ='Asia/Shanghai' LANG=C.UTF-8

# 配置镜像源，pip源，后面安装依赖时可以加快速度
# 创建软链接，将Python3.10.12设置为python3，将Python3.10.12的pip3设置为pip3
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
    sed -i 's/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list && \
    apt-get update && apt-get upgrade -y && \
    apt-get install -y openssh-server net-tools vim git wget curl make build-essential zlib1g-dev libncurses5-dev \
    libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev libbz2-dev python-openssl


# 下载并编译安装Python 3.10.12
WORKDIR /tmp
RUN wget https://www.python.org/ftp/python/3.10.12/Python-3.10.12.tgz && \
    tar -zvxf Python-3.10.12.tgz && \
    cd Python-3.10.12 && \
    ./configure --enable-optimizations && \
    make && \
    make install && \
    rm -rf /tmp/Python-3.10.12*

# 设置 Python3 为默认的 python3 版本
# 设置 pip3 为 Python3.10.12 的 pip3 版本
# 配置镜像源，pip源
RUN ln -sf /usr/local/bin/python3.10 /usr/bin/python && \
    ln -sf /usr/local/bin/pip3.10 /usr/bin/pip && \
    pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple


# 配置 ssh
RUN bash -c "source ~/.bashrc; \
    mkdir /var/run/sshd; \
    echo 'root:sheepbot' | chpasswd; \
    sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config; \
    echo 'PermitEmptyPasswords yes' >> /etc/ssh/sshd_config; \
    echo 'PasswordAuthentication yes' >> /etc/ssh/sshd_config;"

# 服务提供的外部端口号
EXPOSE 22


# 启动 ssh 服务
CMD ["/usr/sbin/sshd", "-D"]
