Skip to content

Commit 7341b7d

Browse files
committed
refactor(dev): update var name and adopt compose v2
1 parent 1d45e4e commit 7341b7d

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

docker-compose-dev.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
services:
22
db:
3-
container_name: db_dev
43
image: postgres:11-alpine
54
environment:
65
- POSTGRES_DB=pycontw2016
76
- POSTGRES_USER=postgres
87
- POSTGRES_PASSWORD=secretpostgres
98
ports:
109
- ${COMPOSE_DB_PORT:-5432}:5432
11-
pycontw:
12-
container_name: pycontw_dev
10+
11+
app-dev:
1312
build:
1413
context: .
1514
dockerfile: dev.Dockerfile

enter_dev_env.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
#!/bin/bash -xe
2-
CONTAINER="pycontw"
2+
CONTAINER="app-dev"
3+
PROJECT_NAME="pycontw_backend_dev"
34
COMPOSE_FILE="./docker-compose-dev.yml"
5+
COMPOSE_CMD="docker compose -f $COMPOSE_FILE -p ${PROJECT_NAME}"
46

57
# test if the container is running
6-
HASH=`docker ps -q -f name=$CONTAINER`
8+
HASH=`docker ps -q -f name="${PROJECT_NAME}-${CONTAINER}-1"`
79

810
# test if the container is stopped
9-
HASH_STOPPED=`docker ps -qa -f name=$CONTAINER`
11+
HASH_STOPPED=`docker ps -qa -f name="${PROJECT_NAME}-${CONTAINER}-1"`
1012

1113
if [[ $(uname -m) == 'arm64' ]]; then
1214
export DOCKER_DEFAULT_PLATFORM=linux/amd64
1315
fi
1416

1517
if [ -n "$HASH" ];then
1618
echo "found existing running container $CONTAINER, proceeding to exec another shell"
17-
docker-compose -f $COMPOSE_FILE exec -i $CONTAINER bash -c "SHELL=bash source /app/.venv/bin/activate && bash"
19+
$COMPOSE_CMD exec -i $CONTAINER bash -c "SHELL=bash source /app/.venv/bin/activate && bash"
1820
elif [ -n "$HASH_STOPPED" ];then
1921
echo "found existing stopped container $CONTAINER, starting"
20-
(docker-compose -f $COMPOSE_FILE restart && docker start $HASH_STOPPED) >/dev/null 2>&1
21-
docker-compose -f $COMPOSE_FILE exec -i $CONTAINER bash -c "SHELL=bash source /app/.venv/bin/activate && bash"
22+
($COMPOSE_CMD restart && docker start $HASH_STOPPED) >/dev/null 2>&1
23+
$COMPOSE_CMD exec -i $CONTAINER bash -c "SHELL=bash source /app/.venv/bin/activate && bash"
2224
else
2325
echo "existing container not found, creating a new one, named $CONTAINER"
24-
docker-compose -f $COMPOSE_FILE up --build --remove-orphans -d
25-
docker-compose -f $COMPOSE_FILE exec -i $CONTAINER bash -c "SHELL=bash source /app/.venv/bin/activate && bash"
26+
$COMPOSE_CMD up --build --remove-orphans -d
27+
$COMPOSE_CMD exec -i $CONTAINER bash -c "SHELL=bash source /app/.venv/bin/activate && bash"
2628
fi
27-
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"
29+
echo "see you, use '$COMPOSE_CMD down' to kill both the postgres and the dev container if you want a fresh env next time"

0 commit comments

Comments
 (0)