Skip to content

Commit

Permalink
feat: initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
entelecheia committed May 18, 2023
1 parent 287f76b commit daa5516
Show file tree
Hide file tree
Showing 45 changed files with 1,798 additions and 1 deletion.
58 changes: 58 additions & 0 deletions .copier-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Changes here will be overwritten by Copier; do NOT edit manually
_commit: v0.4.28
_src_path: gh:entelecheia/hyperfast-python-template
author: Young Joon Lee
build_and_release: false
code_template_answers_file: .copier-hyfi-config.yaml
code_template_source: null
copyright_year: 2023
documentaion_tool: mkdocs
documentation_url: https://hyperfast-docker.entelecheia.ai
email: entelecheia@hotmail.com
favicon_path: https://assets.entelecheia.ai/favicon.png
friendly_name: Hyperfast Docker Template
github_repo_name: hyperfast-docker-template
github_username: entelecheia
google_analytics_id: G-0K77490FJT
logo_path: https://assets.entelecheia.ai/logo.png
package_name: hfdk
project_description: 'Hyperfast Docker Template is an innovative project creation
tool that merges the flexibility of Docker with the simplicity of Copier to optimize
the project creation process. This tool allows developers to quickly and efficiently
set up Docker projects, thereby significantly reducing the time and effort traditionally
associated with this process.
By harnessing the power of Copier, Hyperfast Docker Template provides a user-friendly
interface that developers can utilize to duplicate Docker projects with minimal
hassle. It eradicates the need for extensive coding knowledge, making Docker more
accessible to a wider range of users.
Furthermore, this tool employs a hyperfast approach to Docker project templating,
ensuring that new projects are up and running in the quickest time possible. This
speed does not compromise the quality or functionality of the Docker projects
created, but instead enhances their performance, reliability, and scalability.
Hyperfast Docker Template also ensures consistency across Docker projects, as
the use of a template guarantees that all projects conform to a standardized layout
and configuration. This, in turn, enhances the overall workflow, as developers
can familiarize themselves with a consistent project structure and configuration,
leading to increased productivity and efficiency.
Whether you''re an experienced developer or a novice just starting out, Hyperfast
Docker Template is the ideal tool to fast-track your Docker project creation process,
ensuring a seamless, efficient, and highly productive development experience.'
project_license: MIT
project_name: hyperfast-docker-template
project_short_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.
upload_to_release: false
upload_to_repository: false
use_launch_buttons: false
use_source_code_skeleton: false

112 changes: 112 additions & 0 deletions .copier-template/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# To do stuff with make, you type `make` in a directory that has a file called
# "Makefile". You can also type `make -f <makefile>` to use a different filename.
#
# A Makefile is a collection of rules. Each rule is a recipe to do a specific
# thing, sort of like a grunt task or an npm package.json script.
#
# A rule looks like this:
#
# <target>: <prerequisites...>
# <commands>
#
# The "target" is required. The prerequisites are optional, and the commands
# are also optional, but you have to have one or the other.
#
# Type `make` to show the available targets and a description of each.
#
.DEFAULT_GOAL := help
.PHONY: help
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)


##@ Clean-up

clean: ## run all clean commands
@poe clean

##@ Git Branches

show-branches: ## show all branches
@git show-branch --list

dev-checkout: ## checkout the dev branch
@branch=$(shell echo $${branch:-"dev"}) && \
git show-branch --list | grep -q $${branch} && \
git checkout $${branch}

dev-checkout-upstream: ## create and checkout the dev branch, and set the upstream
@branch=$(shell echo $${branch:-"dev"}) && \
git checkout -B $${branch} && \
git push --set-upstream origin $${branch} || true

main-checkout: ## checkout the main branch
@git checkout main

##@ Utilities

large-files: ## show the 20 largest files in the repo
@find . -printf '%s %p\n'| sort -nr | head -20

disk-usage: ## show the disk usage of the repo
@du -h -d 2 .

git-sizer: ## run git-sizer
@git-sizer --verbose

