Set up auth + corrected local db

This commit is contained in:
2024-11-09 18:41:41 -06:00
parent cb2e59e07e
commit 9c318b4451
6 changed files with 81 additions and 43 deletions

View File

@@ -9,41 +9,38 @@
# On Linux and macOS you can run this script directly - `./start-database.sh`
DB_CONTAINER_NAME="ls-postgres"
COMPOSE_FILE="docker-compose.yml"
DB_CONTAINER_NAME="lf-postgres"
COMPOSE_SERVICE_NAME="postgres"
if ! [ -x "$(command -v docker)" ]; then
echo -e "Docker is not installed. Please install docker and try again.\nDocker install guide: https://docs.docker.com/engine/install/"
if ! [ -x "$(command -v docker-compose)" ]; then
echo -e "Docker Compose is not installed. Please install Docker Compose and try again.\nDocker Compose install guide: https://docs.docker.com/compose/install/"
exit 1
fi
if ! docker info > /dev/null 2>&1; then
echo "Docker daemon is not running. Please start Docker and try again."
exit 1
fi
if [ "$(docker ps -q -f name=$DB_CONTAINER_NAME)" ]; then
echo "Database container '$DB_CONTAINER_NAME' already running"
if [ "$(docker-compose -f $COMPOSE_FILE ps -q $COMPOSE_SERVICE_NAME)" ]; then
echo "Database container '$DB_CONTAINER_NAME' already running via Docker Compose"
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"
# Check if the service exists but is not running
if [ "$(docker-compose -f $COMPOSE_FILE ps -a -q $COMPOSE_SERVICE_NAME)" ] && [ ! "$(docker-compose -f $COMPOSE_FILE ps -q $COMPOSE_SERVICE_NAME)" ]; then
docker-compose -f $COMPOSE_FILE start $COMPOSE_SERVICE_NAME
echo "Existing database container '$DB_CONTAINER_NAME' started via Docker Compose"
exit 0
fi
# import env variables from .env
# Import env variables from .env
set -a
source .env
DB_PASSWORD=$(echo "$DATABASE_URL" | awk -F':' '{print $3}' | awk -F'@' '{print $1}')
DB_PORT=$(echo "$DATABASE_URL" | awk -F':' '{print $4}' | awk -F'\/' '{print $1}')
DB_PASSWORD=$(echo "$POSTGRES_URL" | awk -F':' '{print $3}' | awk -F'@' '{print $1}')
if [ "$DB_PASSWORD" = "password" ]; then
echo "You are using the default database password"
read -p "Should we generate a random password for you? [y/N]: " -r REPLY
if ! [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Please change the default password in the .env file and try again"
echo "Please set a password in the .env file and try again"
exit 1
fi
# Generate a random URL-safe password
@@ -51,10 +48,7 @@ if [ "$DB_PASSWORD" = "password" ]; then
sed -i -e "s#:password@#:$DB_PASSWORD@#" .env
fi
docker run -d \
--name $DB_CONTAINER_NAME \
-e POSTGRES_USER="postgres" \
-e POSTGRES_PASSWORD="$DB_PASSWORD" \
-e POSTGRES_DB=d__dev_ls \
-p "$DB_PORT":5432 \
docker.io/postgres && echo "Database container '$DB_CONTAINER_NAME' was successfully created"
# Update the environment variables in the Docker Compose file if necessary
# Assuming environment variables in the docker-compose.yml file match those in .env
docker-compose -f $COMPOSE_FILE up -d && echo "Database and proxy services were successfully created via Docker Compose"