infrastructure/ansible/plays/templates/macro/postgres.j2

38 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

2024-02-05 18:44:13 +01:00
{# https://github.com/prodrigestivill/docker-postgres-backup-local #}
{% macro postgres(name, user, pass, db, networks, schedule="@daily", version="15") %}
{{ name | mandatory | string }}:
image: postgres:{{ version | mandatory }}
restart: unless-stopped
environment:
- POSTGRES_USER={{ user | mandatory }}
- POSTGRES_DB={{ db | mandatory }}
- POSTGRES_PASSWORD={{ pass | mandatory }}
- POSTGRES_INITDB_ARGS=--encoding=UTF-8 --lc-collate=C --lc-ctype=C
networks: {{ networks | mandatory | list | union(["postgres"]) | sort }}
volumes:
- {{ name | string | lower }}_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready", "-U", "{{ user }}"]
interval: 10s
timeout: 5s
retries: 5
{{ name | mandatory | string }}_pgbackup:
image: prodrigestivill/postgres-backup-local:latest
restart: unless-stopped
volumes:
- "/opt/pgbackups/${COMPOSE_PROJECT_NAME}/:/backups:z"
networks:
- postgres
depends_on:
- {{ name | mandatory | string }}
environment:
- POSTGRES_HOST={{ name | mandatory | string }}
- POSTGRES_USER={{ user | mandatory }}
- POSTGRES_DB={{ db | mandatory }}
- POSTGRES_PASSWORD={{ pass | mandatory }}
- POSTGRES_EXTRA_OPTS=-Z6 --schema=public --blobs
2024-02-20 19:43:36 +01:00
- REMOVE_BEFORE=3 # keep 3 days of backups
2024-02-05 18:44:13 +01:00
- SCHEDULE={{ schedule | mandatory }}
{% endmacro %}