Skip to content

Commit

Permalink
add PostgreSQL in docker-compose deployments (mljar#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
pplonski committed Jul 11, 2022
1 parent c15b17d commit cb620c0
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 9 deletions.
20 changes: 19 additions & 1 deletion docker-compose-pro.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,25 @@ services:
EMAIL_HOST_PASSWORD: ${EMAIL_HOST_PASSWORD}
EMAIL_PORT: ${EMAIL_PORT}
DEFAULT_FROM_EMAIL: ${DEFAULT_FROM_EMAIL}
DJANGO_DB: postgresql
POSTGRES_HOST: db
POSTGRES_NAME: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_PORT: 5432
depends_on:
- db
db:
image: postgres:13.0-alpine
restart: unless-stopped
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres

volumes:
static_volume: {}
media_volume: {}
media_volume: {}
postgres_data: {}
21 changes: 20 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ services:
EMAIL_HOST_PASSWORD: ${EMAIL_HOST_PASSWORD}
EMAIL_PORT: ${EMAIL_PORT}
DEFAULT_FROM_EMAIL: ${DEFAULT_FROM_EMAIL}
DJANGO_DB: postgresql
POSTGRES_HOST: db
POSTGRES_NAME: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_PORT: 5432
depends_on:
- db
db:
image: postgres:13.0-alpine
restart: unless-stopped
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres

volumes:
static_volume: {}
media_volume: {}
media_volume: {}
postgres_data: {}
4 changes: 3 additions & 1 deletion docker/mercury/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ RUN apt-get update && \
libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 \
libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 \
lsb-release xdg-utils wget libcairo-gobject2 libxinerama1 libgtk2.0-0 libpangoft2-1.0-0 libthai0 libpixman-1-0 \
libxcb-render0 libharfbuzz0b libdatrie1 libgraphite2-3 libgbm1
libxcb-render0 libharfbuzz0b libdatrie1 libgraphite2-3 libgbm1 \
libpq-dev


WORKDIR /app
Expand All @@ -19,6 +20,7 @@ ADD ./mercury/requirements.txt /app/mercury/
RUN pip install --upgrade pip
RUN pip install gunicorn
RUN pip install -r mercury/requirements.txt
RUN pip install psycopg2

# install Pro features if GITHUB_TOKEN is set
RUN if [ -z "${GITHUB_TOKEN}" ] ; then \
Expand Down
3 changes: 0 additions & 3 deletions docker/mercury/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ do
echo "Waiting for server volume..."
done

# clear old data dbs
rm *.sqlite
rm *.sqlite3

until python manage.py migrate
do
Expand Down
19 changes: 16 additions & 3 deletions mercury/server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,26 @@
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
"default": {
DB_SQLITE = "sqlite"
DB_POSTGRESQL = "postgresql"

DATABASES_ALL = {
DB_SQLITE: {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
},
DB_POSTGRESQL: {
"ENGINE": "django.db.backends.postgresql",
"HOST": os.environ.get("POSTGRES_HOST", "localhost"),
"NAME": os.environ.get("POSTGRES_NAME", "postgres"),
"USER": os.environ.get("POSTGRES_USER", "postgres"),
"PASSWORD": os.environ.get("POSTGRES_PASSWORD", "postgres"),
"PORT": int(os.environ.get("POSTGRES_PORT", "5432")),
},
}

DATABASES = {"default": DATABASES_ALL[os.environ.get("DJANGO_DB", DB_SQLITE)]}


# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
Expand Down

0 comments on commit cb620c0

Please sign in to comment.