Skip to content

Commit

Permalink
Merge pull request #87 from entelecheia/entelecheia/issue82
Browse files Browse the repository at this point in the history
  • Loading branch information
entelecheia authored Oct 9, 2023
2 parents db7eead + 5a6df61 commit b107f93
Show file tree
Hide file tree
Showing 12 changed files with 240 additions and 48 deletions.
2 changes: 0 additions & 2 deletions .copier-template/.docker/docker.app.env.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
Expand Down
10 changes: 10 additions & 0 deletions .copier-template/.docker/docker.common.env.jinja
Original file line number Diff line number Diff line change
@@ -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 #
#######################################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"; \
Expand All @@ -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
Expand Down Expand Up @@ -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"]
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
6 changes: 3 additions & 3 deletions tmp/.copier-docker-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# 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
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
Expand All @@ -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
Expand Down
67 changes: 67 additions & 0 deletions tmp/.docker/Dockerfile.app
Original file line number Diff line number Diff line change
@@ -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"]
72 changes: 72 additions & 0 deletions tmp/.docker/Dockerfile.base
Original file line number Diff line number Diff line change
@@ -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"]
5 changes: 0 additions & 5 deletions tmp/.docker/docker-compose.app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
36 changes: 36 additions & 0 deletions tmp/.docker/docker-compose.base.yaml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions tmp/.docker/docker.base.env
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b107f93

Please sign in to comment.