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

Docker postgres pg_cron fix #447

Closed
wants to merge 2 commits into from
Closed
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ venv/
ENV/
env.bak/
venv.bak/
.env_docker
env_docker/
env_docker.bak/

# Spyder project settings
.spyderproject
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ services:
- redis

postgres:
image: postgres:15.3-alpine
build:
context: docker/postgres
dockerfile: dockerfile
container_name: postgres
restart: always
environment:
Expand Down
7 changes: 7 additions & 0 deletions docker/postgres/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM postgres:15.3
RUN apt-get update && apt-get install -y postgresql-15-cron

RUN echo "shared_preload_libraries='pg_cron'" >> /usr/share/postgresql/postgresql.conf.sample
RUN echo "cron.database_name='postgres'" >> /usr/share/postgresql/postgresql.conf.sample

COPY init-db /docker-entrypoint-initdb.d
19 changes: 19 additions & 0 deletions docker/postgres/init-db/002-pg-cron.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

# use same db as the one from env
dbname="postgres"

# create custom config
customconf=/var/lib/postgresql/data/custom-conf.conf
echo "" > $customconf
echo "shared_preload_libraries = 'pg_cron'" >> $customconf
echo "cron.database_name = '$dbname'" >> $customconf
chown postgres $customconf
chgrp postgres $customconf

# include custom config from main config
conf=/var/lib/postgresql/data/postgresql.conf
found=$(grep "include = '$customconf'" $conf)
if [ -z "$found" ]; then
echo "include = '$customconf'" >> $conf
fi
1 change: 1 addition & 0 deletions docker/postgres/init-db/003-main.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE EXTENSION pg_cron;