gc-prune: ## garbage collect and prune
@git gc --prune=now

##@ Setup

install-node: ## install node
@export NVM_DIR="$${HOME}/.nvm"; \
[ -s "$${NVM_DIR}/nvm.sh" ] && . "$${NVM_DIR}/nvm.sh"; \
nvm install --lts

nvm-ls: ## list node versions
@export NVM_DIR="$${HOME}/.nvm"; \
[ -s "$${NVM_DIR}/nvm.sh" ] && . "$${NVM_DIR}/nvm.sh"; \
nvm ls

set-default-node: ## set default node
@export NVM_DIR="$${HOME}/.nvm"; \
[ -s "$${NVM_DIR}/nvm.sh" ] && . "$${NVM_DIR}/nvm.sh"; \
nvm alias default node

install-pipx: ## install pipx (pre-requisite for external tools)
@command -v pipx &> /dev/null || pip install --user pipx || true

install-copier: install-pipx ## install copier (pre-requisite for init-project)
@command -v copier &> /dev/null || pipx install copier || true

install-poetry: install-pipx ## install poetry (pre-requisite for install)
@command -v poetry &> /dev/null || pipx install poetry || true

install-poe: install-pipx ## install poetry (pre-requisite for install)
@command -v poe &> /dev/null || pipx install poethepoet || true

install-commitzen: install-pipx ## install commitzen (pre-requisite for commit)
@command -v cz &> /dev/null || pipx install commitizen || true

install-precommit: install-pipx ## install pre-commit
@command -v pre-commit &> /dev/null || pipx install pre-commit || true

install-precommit-hooks: install-precommit ## install pre-commit hooks
@pre-commit install

initialize: install-pipx ## initialize the project environment
@pipx install copier
@pipx install poethepoet
@pipx install commitizen
@pipx install pre-commit
@pre-commit install

init-project: initialize ## initialize the project (Warning: do this only once!)
@copier --answers-file .copier-config.yaml --vcs-ref=HEAD gh:entelecheia/hyperfast-python-template .

reinit-project: install-copier ## reinitialize the project (Warning: this may overwrite existing files!)
@bash -c 'args=(); while IFS= read -r file; do args+=("--skip" "$$file"); done < .copierignore; copier "$${args[@]}" --answers-file .copier-config.yaml --vcs-ref=HEAD . .'

reinit-project-force: install-copier ## initialize the project ignoring existing files (Warning: this will overwrite existing files!)
@bash -c 'args=(); while IFS= read -r file; do args+=("--skip" "$$file"); done < .copierignore; copier "$${args[@]}" --answers-file .copier-config.yaml --force --vcs-ref=HEAD . .'
66 changes: 66 additions & 0 deletions .copier-template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Hyperfast Docker Template

This repository provides Docker setup instructions to install and run Stable-Diffusion-WebUI. It uses NVIDIA's PyTorch container as a base image and includes several additional packages necessary for Stable-Diffusion-WebUI.

## Prerequisites

- Docker
- Docker Compose
- NVIDIA Docker (for GPU support)

## Setup

1. Clone the repository and navigate to the directory.

2. Export the environment variables and build the Docker image:

```
set -a; source .docker/docker.env; set +a; docker-compose --project-directory . -f .docker/docker-compose.yaml build
```

The `docker.env` file includes various configuration options and environment variables. Feel free to adjust them to suit your needs. For instance, you may want to change the default NVIDIA Docker image in the `BUILD_FROM` variable, or the port mapping in `SDW_HOST_SSH_PORT` and `SDW_HOST_GRADIO_PORT`.

The `set -a; source .docker/docker.env; set +a;` sequence of commands exports the environment variables in the `.docker/docker.env` file to the shell environment, making them available to the subsequent `docker-compose` command. This method allows us to use shell commands in the variable definitions, like `"$(whoami)"` for the `USERNAME` variable. We're using this approach instead of the `--env-file` argument because we need these environment variables to be available to the `docker-compose` command itself, not just to the services defined in the `docker-compose.yml` file.

