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: leverage .env file #42

Merged
merged 3 commits into from
Feb 18, 2024
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
11 changes: 10 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
DATABASE_URL=postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public
PORT=3000
SALT="this is a very insecure salt, change it"

DB_NAME=mydb
DB_PROVIDER=postgres
DB_HOST=db # db refers to the name of the service in docker-compose.yml
DB_USER=johndoe
DB_PASSWORD=randompassword

# do not modify. copy as-is. dotenv-expand will replace the variables
DATABASE_URL=${DB_PROVIDER}://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:5432?schema=public

MAIL_ENABLED=false
MAIL_SERVER=smtp.gmail.com
MAIL_PORT=465
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ Right now, my instance is using PostgreSQL on Vercel. However, it can be run usi

### .env Configuration

`DATABASE_URL` needs to point to a running SQL database. It uses PostgreSQL by default, but can be changed to MySQL or SQLite by modifying the provider in [schema.prisma](src/lib/server/prisma/schema.prisma).
- `DB_NAME` is the database name;
- `DB_PROVIDER` uses 'postgres' by default, but can be changed to MySQL or SQLite.
- `DB_HOST` database host (defaults to 'db', but can be changed to aything like localhost)
- `DB_USER` database user
- `DB_PORT` database port 5432
- `DB_PASSWORD` the database user password
- `DATABASE_URL` you don't need to modify this variable (thanks to dotenv-expand). keep it though!

Remember to modify `SALT` to something secure if you plan on using user accounts.

Expand Down
31 changes: 21 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
version: '3.3'
networks:
yabin-network:
name: yabin-network
ipam:
driver: default
services:
yabin:
container_name: yabin
ports:
- '3000:3000'
- '${PORT:-3000}:${PORT:-3000}'
image: 'yureien/yabin:latest'
environment:
- DATABASE_URL=postgresql://user:pass@db:5432/yabin?schema=public
env_file: .env
depends_on:
- db
networks:
- yabin-network
db:
container_name: yabin-db
restart: always
image: postgres:15-alpine
env_file: .env
expose:
- '5432'
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: yabin
POSTGRES_USER: ${DB_USER:-yabin_user}
POSTGRES_PASSWORD: ${DB_USER_PASS:-123}
POSTGRES_DB: ${DB_NAME:-yabin_db}
POSTGRES_HOST_AUTH_METHOD: "trust"
volumes:
- db_data:/var/lib/postgresql/data:Z
restart: always
volumes:
db_data: {}
- ./db-data:/var/lib/postgresql/data
networks:
- yabin-network
2 changes: 1 addition & 1 deletion src/lib/server/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ generator client {
}

datasource db {
provider = "postgresql"
provider = env("DB_PROVIDER")
url = env("DATABASE_URL")
}

Expand Down
Loading