From 921ce51671d6050608eb7dfaf5e8b8510406f085 Mon Sep 17 00:00:00 2001 From: "Wei-Hsiang (Matt) Wang" Date: Thu, 18 Apr 2024 14:35:40 +0000 Subject: [PATCH] fix(dev): fix attach behavior --- enter_dev_env.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/enter_dev_env.sh b/enter_dev_env.sh index dd621f3ae..c13f6c6f5 100755 --- a/enter_dev_env.sh +++ b/enter_dev_env.sh @@ -1,5 +1,5 @@ #!/bin/bash -xe -CONTAINER="${USER}_pycontw_vm" +CONTAINER="pycontw" COMPOSE_FILE="./docker-compose-dev.yml" # test if the container is running @@ -14,15 +14,14 @@ fi if [ -n "$HASH" ];then echo "found existing running container $CONTAINER, proceeding to exec another shell" - docker-compose -f $COMPOSE_FILE restart - docker exec -w /app/src -it $HASH bash -c "SHELL=bash poetry shell" + docker-compose -f $COMPOSE_FILE exec -i $CONTAINER bash -c "SHELL=bash source /app/.venv/bin/activate && bash" elif [ -n "$HASH_STOPPED" ];then echo "found existing stopped container $CONTAINER, starting" - docker-compose -f $COMPOSE_FILE restart - docker start --attach -i $HASH_STOPPED + (docker-compose -f $COMPOSE_FILE restart && docker start $HASH_STOPPED) >/dev/null 2>&1 + docker-compose -f $COMPOSE_FILE exec -i $CONTAINER bash -c "SHELL=bash source /app/.venv/bin/activate && bash" else echo "existing container not found, creating a new one, named $CONTAINER" - docker-compose -f $COMPOSE_FILE pull - docker-compose -f $COMPOSE_FILE run -p 8000:8000 --name=$CONTAINER pycontw bash -c "SHELL=bash poetry shell" + docker-compose -f $COMPOSE_FILE up --build --remove-orphans -d + docker-compose -f $COMPOSE_FILE exec -i $CONTAINER bash -c "SHELL=bash source /app/.venv/bin/activate && bash" fi echo "see you, use 'docker rm $CONTAINER' to kill the dev container or 'docker-compose -f $COMPOSE_FILE down' to kill both the postgres and the dev container if you want a fresh env next time"