3. Start the Docker container:

```
set -a; source .docker/docker.env; set +a; docker-compose --project-directory . -f .docker/docker-compose.yaml up
```

This will start a Docker container with the image built in the previous step. The container will run a bash command (`webui.sh`) specified in the `command` section of the `docker-compose.yml` file.

## Usage

After starting the container, you can access the Stable-Diffusion-WebUI at `localhost:<SDW_HOST_GRADIO_PORT>`. By default, the port is set to `18860`.

You can also SSH into the container using the SSH port specified in `SDW_HOST_SSH_PORT`. By default, the port is set to `2722`.

## Volumes

The `docker-compose.yml` file specifies several volumes that bind mount directories on the host to directories in the container. These include the Hugging Face cache and data directories, the workspace directory, and a scripts directory. Changes made in these directories will persist across container restarts.

## Troubleshooting

If you encounter any issues with this setup, please check the following:

- Make sure Docker and Docker Compose are installed correctly.
- Make sure NVIDIA Docker is installed if you're planning to use GPU acceleration.
- Ensure the environment variables in the `docker.env` file are correctly set.
- Check the Docker and Docker Compose logs for any error messages.

## Environment Variables

The `set -a; source .docker/docker.env; set +a;` sequence of commands in the setup steps exports the environment variables in the `.docker/docker.env` file to the shell environment, making them available to the subsequent `docker-compose` command.

In Docker, environment variables can be used in the `docker-compose.yml` file to customize the behavior of the services. This is a common practice when you want to set different configurations for development, testing, and production environments.

The `docker-compose` command has an `--env-file` argument, but it's used to set the environment variables for the services defined in the `docker-compose.yml` file, not for the `docker-compose` command itself. The variables defined in the `--env-file` will not be substituted into the `docker-compose.yml` file.

However, the environment variables we set in the `.docker/docker.env` file are used in the `docker-compose.yml` file. For example, the `$BUILD_FROM` variable is used to set the base image for the Docker build. Therefore, we need to export these variables to the shell environment before running the `docker-compose` command.

This method also allows us to use shell commands in the variable definitions, like `"$(whoami)"` for the `USERNAME` variable, which wouldn't be possible if we used the `--env-file` argument. Shell commands in the `.env` file are not evaluated.

## Contributing

Contributions to improve this setup are welcome. Please feel free to submit a pull request or open an issue on the GitHub repository.
2 changes: 2 additions & 0 deletions .copier-template/{{ _copier_conf.answers_file }}.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Changes here will be overwritten by Copier; do NOT edit manually
{{ _copier_answers|to_nice_yaml }}
4 changes: 4 additions & 0 deletions .copierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.copierignore
.tasks-extra.toml
CHANGELOG.md
pyproject.toml
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[html]
directory = tests/htmlcov
3 changes: 3 additions & 0 deletions .docker/.docker-scripts/docker-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
# add your custom commands here that should be executed when building the docker image
echo "Building docker image..."
5 changes: 5 additions & 0 deletions .docker/.docker-scripts/docker-init-dotfiles.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
# this script should be executed only once when the docker container is created
chezmoi update --apply=false
chezmoi init --apply --verbose
dotu
14 changes: 14 additions & 0 deletions .docker/.docker-scripts/docker-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
# add your custom commands here that should be executed every time the docker container starts
echo "Starting docker container..."

# start ssh server
sudo service ssh start
# start jupyter lab
jupyter lab \
--no-browser \
--notebook-dir="$WORKSPACE_ROOT" \
--ServerApp.token="$JUPYTER_TOKEN" \
--port="$JUPYTER_PORT" \
--ip=0.0.0.0 \
--allow-root
Empty file.
17 changes: 17 additions & 0 deletions .docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.virtual_documents
jupyterhub*
.vscode
.history
workspace
notebooks
.workspace
data
refs
tmp
_tmp_
logs
outputs
runs
.env*
!.env.project
!.env.vault
85 changes: 85 additions & 0 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
ARG ARG_BUILD_FROM="nvcr.io/nvidia/pytorch:23.04-py3"
FROM $ARG_BUILD_FROM

ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Seoul

