diff --git a/.gitignore b/.gitignore index 633b59410..9f5f93890 100644 --- a/.gitignore +++ b/.gitignore @@ -1,26 +1,65 @@ +# Git 저장소 설정 파일을 무시하지 않도록 설정 !.gitignore + +# Visual Studio Code 설정 디렉토리 무시 .vscode + +# Visual Studio Code 서버 설정 디렉토리 무시 .vscode-server + +# Python 컴파일 캐시 무시 __pycache__ + +# Python 컴파일된 파일 무시 *.pyc *.pyo + +# Vim 정보 파일 무시 .viminfo + +# 캐시 디렉토리 무시 .cache + +# 로컬 디렉토리 무시 .local + +# .bash로 시작하는 파일 무시 .bash* + +# 데이터 디렉토리 무시 data/ + +# test로 시작하고 어떤 확장자로 끝나는 파일 무시 test.* + +# IntelliJ IDEA 설정 디렉토리 무시 .idea + +# 환경 설정 파일 무시 .env prod.env dev.env + +# 로컬 개발용 SSL 인증서 무시 localhost.crt localhost.key + +# SQLite 데이터베이스 파일 무시 sqlite3.db *.db + +# 가상 환경 디렉토리 무시 venv/ + +# PyCharm 플러그인 상태 파일 무시 plugin_states.json plugin_states.json.lock + +# 로그 설정 파일 무시 log_config.ini + +# Uvicorn 로그 파일 무시 uvicorn.log + +# 로그 디렉토리 무시 log/ diff --git a/Base.Dockerfile b/Base.Dockerfile new file mode 100644 index 000000000..683f2d099 --- /dev/null +++ b/Base.Dockerfile @@ -0,0 +1,57 @@ +FROM python:bookworm AS git-base + +ARG user=g6 +RUN useradd --create-home --shell /bin/bash $user + +WORKDIR /g6 +COPY . . + +RUN mkdir -p /g6/data +RUN chown -R $user:$user /g6 +# Encountering issues with the ownership change of the ./data directory. +# The exact cause is unclear, however, the COPY --chown option does not +# seem to be working as expected for the ./data directory. +# As a result, we're utilising the RUN command to correctly set the ownership. + +RUN find . -mindepth 1 -maxdepth 1 \( -name '.*' ! -name '.' ! -name '..' \) -o \( -name '*.md' -o -name '*.yml' \) -exec bash -c 'echo "Deleting {}"; rm -rf {}' \; + +FROM python:bookworm AS env-builder + +ARG user=g6 +RUN useradd --create-home --shell /bin/bash $user + +ARG TARGETARCH +COPY --from=git-base /g6/requirements.txt /g6/requirements.txt + +WORKDIR /g6 +RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked \ + --mount=target=/var/cache/apt,type=cache,sharing=locked \ + rm -f /etc/apt/apt.conf.d/docker-clean \ + && apt-get update \ + && apt-get -y --no-install-recommends install \ + locales \ + tini + +RUN if [ "$TARGETARCH" = "arm" ]; then \ + apt-get update \ + && apt-get -y install \ + cmake \ + ninja-build \ + build-essential \ + g++ \ + gobjc \ + meson \ + liblapack-dev \ + libblis-dev \ + libblas-dev \ + rustc \ + cargo \ + libopenblas-dev \ + python3-dev; \ + fi + +RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen +RUN dpkg-reconfigure --frontend=noninteractive locales +RUN python3 -m venv /venv +RUN /venv/bin/python3 -m pip install -r requirements.txt +COPY --from=git-base --chown=$user:$user /g6 /standby-g6 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..0a8c636f9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +FROM python:bookworm AS git-base +WORKDIR /g6 +COPY . . +RUN find . -mindepth 1 -maxdepth 1 \( -name '.*' ! -name '.' ! -name '..' \) -o \( -name '*.md' -o -name '*.yml' \) -exec bash -c 'echo "Deleting {}"; rm -rf {}' \; + +FROM ghcr.io/navystack/gnuboard-g6:base-nightly AS base +RUN rm -rf /g6/requirements.txt +COPY --from=git-base --chown=$user:$user /g6/requirements.txt /g6/requirements.txt + +RUN /venv/bin/python3 -m pip install -r requirements.txt +RUN find . -type f \( -name '__pycache__' -o -name '*.pyc' -o -name '*.pyo' \) -exec bash -c 'echo "Deleting {}"; rm -f {}' \; + +FROM python:slim-bookworm AS final + +ARG user=g6 +RUN useradd --create-home --shell /bin/bash $user + +COPY --from=base --chown=$user:$user /standby-g6 /g6 +COPY --from=base --chown=$user:$user /venv /venv +COPY --from=base --chown=$user:$user /usr/bin/tini /usr/bin/tini + +USER g6 +WORKDIR /g6 +VOLUME /g6/data +EXPOSE 8000 + +ENTRYPOINT ["tini", "--"] +# Utilising tini as our init system within the Docker container for graceful start-up and termination. +# Tini serves as an uncomplicated init system, adept at managing the reaping of zombie processes and forwarding signals. +# This approach is crucial to circumvent issues with unmanaged subprocesses and signal handling in containerised environments. +# By integrating tini, we enhance the reliability and stability of our Docker containers. +# Ensures smooth start-up and shutdown processes, and reliable, safe handling of signal processing. + +CMD ["/venv/bin/uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] \ No newline at end of file diff --git a/Full.Dockerfile b/Full.Dockerfile new file mode 100644 index 000000000..b64ad04b8 --- /dev/null +++ b/Full.Dockerfile @@ -0,0 +1,80 @@ +FROM python:bookworm AS git-base + +ARG user=g6 +RUN useradd --create-home --shell /bin/bash $user + +WORKDIR /g6 +COPY . . + +RUN mkdir -p /g6/data +RUN chown -R $user:$user /g6 +# Encountering issues with the ownership change of the ./data directory. +# The exact cause is unclear, however, the COPY --chown option does not +# seem to be working as expected for the ./data directory. +# As a result, we're utilising the RUN command to correctly set the ownership. + +RUN find . -mindepth 1 -maxdepth 1 \( -name '.*' ! -name '.' ! -name '..' \) -o \( -name '*.md' -o -name '*.yml' \) -exec bash -c 'echo "Deleting {}"; rm -rf {}' \; + +FROM python:bookworm AS env-builder + +ARG user=g6 +RUN useradd --create-home --shell /bin/bash $user + +ARG TARGETARCH +COPY --from=git-base /g6/requirements.txt /g6/requirements.txt + +WORKDIR /g6 +RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked \ + --mount=target=/var/cache/apt,type=cache,sharing=locked \ + rm -f /etc/apt/apt.conf.d/docker-clean \ + && apt-get update \ + && apt-get -y --no-install-recommends install \ + locales \ + tini + +RUN if [ "$TARGETARCH" = "arm" ]; then \ + apt-get update \ + && apt-get -y install \ + cmake \ + ninja-build \ + build-essential \ + g++ \ + gobjc \ + meson \ + liblapack-dev \ + libblis-dev \ + libblas-dev \ + rustc \ + cargo \ + libopenblas-dev \ + python3-dev; \ + fi + +RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen +RUN dpkg-reconfigure --frontend=noninteractive locales +RUN python3 -m venv /venv +RUN /venv/bin/python3 -m pip install -r requirements.txt -vvv +RUN find . -type f \( -name '__pycache__' -o -name '*.pyc' -o -name '*.pyo' \) -exec bash -c 'echo "Deleting {}"; rm -f {}' \; + +FROM python:slim-bookworm AS final + +ARG user=g6 +RUN useradd --create-home --shell /bin/bash $user + +COPY --from=git-base --chown=$user:$user /g6 /g6 +COPY --from=env-builder --chown=$user:$user /venv /venv +COPY --from=env-builder --chown=$user:$user /usr/bin/tini /usr/bin/tini + +USER g6 +WORKDIR /g6 +VOLUME /g6/data +EXPOSE 8000 + +ENTRYPOINT ["tini", "--"] +# Utilising tini as our init system within the Docker container for graceful start-up and termination. +# Tini serves as an uncomplicated init system, adept at managing the reaping of zombie processes and forwarding signals. +# This approach is crucial to circumvent issues with unmanaged subprocesses and signal handling in containerised environments. +# By integrating tini, we enhance the reliability and stability of our Docker containers. +# Ensures smooth start-up and shutdown processes, and reliable, safe handling of signal processing. + +CMD ["/venv/bin/uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] \ No newline at end of file diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml new file mode 100644 index 000000000..641a0cfdd --- /dev/null +++ b/docker-compose-dev.yml @@ -0,0 +1,14 @@ +version: "3.8" +services: + gnuboard-g6: + restart: always + build: + context: . + dockerfile: Full.Dockerfile + volumes: + - gnuboard6-data-dev:/g6/data + ports: + - "8000:8000" + +volumes: + gnuboard6-data-dev: