-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenter_dev_env.sh
executable file
·30 lines (26 loc) · 1.19 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
29
30
#! /bin/bash -xe
CONTAINER="${USER}_tfjs_demo"
COMPOSE_FILE="./docker-compose-dev.yml"
START_SHELL="sh"
# 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 [ -n "$HASH" ];then
echo "found existing running container $CONTAINER, proceeding to exec another shell"
# docker-compose -f $COMPOSE_FILE restart # for db container
docker exec -it $HASH $START_SHELL
elif [ -n "$HASH_STOPPED" ];then
echo "found existing stopped container $CONTAINER, starting"
# docker-compose -f $COMPOSE_FILE restart # for db container
docker start --attach -i $HASH_STOPPED
else
echo "existing container not found, creating a new one, named $CONTAINER"
# rm -rf node_modules
if [[ "$OSTYPE" == "darwin"* ]]; then
docker compose -f $COMPOSE_FILE run --service-ports --name=$CONTAINER app
else
docker-compose -f $COMPOSE_FILE run --service-ports --name=$CONTAINER app
fi
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"