diff --git a/bun.lockb b/bun.lockb index 0cb9afc..e90ad26 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/docker-compose.yaml b/docker-compose.yml similarity index 91% rename from docker-compose.yaml rename to docker-compose.yml index 5a548c1..66c0d37 100644 --- a/docker-compose.yaml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ services: image: postgres restart: always ports: - - 5432:5432 + - ${POSTGRES_PORT}:5432 environment: PGUSER: ${POSTGRES_USER} POSTGRES_DB: ${POSTGRES_DB} @@ -19,4 +19,4 @@ services: env_file: - .env volumes: - pgdata: \ No newline at end of file + pgdata: diff --git a/package.json b/package.json index c46e590..83bd439 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "docs:dev": "vitepress dev docs", "docs:build": "vitepress build docs", "docs:preview": "vitepress preview docs", - "db:up": "docker-compose up -d", + "db:up": "./scripts/create-start-container-with-env.sh", "db:generate": "bun drizzle-kit generate:pg --config=db/config.ts", "db:migrate": "bun run db/migrations/migrate.ts", "db:push": "bun drizzle-kit push:pg --config=db/config.ts", diff --git a/scripts/create-start-container-with-env.sh b/scripts/create-start-container-with-env.sh new file mode 100755 index 0000000..1fe39d6 --- /dev/null +++ b/scripts/create-start-container-with-env.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# this script extends docker-compose up by supporting .env files in the same way as bun +# see: https://bun.sh/docs/runtime/env#setting-environment-variables + +# Default env file +env_file=".env" + +# Determine which env file to use based on NODE_ENV +if [ "$NODE_ENV" == "production" ]; then + env_file=".env.production" +elif [ "$NODE_ENV" == "development" ]; then + env_file=".env.development" +elif [ "$NODE_ENV" == "test" ]; then + env_file=".env.test" +fi + +# If .env.local exists, use that instead +if [ -f ".env.local" ]; then + env_file=".env.local" +fi + +# Run docker-compose with the selected env file and pass along any arguments +docker-compose --env-file $env_file up "$@"