Skip to content

Commit

Permalink
fix(dev): fix attach behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwang44 committed Apr 18, 2024
1 parent 3fba085 commit 921ce51
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions enter_dev_env.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"

0 comments on commit 921ce51

Please sign in to comment.