{# This template needs to be included in compose.yml, which depend on a postgres database #} {% if lookup('database', application_id, 'local') %} {% set _extensions = lookup('service_extensions', 'postgres').get(application_id, []) %} {% set _libraries = lookup('postgres_libraries', _extensions) %} {{ lookup('database', application_id, 'host') }}: {{ lookup('container_deploy', replicas=1) | indent(4) }} {{ lookup('compose_only', 'container_name', ((application_id | get_entity_name) ~ '-database')) }} {% if _libraries | length > 0 %} {{ lookup('container_image', 'svc-db-postgres', 'postgres', image=(application_id | get_entity_name ~ '-database'), version=lookup('database', application_id, 'version')) }} {{ lookup('compose_only', 'pull_policy', 'never') }} build: context: {{ lookup('database', application_id, 'build_dir') }} dockerfile: Dockerfile {% else %} {{ lookup('container_image', 'svc-db-postgres', 'postgres', image=lookup('database', application_id, 'image'), version=lookup('database', application_id, 'version')) }} {% endif %} command: - "postgres" - "-c" - "max_locks_per_transaction={{ POSTGRES_MAX_LOCKS_PER_TRANSACTION }}" env_file: - {{ lookup('database', application_id, 'env') }} {{ lookup('compose_restart') }} healthcheck: test: ["CMD-SHELL", "pg_isready -h 127.0.0.1 -U {{ lookup('database', application_id, 'username') }}"] interval: 2m timeout: 5s retries: 6 start_period: 10m start_interval: 5s volumes: - type: volume source: database target: /var/lib/postgresql {% if _extensions | length > 0 %} - type: bind source: {{ lookup('database', application_id, 'initdb_dir') }} target: /docker-entrypoint-initdb.d read_only: true {% endif %} networks: # nocheck: networks-literal local sidecar inside consumer stack, default-only attachment - default {% endif %} {{ "\n" }}