From b141bd02c03d6ec2f6b70e0b65b571ebcfa49a91 Mon Sep 17 00:00:00 2001 From: Joshua Schlichting <7680545+JoshuaSchlichting@users.noreply.github.com> Date: Wed, 28 Aug 2024 18:12:18 -0400 Subject: [PATCH] 0.1.0 add run, run -d, stop --- README.md | 3 +++ jo.sh | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8fae142..81e016e 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,9 @@ Use `jo.sh` in lieu of `virtualenv`, `venv,` `pyenv`, or any of the others; *Pyt ``` Usage: ./jo.sh [COMMAND] [OPTIONS] Commands: + run: Launch a stateless interactive shell with Python and Poetry installed + --detach, -d: Run the container in the background + stop: Stop the container if running build: Build the container --poetry-install: Install the dependencies in the pyproject.toml file into the image --no-cache: Do not use cached layers of user specific content (poetry packages, Dockerfile commands from /Users/josh/.config/josh/dockerfile_commands) diff --git a/jo.sh b/jo.sh index f156069..8414343 100755 --- a/jo.sh +++ b/jo.sh @@ -108,7 +108,39 @@ echo "Image and container name (based on \$pwd): $CONTAINER_NAME" echo Default Docker image: $PYTHON_VERSION echo "Use '$0 help' for more information" set -e -if [ "$1" = "build" ]; then +if [ "$1" = "run" ]; then + DETACH_FLAG="" + while [ $# -gt 0 ]; do + case $1 in + --detach|-d) + DETACH_FLAG="-d" + DETACH_DETAILS="-c \"tail -f /dev/null\"" + echo "Running in detached mode" + shift + ;; + *) + shift + ;; + esac + done + if [ -z "$DETACH_FLAG" ]; then + DETACH_FLAG="-it" + fi + docker run \ + $DETACH_FLAG \ + --entrypoint /bin/bash \ + --rm \ + --name $CONTAINER_NAME \ + --volume $(pwd):/app \ + --platform linux/amd64 \ + -w /app \ + -v $HOME/.aws:/root/.aws \ + $CONTAINER_NAME $DETACH_DETAILS + +elif [ "$1" = "stop" ]; then + echo Stopping container \"$CONTAINER_NAME\"... + docker container stop $CONTAINER_NAME +elif [ "$1" = "build" ]; then POETRY_INSTALL="" POETRY_FILES="" NO_CACHE="" @@ -245,6 +277,9 @@ elif [[ "$1" == *.py ]]; then elif [[ "$1" == *help ]]; then echo "Usage: $0 [COMMAND] [OPTIONS]" echo "Commands:" + echo " run: Launch a stateless interactive shell with Python and Poetry installed" + echo " --detach, -d: Run the container in the background" + echo " stop: Stop the container if running" echo " build: Build the container" echo " --poetry-install: Install the dependencies in the pyproject.toml file into the image" echo " --no-cache: Do not use cached layers of user specific content (poetry packages, Dockerfile commands from $CONFIG_DOCKER_COMMANDS_FILE)"