From 3d41a1f4d28706c6290e36ca467756942ca3dee5 Mon Sep 17 00:00:00 2001 From: Young Joon Lee Date: Tue, 15 Oct 2024 12:06:32 +0900 Subject: [PATCH] feat(docker): add support for restart policy and TTY options --- .copier-docker-config.yaml | 3 ++- ...age_variant_name }}`.yaml{% endif %}.jinja | 2 ++ .docker/docker-compose.base.yaml | 2 ++ copier.yaml | 5 +++++ tmp/.copier-docker-config.yaml | 3 ++- tmp/.docker/docker-compose.base.yaml | 2 ++ tmp/.docker/scripts/entrypoint.sh | 2 +- tmp/.docker/scripts/launch.sh | 19 ++++++++++--------- 8 files changed, 26 insertions(+), 12 deletions(-) diff --git a/.copier-docker-config.yaml b/.copier-docker-config.yaml index 997f9b6..503ab02 100644 --- a/.copier-docker-config.yaml +++ b/.copier-docker-config.yaml @@ -1,5 +1,5 @@ # Changes here will be overwritten by Copier; do NOT edit manually -_commit: v0.30.6-10-g90bb37e +_commit: v0.31.5-2-g927d89e _src_path: . app_dirname: entelecheia app_install_root: /opt @@ -67,6 +67,7 @@ project_short_description: Hyperfast Docker Template is a powerful tool that lev copier to streamline the creation of new Docker projects. It simplifies and accelerates Docker configurations, fostering a highly efficient and user-friendly development experience. +restart_always: true ssh_host_port: 2929 ssh_port: 22 use_deploy_workflows: true diff --git a/.copier-template/.docker/{% if build_images_from_dockerfile %}docker-compose.`{{ docker_image_variant_name }}`.yaml{% endif %}.jinja b/.copier-template/.docker/{% if build_images_from_dockerfile %}docker-compose.`{{ docker_image_variant_name }}`.yaml{% endif %}.jinja index b4d1be4..fa5492a 100644 --- a/.copier-template/.docker/{% if build_images_from_dockerfile %}docker-compose.`{{ docker_image_variant_name }}`.yaml{% endif %}.jinja +++ b/.copier-template/.docker/{% if build_images_from_dockerfile %}docker-compose.`{{ docker_image_variant_name }}`.yaml{% endif %}.jinja @@ -28,8 +28,10 @@ services: image: $IMAGE_NAME:$IMAGE_TAG # Sets the hostname of the container hostname: $CONTAINER_HOSTNAME + {% if restart_always %}restart: always{% endif %} # Sets tty to true if the container needs a pseudo-TTY tty: `{{ use_tty | lower }}` + {% if use_tty %}stdin_open: true{% endif %} {% if use_tty %}# {% endif %}command: {% if use_tty %}# {% endif %} # Specifies the command to be executed when the container is run {% if use_tty %}# {% endif %} - bash diff --git a/.docker/docker-compose.base.yaml b/.docker/docker-compose.base.yaml index 658bfb1..3014dbb 100644 --- a/.docker/docker-compose.base.yaml +++ b/.docker/docker-compose.base.yaml @@ -26,8 +26,10 @@ services: image: $IMAGE_NAME:$IMAGE_TAG # Sets the hostname of the container hostname: $CONTAINER_HOSTNAME + restart: always # Sets tty to true if the container needs a pseudo-TTY tty: false + command: # Specifies the command to be executed when the container is run - bash diff --git a/copier.yaml b/copier.yaml index 5783708..4df4a7d 100644 --- a/copier.yaml +++ b/copier.yaml @@ -213,6 +213,11 @@ use_tty: type: bool help: Do you want to enable tty (pseudo-terminal) when running the Docker container? +restart_always: + default: false + type: bool + help: Do you want to set restart policy to 'always' for the Docker container? + use_ssh_service: default: true type: bool diff --git a/tmp/.copier-docker-config.yaml b/tmp/.copier-docker-config.yaml index d022a0f..495d6fe 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.30.6-4-gd74e456 +_commit: v0.31.5-2-g7796203 _src_path: . app_dirname: entelecheia app_install_root: /workspace/projects @@ -67,6 +67,7 @@ project_short_description: Hyperfast Docker Template is a powerful tool that lev copier to streamline the creation of new Docker projects. It simplifies and accelerates Docker configurations, fostering a highly efficient and user-friendly development experience. +restart_always: false ssh_host_port: 2222 ssh_port: 22 use_deploy_workflows: true diff --git a/tmp/.docker/docker-compose.base.yaml b/tmp/.docker/docker-compose.base.yaml index 68ff63d..17a7470 100644 --- a/tmp/.docker/docker-compose.base.yaml +++ b/tmp/.docker/docker-compose.base.yaml @@ -20,8 +20,10 @@ services: image: $IMAGE_NAME:$IMAGE_TAG # Sets the hostname of the container hostname: $CONTAINER_HOSTNAME + # Sets tty to true if the container needs a pseudo-TTY tty: false + command: # Specifies the command to be executed when the container is run - bash diff --git a/tmp/.docker/scripts/entrypoint.sh b/tmp/.docker/scripts/entrypoint.sh index efa65b2..f448c17 100644 --- a/tmp/.docker/scripts/entrypoint.sh +++ b/tmp/.docker/scripts/entrypoint.sh @@ -31,7 +31,7 @@ if [ "$USER_UID" != "$LOCAL_UID" ]; then echo "Changing ownership of $APP_INSTALL_ROOT directory to $USER_UID:$USER_UID" chown -R "$USER_UID:$USER_UID" "$APP_INSTALL_ROOT" fi - if [ -n "$WORKSPACE_ROOT" ] && [ -d "$WORKSPACE_ROOT" ]; then + if [ -n "$WORKSPACE_ROOT" ] && [ -d "$WORKSPACE_ROOT" ] && [ "$WORKSPACE_ROOT" != "$APP_INSTALL_ROOT" ]; then echo "Changing ownership of workspace directory [$WORKSPACE_ROOT] to $USER_UID:$USER_UID" chown -R "$USER_UID:$USER_UID" "$WORKSPACE_ROOT" fi diff --git a/tmp/.docker/scripts/launch.sh b/tmp/.docker/scripts/launch.sh index 398fade..34c3eb1 100644 --- a/tmp/.docker/scripts/launch.sh +++ b/tmp/.docker/scripts/launch.sh @@ -30,13 +30,14 @@ service ssh start # set token to value of JUPYTER_TOKEN # set port to value of JUPYTER_DOCKER_PORT if [[ -z "$(command -v jupyter)" ]]; then - echo "Jupyter not installed. Exiting..." - exit 1 + echo "Jupyter not installed." +else + echo "Starting Jupyter Lab..." + jupyter lab \ + --no-browser \ + --notebook-dir="$WORKSPACE_ROOT" \ + --ServerApp.token="$JUPYTER_TOKEN" \ + --port="$JUPYTER_PORT" \ + --ip=0.0.0.0 \ + --allow-root fi -exec gosu "${USER}" jupyter lab \ - --no-browser \ - --notebook-dir="$WORKSPACE_ROOT" \ - --ServerApp.token="$JUPYTER_TOKEN" \ - --port="$JUPYTER_PORT" \ - --ip=0.0.0.0 \ - --allow-root