Skip to content

Commit

Permalink
fix: improve start-databse scripts exit and messages
Browse files Browse the repository at this point in the history
  • Loading branch information
kasbah committed Apr 5, 2024
1 parent fedd7b3 commit 62d1f67
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
18 changes: 13 additions & 5 deletions cli/template/extras/start-database/mysql.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ if ! [ -x "$(command -v docker)" ]; then
fi

if [ "$(docker ps -q -f name=$DB_CONTAINER_NAME)" ]; then
docker start $DB_CONTAINER_NAME
echo "Database container started"
echo "Database container '$DB_CONTAINER_NAME' already running"
exit 0
fi

if [ "$(docker ps -q -a -f name=$DB_CONTAINER_NAME)" ]; then
docker start "$DB_CONTAINER_NAME"
echo "Existing database container '$DB_CONTAINER_NAME' started"
exit 0
fi

Expand All @@ -40,6 +45,9 @@ if [ "$DB_PASSWORD" == "password" ]; then
sed -i -e "s#:password@#:$DB_PASSWORD@#" .env
fi

docker run --name $DB_CONTAINER_NAME -e MYSQL_ROOT_PASSWORD=$DB_PASSWORD -e MYSQL_DATABASE=project1 -d -p 3306:3306 docker.io/mysql

echo "Database container was successfully created"
docker run -d \
--name $DB_CONTAINER_NAME \
-e MYSQL_ROOT_PASSWORD="$DB_PASSWORD" \
-e MYSQL_DATABASE=project1 \
-p 3306:3306 \
docker.io/mysql && echo "Database container '$DB_CONTAINER_NAME' was successfully created"
18 changes: 13 additions & 5 deletions cli/template/extras/start-database/postgres.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ if ! [ -x "$(command -v docker)" ]; then
fi

if [ "$(docker ps -q -f name=$DB_CONTAINER_NAME)" ]; then
docker start $DB_CONTAINER_NAME
echo "Database container started"
echo "Database container '$DB_CONTAINER_NAME' already running"
exit 0
fi

if [ "$(docker ps -q -a -f name=$DB_CONTAINER_NAME)" ]; then
docker start "$DB_CONTAINER_NAME"
echo "Existing database container '$DB_CONTAINER_NAME' started"
exit 0
fi

Expand All @@ -40,6 +45,9 @@ if [ "$DB_PASSWORD" = "password" ]; then
sed -i -e "s#:password@#:$DB_PASSWORD@#" .env
fi

docker run --name $DB_CONTAINER_NAME -e POSTGRES_PASSWORD=$DB_PASSWORD -e POSTGRES_DB=project1 -d -p 5432:5432 docker.io/postgres

echo "Database container was successfully created"
docker run -d \
--name $DB_CONTAINER_NAME \
-e POSTGRES_PASSWORD="$DB_PASSWORD" \
-e POSTGRES_DB=project1 \
-p 5432:5432 \
docker.io/postgres && echo "Database container '$DB_CONTAINER_NAME' was successfully created"

0 comments on commit 62d1f67

Please sign in to comment.