diff --git a/.copier-template/.docker/docker.app.env.jinja b/.copier-template/.docker/docker.app.env.jinja index 50573f0..2e7b026 100644 --- a/.copier-template/.docker/docker.app.env.jinja +++ b/.copier-template/.docker/docker.app.env.jinja @@ -8,8 +8,6 @@ APP_USER_EMAIL=${USER_EMAIL:-"`{{ email }}`"} # The email APP_SOURCE_REPO=${`{{ docker_name_prefix }}`_SOURCE_REPO:-"`{{ app_source_repo }}`"} # The GitHub repository name of the project APP_SOURCE_BRANCH=${`{{ docker_name_prefix }}`_SOURCE_BRANCH:-"`{{ app_source_branch }}`"} # The branch of the project to clone -APP_INSTALL_ROOT=${`{{ docker_name_prefix }}`_INSTALL_ROOT:-"`{{ app_install_root }}`"} # The directory in the container where the project will be installed or cloned -APP_CLONE_DIRNAME=${`{{ docker_name_prefix }}`_CLONE_DIRNAME:-"`{{ app_clone_dirname }}`"} # The directory name for the cloned project ####################################################################################### # Please do not make any changes below this line if you don't know what you are doing # diff --git a/.copier-template/.docker/docker.common.env.jinja b/.copier-template/.docker/docker.common.env.jinja index 5e8d4de..706dcfd 100644 --- a/.copier-template/.docker/docker.common.env.jinja +++ b/.copier-template/.docker/docker.common.env.jinja @@ -1,3 +1,13 @@ +######################################################### +# Configuration parameters for the docker project # +# Change the variables below to your need: # +######################################################### +APP_INSTALL_ROOT=${`{{ docker_name_prefix }}`_INSTALL_ROOT:-"`{{ app_install_root }}`"} # The directory in the container where the project will be installed or cloned +APP_CLONE_DIRNAME=${`{{ docker_name_prefix }}`_CLONE_DIRNAME:-"`{{ app_clone_dirname }}`"} # The directory name for the cloned project +APP_SRC_DIR=${APP_INSTALL_ROOT}/${APP_CLONE_DIRNAME} +APP_VIRTUAL_ENV=${APP_INSTALL_ROOT}/.venvs/${APP_CLONE_DIRNAME} +APP_WORKSPACE_ROOT=${APP_INSTALL_ROOT}/workspace + ####################################################################################### # Host machine environment variables # ####################################################################################### diff --git a/.copier-template/.docker/scripts/requirements-base.txt b/.copier-template/.docker/scripts/{% if install_pip_requirements -%}requirements-base.txt{% endif %} similarity index 100% rename from .copier-template/.docker/scripts/requirements-base.txt rename to .copier-template/.docker/scripts/{% if install_pip_requirements -%}requirements-base.txt{% endif %} diff --git a/.copier-template/.docker/scripts/requirements.txt b/.copier-template/.docker/scripts/{% if install_pip_requirements -%}requirements.txt{% endif %} similarity index 100% rename from .copier-template/.docker/scripts/requirements.txt rename to .copier-template/.docker/scripts/{% if install_pip_requirements -%}requirements.txt{% endif %} diff --git a/.copier-template/.docker/{% if build_images_from_dockerfile %}Dockerfile.app{% endif %}.jinja b/.copier-template/.docker/{% if build_images_from_dockerfile %}Dockerfile.app{% endif %}.jinja index f6cbf3c..440e27a 100644 --- a/.copier-template/.docker/{% if build_images_from_dockerfile %}Dockerfile.app{% endif %}.jinja +++ b/.copier-template/.docker/{% if build_images_from_dockerfile %}Dockerfile.app{% endif %}.jinja @@ -12,8 +12,47 @@ ENV USER_UID $ARG_USER_UID ENV USER_GID $ARG_USER_GID ENV WORKSPACE_ROOT $ARG_WORKSPACE_ROOT +# Sets up the workspace for the user +RUN if [ ! -d $WORKSPACE_ROOT/projects ]; then mkdir -p $WORKSPACE_ROOT/projects; fi + +# Sets the working directory to workspace root +WORKDIR $WORKSPACE_ROOT +{% if copy_scripts_dir -%} +# Copies scripts from host into the image +COPY ./.docker/scripts/ ./scripts/ +{%- endif %} +{% if install_pip_requirements -%} +# Installs Python dependencies listed in requirements.txt +RUN if [ -f ./scripts/requirements.txt ]; then `{{ pip_command }}` install -r ./scripts/requirements.txt; fi +{%- endif %} + +# Setting ARGs and ENVs for Stable-Diffusion-WebUI GitHub repository +ARG ARG_APP_SOURCE_REPO="`{{ app_source_repo }}`" +ARG ARG_APP_INSTALL_ROOT="`{{ app_install_root }}`" +ARG ARG_APP_CLONE_DIRNAME="`{{ app_clone_dirname }}`" +ARG ARG_APP_SOURCE_BRANCH="`{{ app_source_branch }}`" +ARG ARG_APP_SERVICE_NAME="`{{ app_service_name }}`" +ENV APP_SOURCE_REPO $ARG_APP_SOURCE_REPO +ENV APP_INSTALL_ROOT $ARG_APP_INSTALL_ROOT +ENV APP_CLONE_DIRNAME $ARG_APP_CLONE_DIRNAME +ENV APP_SOURCE_BRANCH $ARG_APP_SOURCE_BRANCH +ENV APP_SERVICE_NAME $ARG_APP_SERVICE_NAME +ENV APP_SRC_DIR=${APP_INSTALL_ROOT}/${APP_CLONE_DIRNAME} +ENV APP_VIRTUAL_ENV=${APP_INSTALL_ROOT}/.venvs/${APP_CLONE_DIRNAME} +ENV APP_WORKSPACE_ROOT=${APP_INSTALL_ROOT}/workspace + +{% if clone_source_code and app_source_repo -%} +# Clones the app repository from GitHub +RUN git clone --branch $APP_SOURCE_BRANCH https://github.com/${ARG_APP_SOURCE_REPO}.git ${APP_SRC_DIR} &&\ + cd ${APP_SRC_DIR} &&\ + git checkout $APP_SOURCE_BRANCH +{%- endif %} + +RUN chown -R $USERNAME:$USERNAME $WORKSPACE_ROOT +RUN chown -R $USERNAME:$USERNAME $APP_INSTALL_ROOT + +{% if install_dotfiles -%} # Creates a non-root user with sudo privileges -USER root # check if user exists and if not, create user RUN if id -u $USERNAME >/dev/null 2>&1; then \ echo "User exists"; \ @@ -29,20 +68,7 @@ RUN if id -u $USERNAME >/dev/null 2>&1; then \ # Switches to the newly created user USER $USERNAME -# Sets up the workspace for the user -RUN sudo rm -rf $WORKSPACE_ROOT && sudo mkdir -p $WORKSPACE_ROOT/projects -RUN sudo chown -R $USERNAME:$USERNAME $WORKSPACE_ROOT -# Adds .local/bin to PATH -ENV PATH="/home/$USERNAME/.local/bin:${PATH}" -# Sets Python environment variables -ENV PIP_DEFAULT_TIMEOUT 100 -ENV PYTHONDONTWRITEBYTECODE 1 -ENV PYTHONUNBUFFERED 1 -# Sets the time zone within the container -ENV TZ="`{{ docker_timezone }}`" - -{% if install_dotfiles -%} # Install dotfiles ARG ARG_USER_FULLNAME ARG ARG_USER_EMAIL @@ -71,28 +97,5 @@ RUN if [ -d "/home/$USERNAME/.dotfiles" ]; then \ fi {%- endif %} -# Sets the working directory to workspace root -WORKDIR $WORKSPACE_ROOT -{% if copy_scripts_dir -%} -# Copies scripts from host into the image -COPY ./.docker/scripts/ ./scripts/ -{%- endif %} -{% if install_pip_requirements -%} -# Installs Python dependencies listed in requirements.txt -RUN `{{ pip_command }}` install -r ./scripts/requirements.txt -{%- endif %} - -# Setting ARGs and ENVs for Stable-Diffusion-WebUI GitHub repository -ARG ARG_APP_SOURCE_REPO="`{{ app_source_repo }}`" -ARG ARG_APP_INSTALL_ROOT="`{{ app_install_root }}`" -ARG ARG_APP_CLONE_DIRNAME="`{{ app_clone_dirname }}`" -ARG ARG_APP_SOURCE_BRANCH="`{{ app_source_branch }}`" -ARG ARG_APP_SERVICE_NAME="`{{ app_service_name }}`" -ENV APP_SOURCE_REPO $ARG_APP_SOURCE_REPO -ENV APP_INSTALL_ROOT $ARG_APP_INSTALL_ROOT -ENV APP_CLONE_DIRNAME $ARG_APP_CLONE_DIRNAME -ENV APP_SOURCE_BRANCH $ARG_APP_SOURCE_BRANCH -ENV APP_SERVICE_NAME $ARG_APP_SERVICE_NAME - # Specifies the command that will be executed when the container is run CMD ["bash"] diff --git a/.copier-template/.docker/{% if build_images_from_dockerfile %}Dockerfile.base{% endif %}.jinja b/.copier-template/.docker/{% if build_images_from_dockerfile %}Dockerfile.base{% endif %}.jinja index 4fc1970..7c6dcb5 100644 --- a/.copier-template/.docker/{% if build_images_from_dockerfile %}Dockerfile.base{% endif %}.jinja +++ b/.copier-template/.docker/{% if build_images_from_dockerfile %}Dockerfile.base{% endif %}.jinja @@ -100,8 +100,10 @@ RUN sudo rm -rf $WORKSPACE_ROOT && sudo mkdir -p $WORKSPACE_ROOT RUN sudo chown -R $USERNAME:$USERNAME $WORKSPACE_ROOT RUN sh -c "$(wget -qO- https://dotfiles.entelecheia.ai/install)" -RUN sudo chown -R $USERNAME:$USERNAME $WORKSPACE_ROOT +USER root {%- endif %} +RUN chown -R $USERNAME:$USERNAME $WORKSPACE_ROOT + # Specifies the command that will be executed when the container is run CMD ["bash"] diff --git a/tmp/.copier-docker-config.yaml b/tmp/.copier-docker-config.yaml index 06a27b3..e8c84a5 100644 --- a/tmp/.copier-docker-config.yaml +++ b/tmp/.copier-docker-config.yaml @@ -1,5 +1,5 @@ # Changes here will be overwritten by Copier; do NOT edit manually -_commit: v0.22.1-7-gc101bef +_commit: v0.22.1-10-g60d98aa _src_path: . app_clone_dirname: entelecheia/entelecheia app_install_root: /workspace/projects @@ -7,7 +7,7 @@ app_service_name: app app_source_branch: main app_source_repo: entelecheia/entelecheia author: Young Joon Lee -build_images_from_dockerfile: false +build_images_from_dockerfile: true clone_source_code: true container_workspace_root: /workspace copy_scripts_dir: true @@ -30,7 +30,7 @@ enable_nvidia_gpu: true friendly_name: Hyperfast Docker Template github_repo_name: hyperfast-docker-template github_username: entelecheia -install_dotfiles: true +install_dotfiles: false install_pip_requirements: true jupyter_host_port: 18888 jupyter_port: 8585 diff --git a/tmp/.docker/Dockerfile.app b/tmp/.docker/Dockerfile.app new file mode 100644 index 0000000..80cd829 --- /dev/null +++ b/tmp/.docker/Dockerfile.app @@ -0,0 +1,67 @@ +# Sets the base image for subsequent instructions +ARG ARG_BUILD_FROM="ghcr.io/entelecheia/hyperfast-docker:latest-base" +FROM $ARG_BUILD_FROM + +# Setting ARGs and ENVs for user creation and workspace setup +ARG ARG_USERNAME="app" +ARG ARG_USER_UID=9001 +ARG ARG_USER_GID=$ARG_USER_UID +ARG ARG_WORKSPACE_ROOT="/workspace" +ENV USERNAME $ARG_USERNAME +ENV USER_UID $ARG_USER_UID +ENV USER_GID $ARG_USER_GID +ENV WORKSPACE_ROOT $ARG_WORKSPACE_ROOT + +# Creates a non-root user with sudo privileges +USER root +# check if user exists and if not, create user +RUN if id -u $USERNAME >/dev/null 2>&1; then \ + echo "User exists"; \ + else \ + groupadd --gid $USER_GID $USERNAME && \ + adduser --uid $USER_UID --gid $USER_GID --force-badname --disabled-password --gecos "" $USERNAME && \ + echo "$USERNAME:$USERNAME" | chpasswd && \ + adduser $USERNAME sudo && \ + echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers && \ + echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/$USERNAME && \ + chmod 0440 /etc/sudoers.d/$USERNAME; \ + fi + +# Switches to the newly created user +USER $USERNAME +# Sets up the workspace for the user +RUN sudo rm -rf $WORKSPACE_ROOT && sudo mkdir -p $WORKSPACE_ROOT/projects +RUN sudo chown -R $USERNAME:$USERNAME $WORKSPACE_ROOT + +# Adds .local/bin to PATH +ENV PATH="/home/$USERNAME/.local/bin:${PATH}" +# Sets Python environment variables +ENV PIP_DEFAULT_TIMEOUT 100 +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 +# Sets the time zone within the container +ENV TZ="Asia/Seoul" + + + +# Sets the working directory to workspace root +WORKDIR $WORKSPACE_ROOT +# Copies scripts from host into the image +COPY ./.docker/scripts/ ./scripts/ +# Installs Python dependencies listed in requirements.txt +RUN pip3 install -r ./scripts/requirements.txt + +# Setting ARGs and ENVs for Stable-Diffusion-WebUI GitHub repository +ARG ARG_APP_SOURCE_REPO="entelecheia/entelecheia" +ARG ARG_APP_INSTALL_ROOT="/workspace/projects" +ARG ARG_APP_CLONE_DIRNAME="entelecheia/entelecheia" +ARG ARG_APP_SOURCE_BRANCH="main" +ARG ARG_APP_SERVICE_NAME="app" +ENV APP_SOURCE_REPO $ARG_APP_SOURCE_REPO +ENV APP_INSTALL_ROOT $ARG_APP_INSTALL_ROOT +ENV APP_CLONE_DIRNAME $ARG_APP_CLONE_DIRNAME +ENV APP_SOURCE_BRANCH $ARG_APP_SOURCE_BRANCH +ENV APP_SERVICE_NAME $ARG_APP_SERVICE_NAME + +# Specifies the command that will be executed when the container is run +CMD ["bash"] diff --git a/tmp/.docker/Dockerfile.base b/tmp/.docker/Dockerfile.base new file mode 100644 index 0000000..8f7324b --- /dev/null +++ b/tmp/.docker/Dockerfile.base @@ -0,0 +1,72 @@ +# Sets the base image for subsequent instructions +ARG ARG_BUILD_FROM="python:3.9-slim-bookworm" +FROM $ARG_BUILD_FROM + +# Sets labels for the image +LABEL org.opencontainers.image.source="https://github.com/entelecheia/hyperfast-docker-template" +LABEL org.opencontainers.image.description="Hyperfast Docker Template is a powerful tool that leverages copier to streamline the creation of new Docker projects. It simplifies and accelerates Docker configurations, fostering a highly efficient and user-friendly development experience." +LABEL org.opencontainers.image.licenses="MIT" + +# Setting this argument prevents interactive prompts during the build process +ARG DEBIAN_FRONTEND=noninteractive +# Updates the image and installs necessary packages +RUN apt-get update --fix-missing \ + && apt-get install -y curl wget jq sudo \ + # !! Without python3-launchpadlib, software-properties-common fails to install + python3-launchpadlib software-properties-common \ + locales locales-all fontconfig fonts-nanum \ + tzdata openssh-server \ + # Adds PPA for the latest git version + && add-apt-repository ppa:git-core/ppa -y \ + && apt-get update \ + && apt-get -y install --no-install-recommends git \ + # Cleans up unnecessary packages to reduce image size + && apt-get autoremove -y \ + && apt-get clean -y + +# Installs the latest pip and setuptools from PyPI +RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py \ + && python3 get-pip.py \ + && rm get-pip.py +# Sets Python environment variables +ENV PIP_DEFAULT_TIMEOUT 100 +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +# Sets the working directory to workspace root +ARG ARG_WORKSPACE_ROOT="/workspace" +ENV WORKSPACE_ROOT $ARG_WORKSPACE_ROOT +# Sets up the workspace for the user +RUN rm -rf $WORKSPACE_ROOT && mkdir -p $WORKSPACE_ROOT/projects +WORKDIR $WORKSPACE_ROOT +# Copies scripts from host into the image +COPY ./.docker/scripts/ ./scripts/ +RUN if [ -f ./scripts/requirements-base.txt ]; then pip3 install -r ./scripts/requirements-base.txt; fi + +# Sets the time zone within the container +ENV TZ="Asia/Seoul" +# Sets up the locale to en_US.UTF-8 +RUN localedef -v -c -i en_US -f UTF-8 en_US.UTF-8 || true + +# Setting ARGs and ENVs for user creation and workspace setup +ARG ARG_USERNAME="app" +ARG ARG_USER_UID=9001 +ARG ARG_USER_GID=$ARG_USER_UID +ENV USERNAME $ARG_USERNAME +ENV USER_UID $ARG_USER_UID +ENV USER_GID $ARG_USER_GID + +# Creates a non-root user with sudo privileges +RUN groupadd --gid $USER_GID $USERNAME \ + && adduser --uid $USER_UID --gid $USER_GID --force-badname --disabled-password --gecos "" $USERNAME \ + && echo "$USERNAME:$USERNAME" | chpasswd \ + && adduser $USERNAME sudo \ + && echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers \ + && echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/$USERNAME \ + && chmod 0440 /etc/sudoers.d/$USERNAME + + + + +# Specifies the command that will be executed when the container is run +CMD ["bash"] diff --git a/tmp/.docker/docker-compose.app.yaml b/tmp/.docker/docker-compose.app.yaml index 54badc6..53d452f 100644 --- a/tmp/.docker/docker-compose.app.yaml +++ b/tmp/.docker/docker-compose.app.yaml @@ -63,11 +63,6 @@ services: volumes: # Maps directories from the host to the container - "$PWD/.docker/scripts:$CONTAINER_WORKSPACE_ROOT/scripts" - - "$WORKSPACE_ROOT:$CONTAINER_WORKSPACE_ROOT" - - "$HOME/.cache:/home/$USERNAME/.cache" - - "$HOME/.ssh:/home/$USERNAME/.ssh" - - "$HOME/.config/gh:/home/$USERNAME/.config/gh" - - "$HOME/.passage:/home/$USERNAME/.passage" deploy: resources: reservations: diff --git a/tmp/.docker/docker-compose.base.yaml b/tmp/.docker/docker-compose.base.yaml new file mode 100644 index 0000000..e89ca14 --- /dev/null +++ b/tmp/.docker/docker-compose.base.yaml @@ -0,0 +1,36 @@ +version: "3" + +services: + # Defines a service name + workspace: + build: + # Sets the build context to the current directory + context: . + # Specifies the Dockerfile to use for the build + dockerfile: .docker/Dockerfile.base + # Specifies build-time variables (ARGs) + args: + ARG_BUILD_FROM: $BUILD_FROM + ARG_USERNAME: $CONTAINER_USERNAME + ARG_USER_UID: $CONTAINER_USER_UID + ARG_USER_GID: $CONTAINER_USER_GID + ARG_WORKSPACE_ROOT: $CONTAINER_WORKSPACE_ROOT + ARG_WORKSPACE_LOCATION: $CONTAINER_WORKSPACE_LOCATION + ARG_SYSTEM_HOSTNAME: $CONTAINER_HOSTNAME + # Sets the image name for the built image + image: $IMAGE_NAME:$IMAGE_TAG + # Sets the hostname of the container + hostname: $CONTAINER_HOSTNAME + command: + # Specifies the command to be executed when the container is run + - $CONTAINER_RUN_COMMAND + ulimits: + # Sets the stack size and memory lock limits + stack: 67108864 + memlock: -1 + ipc: $CONTAINER_IPC +networks: + default: + # Sets the name of the default network and makes it external + name: $CONTAINER_NETWORK_NAME + external: true diff --git a/tmp/.docker/docker.base.env b/tmp/.docker/docker.base.env new file mode 100644 index 0000000..9ad00cb --- /dev/null +++ b/tmp/.docker/docker.base.env @@ -0,0 +1,9 @@ +####################################################################################### +# Please do not make any changes below this line if you don't know what you are doing # +# change the variables above to your need # +####################################################################################### +# docker build: Configuration parameters for building the Docker image +BASE_VARIANT=${BASE_VARIANT:-"base"} # The variant of the Docker image. +IMAGE_TAG="${IMAGE_VERSION}-${BASE_VARIANT}" # The tag of the Docker image +IMAGE_NAME="${CONTAINER_REGISTRY}/${DOCKER_USERNAME}/${DOCKER_PROJECT_NAME}" # The full name of the Docker image +BUILD_FROM="python:3.9-slim-bookworm" # The base image for the Docker build