# Containerfile

# 기반 이미지를 NVIDIA CUDA 이미지로 변경
FROM nvidia/cuda:12.2.2-devel-ubuntu22.04

#MAINTAINER "birdhead"

# 로케일 및 타임존 환경 변수 설정
ENV LANG en_US.UTF-8
ENV TZ=Asia/Seoul
ENV DEBIAN_FRONTEND=noninteractive

# 패키지 설치
RUN \
    echo "deb http://kr.archive.ubuntu.com/ubuntu/ jammy main restricted universe multiverse" > /etc/apt/sources.list && \
    echo "deb http://kr.archive.ubuntu.com/ubuntu/ jammy-updates main restricted universe multiverse" >> /etc/apt/sources.list && \
    echo "deb http://kr.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse" >> /etc/apt/sources.list && \
    echo "deb http://security.ubuntu.com/ubuntu jammy-security main restricted universe multiverse" >> /etc/apt/sources.list && \
    apt-get update && \
    apt-get install -y --no-install-recommends \
        cron rsyslog openssh-server supervisor \
        build-essential vim curl wget git ca-certificates gnupg \
        sudo pkg-config \
        cmake g++ gdb \
        libboost-all-dev libdcmtk-dev libsndfile1-dev \
        libpq-dev libnsl-dev \
        python3 python3-pip python3-venv \
        ffmpeg libopenblas-dev && \
    \
    # --- SSH 호스트 키 생성 및 필요 디렉토리 설정 ---
    ssh-keygen -A && \
    mkdir -p /run/sshd && \
    chown root:root /run/sshd && \
    chmod 755 /run/sshd && \
    \
    # --- Node.js 22.x 버전 설치 시작 ---
    curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
    apt-get install -y nodejs && \
    # --- Node.js 설치 끝 ---
    \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*



# 필요한 커스텀 파일들을 이미지에 미리 복사
COPY --chown=root:root ./system/etc/. /etc/ 
COPY --chown=root:root ./system/usr_local/. /usr/local/

# Set Timezone
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# npm을 사용하여 pm2 전역 설치
RUN npm install pm2 -g && npm cache clean --force

# ssdoctors 사용자가 비밀번호 없이 sudo를 사용하도록 설정
RUN echo "ssdoctors ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/ssdoctors

# supervisord.conf 파일을 컨테이너 안으로 복사
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# 컨테이너 시작 시 실행할 명령
#CMD ["/usr/bin/supervisord", "-n",  "-c", "/etc/supervisord.conf"]


# ✅ entrypoint.sh 스크립트 추가
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
