# 베이스 이미지로부터 시작합니다.
FROM ubuntu:22.04

# 필수 패키지 설치
RUN apt-get update && \
  apt-get upgrade -y && \
  apt-get install -y openssh-server gcc mecab libmecab-dev mecab-ipadic-utf8 vim g++ wget curl net-tools ubuntu-drivers-common git python3.10 python3-pip python3.10-venv && \
  pip install eunjeon

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

# 작업 디렉토리 설정
WORKDIR /app

# 가상 환경 생성
RUN python3.10 -m venv /app/venv

# 가상 환경 활성화 및 requirements.txt 설치
COPY requirements.txt .
RUN /app/venv/bin/pip install --upgrade pip && \
    /app/venv/bin/pip install mkl-fft && \
    /app/venv/bin/pip install -r requirements.txt

# Jupyter 및 추가 패키지 설치
RUN /app/venv/bin/pip install jupyter notebook theme-darcula torch torchvision torchaudio

# Jupyter의 설정 파일을 생성합니다.
RUN /app/venv/bin/jupyter notebook --generate-config

# 권한 설정
COPY start_service.sh .
RUN chmod +x /app/start_service.sh

# Jupyter의 비밀번호를 설정합니다.
RUN echo "c.NotebookApp.password = 'sha1:3c2088751e24:247c5332fcc1f9bb71203adb8573a701abe0f3a9'" >> /root/.jupyter/jupyter_notebook_config.py

# 디렉토리 권한 설정
RUN chown -R root:root /app && chmod -R 755 /app

# 포트 설정
EXPOSE 22 8888

# 가상 환경 활성화 후 Jupyter 및 SSH 서버 실행
CMD ["/bin/sh", "-c", "/app/venv/bin/jupyter lab --ip=0.0.0.0 --port=8888 --allow-root --no-browser && /app/start_service.sh"]

