Fakultas Ilmu Komputer UI

Commit d373d051 authored by hashlash's avatar hashlash
Browse files

[CHORES] change database environment

parent 3cb5b2f0
Pipeline #51486 passed with stages
in 4 minutes and 33 seconds
......@@ -8,19 +8,15 @@
## Environment
### Backend environment
File `.env`:
```
SECRET_KEY=foobarbarfoo
ALLOWED_HOSTS=*
DEBUG=1
SQL_DATABASE=sizakat
SQL_USER=postgres
SQL_PASSWORD=postgres
SQL_HOST=db
SQL_PORT=5432
POSTGRES_DB=sizakat
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
BACKEND_PORT=8000
```
......@@ -36,22 +32,12 @@ BACKEND_PORT=8000
https://docs.djangoproject.com/en/3.0/ref/settings/#debug
- `SQL_*`
- `POSTGRES_*`
Pengaturan untuk database
https://github.com/docker-library/docs/tree/master/postgres#environment-variables
- `BACKEND_PORT`
Port untuk service backend. Digunakan dalam `docker-compose`
### Database environment
File `.db.env`
```
POSTGRES_DB=sizakat
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
```
https://github.com/docker-library/docs/tree/master/postgres#environment-variables
......@@ -11,6 +11,7 @@ services:
- staticfiles:/var/www/html/static/
depends_on:
- backend
backend:
build:
context: ./
......@@ -21,15 +22,19 @@ services:
- staticfiles:/app/backend/staticfiles/
env_file:
- .env
environment:
POSTGRES_HOST: db
POSTGRES_PORT: 5432
depends_on:
- db
db:
image: postgres:12.0-alpine
restart: always
volumes:
- postgres_data:/var/lib/postgresql/data/
env_file:
- .db.env
- .env
volumes:
postgres_data:
......
......@@ -91,15 +91,15 @@ DATABASES = {
}
}
if 'SQL_DATABASE' in os.environ:
if 'POSTGRES_DB' in os.environ:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.environ.get('SQL_DATABASE'),
'USER': os.environ.get('SQL_USER'),
'PASSWORD': os.environ.get('SQL_PASSWORD'),
'HOST': os.environ.get('SQL_HOST'),
'PORT': os.environ.get('SQL_PORT'),
'NAME': os.environ.get('POSTGRES_DB'),
'USER': os.environ.get('POSTGRES_USER'),
'PASSWORD': os.environ.get('POSTGRES_PASSWORD'),
'HOST': os.environ.get('POSTGRES_HOST'),
'PORT': os.environ.get('POSTGRES_PORT'),
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment