forked from pycontw/pycon.tw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enter_dev_env.sh
executable file
·28 lines (24 loc) · 1.15 KB
/
enter_dev_env.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash -xe
CONTAINER="${USER}_pycontw_vm"
COMPOSE_FILE="./docker-compose-dev.yml"
# test if the container is running
HASH=`docker ps -q -f name=$CONTAINER`
# test if the container is stopped
HASH_STOPPED=`docker ps -qa -f name=$CONTAINER`
if [[ $(uname -m) == 'arm64' ]]; then
export DOCKER_DEFAULT_PLATFORM=linux/amd64
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"
elif [ -n "$HASH_STOPPED" ];then
echo "found existing stopped container $CONTAINER, starting"
docker-compose -f $COMPOSE_FILE restart
docker start --attach -i $HASH_STOPPED
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"
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"