RUN apt-get update && apt-get upgrade -y \
&& apt-get install -y fontconfig fonts-nanum curl git tzdata locales locales-all \
libcairo2-dev imagemagick ffmpeg sudo software-properties-common openssh-server \
&& add-apt-repository ppa:git-core/ppa -y \
&& apt-get update \
&& apt-get -y install --no-install-recommends git \
&& apt-get autoremove -y \
&& apt-get clean -y

# Set up locale
RUN localedef -v -c -i en_US -f UTF-8 en_US.UTF-8 || true
# fix sudo setrlimit(RLIMIT_CORE) error
RUN echo "Set disable_coredump false" > /etc/sudo.conf

# Add a non-root user to a container
ARG ARG_USERNAME="dev"
ARG ARG_USER_UID=1000
ARG ARG_USER_GID=$ARG_USER_UID
ARG ARG_USER_FULLNAME="Dev User"
ARG ARG_USER_EMAIL="dev@domain.com"
ARG ARG_GITHUB_USERNAME=""
ARG ARG_SYSTEM_HOSTNAME="dev-container"
ARG ARG_WORKSPACE_LOCATION="/"
ARG ARG_WORKSPACE_ROOT="/workspace"

ENV USERNAME $ARG_USERNAME
ENV USER_UID $ARG_USER_UID
ENV USER_GID $ARG_USER_GID
ENV USER_FULLNAME $ARG_USER_FULLNAME
ENV USER_EMAIL $ARG_USER_EMAIL
ENV GITHUB_USERNAME $ARG_GITHUB_USERNAME
ENV SYSTEM_HOSTNAME $ARG_SYSTEM_HOSTNAME
ENV WORKSPACE_LOCATION $ARG_WORKSPACE_LOCATION
ENV WORKSPACE_ROOT $ARG_WORKSPACE_ROOT
# print all args to check
RUN echo "USERNAME: $USERNAME from $ARG_USERNAME"
RUN echo "USER_UID: $USER_UID from $ARG_USER_UID"
RUN echo "USER_GID: $USER_GID from $ARG_USER_GID"
RUN echo "USER_FULLNAME: $USER_FULLNAME from $ARG_USER_FULLNAME"
RUN echo "USER_EMAIL: $USER_EMAIL from $ARG_USER_EMAIL"
RUN echo "GITHUB_USERNAME: $GITHUB_USERNAME from $ARG_GITHUB_USERNAME"
RUN echo "SYSTEM_HOSTNAME: $SYSTEM_HOSTNAME from $ARG_SYSTEM_HOSTNAME"
RUN echo "WORKSPACE_LOCATION: $WORKSPACE_LOCATION from $ARG_WORKSPACE_LOCATION"
RUN echo "WORKSPACE_ROOT: $WORKSPACE_ROOT from $ARG_WORKSPACE_ROOT"

# Create the user
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

# install dotfiles
ENV DOTFILES_APPLY_ROOTMOI=0
ENV DOTFILES_USE_CODE=1
ENV DOTFILES_USE_PYTHON_TOOLS=1
ENV REMOTE_CONTAINERS=1
# ENV DOTFILES_DEBUG=1

ENV PIP_DEFAULT_TIMEOUT 100
ENV DS_BUILD_FUSED_ADAM 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV KMP_DUPLICATE_LIB_OK TRUE

USER $USERNAME
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)"

# set workdir to user home
WORKDIR /home/$USERNAME
COPY ./.docker/scripts/ ./scripts/
RUN sudo chmod 755 ./scripts/devenv-entrypoint.sh

WORKDIR $WORKSPACE_ROOT
CMD ["zsh"]
Loading

0 comments on commit daa5516

Please sign in to comment.