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

feat: support bun-like .env hierarchy in docker compose #40

Merged
merged 2 commits into from
Sep 26, 2023
Merged
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
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions docker-compose.yaml → docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
image: postgres
restart: always
ports:
- 5432:5432
- ${POSTGRES_PORT}:5432
environment:
PGUSER: ${POSTGRES_USER}
POSTGRES_DB: ${POSTGRES_DB}
Expand All @@ -19,4 +19,4 @@ services:
env_file:
- .env
volumes:
pgdata:
pgdata:
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
24 changes: 24 additions & 0 deletions scripts/create-start-container-with-env.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
Loading