-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(dev): update var name and adopt compose v2
- Loading branch information
1 parent
921ce51
commit 8482a01
Showing
2 changed files
with
13 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,29 @@ | ||
#!/bin/bash -xe | ||
CONTAINER="pycontw" | ||
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 exec -i $CONTAINER bash -c "SHELL=bash source /app/.venv/bin/activate && bash" | ||
$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 $HASH_STOPPED) >/dev/null 2>&1 | ||
docker-compose -f $COMPOSE_FILE exec -i $CONTAINER bash -c "SHELL=bash source /app/.venv/bin/activate && bash" | ||
($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 up --build --remove-orphans -d | ||
docker-compose -f $COMPOSE_FILE exec -i $CONTAINER bash -c "SHELL=bash source /app/.venv/bin/activate && bash" | ||
$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" |