Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dev): update the way it attach to the dev container #1192

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
version: "3"

services:
db:
container_name: db_dev
image: postgres:11-alpine
environment:
- POSTGRES_DB=pycontw2016
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=secretpostgres
ports:
- ${COMPOSE_DB_PORT:-5432}:5432
pycontw:
container_name: pycontw_dev

app-dev:
build:
context: .
dockerfile: dev.Dockerfile
Expand Down
21 changes: 11 additions & 10 deletions enter_dev_env.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
#!/bin/bash -xe
CONTAINER="${USER}_pycontw_vm"
CONTAINER="app-dev"
PROJECT_NAME="pycontw_backend_dev"
COMPOSE_FILE="./docker-compose-dev.yml"
COMPOSE_CMD="docker compose -f $COMPOSE_FILE -p ${PROJECT_NAME}"

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

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

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"
$COMPOSE_CMD 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
($COMPOSE_CMD restart && docker start $HASH_STOPPED) >/dev/null 2>&1
$COMPOSE_CMD 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"
$COMPOSE_CMD up --build --remove-orphans -d
$COMPOSE_CMD 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"
echo "see you, use '$COMPOSE_CMD down' to kill both the postgres and the dev container if you want a fresh env next time"
Loading