compose.yaml 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. ---
  2. kind: "compose"
  3. metadata:
  4. name: "PostgreSQL"
  5. description: "An open-source relational database management system"
  6. version: "0.0.1"
  7. date: "2023-10-01"
  8. author: "Christian Lempa"
  9. tags:
  10. - postgres
  11. - database
  12. - sql
  13. spec:
  14. postgres:
  15. vars:
  16. postgres_initdb_args:
  17. description: "PostgreSQL initdb arguments"
  18. type: str
  19. default: "--data-checksums"
  20. postgres_host_auth_method:
  21. description: "PostgreSQL host authentication method"
  22. type: str
  23. default: ""
  24. postgres_secrets_enabled:
  25. description: "Use PostgreSQL secrets file for password"
  26. type: bool
  27. default: true
  28. ---
  29. services:
  30. {{ service_name | default('postgres') }}:
  31. image: docker.io/library/postgres:17.6
  32. container_name: {{ container_name | default('postgres') }}
  33. environment:
  34. - POSTGRES_INITDB_ARGS={{ postgres_initdb_args | default('--data-checksums') }}
  35. {% if postgres_host_auth_method -%}
  36. - POSTGRES_HOST_AUTH_METHOD={{ postgres_host_auth_method }}
  37. {% endif %}
  38. - POSTGRES_USER={{ database_user | default('postgres') }}
  39. {% if postgres_secrets_enabled -%}
  40. - POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password
  41. {% else -%}
  42. - POSTGRES_PASSWORD={{ database_password | default('postgres') }}
  43. {% endif %}
  44. - POSTGRES_DB={{ database_name | default('postgres') }}
  45. - TZ={{ container_timezone | default('UTC') }}
  46. {% if ports_enabled %}
  47. ports:
  48. - "{{ database_port | default(5432) }}:5432"
  49. {% endif %}
  50. healthcheck:
  51. test: ['CMD-SHELL', 'pg_isready -U "{{ database_user | default('postgres') }}"']
  52. start_period: 30s
  53. interval: 10s
  54. timeout: 10s
  55. retries: 5
  56. {% if network_enabled %}
  57. networks:
  58. - {{ network_name | default('bridge') }}
  59. {% endif %}
  60. {% if postgres_secrets_enabled %}
  61. secrets:
  62. - postgres_password
  63. {% endif %}
  64. volumes:
  65. - postgres_data:/var/lib/postgresql/data
  66. restart: {{ restart_policy | default('unless-stopped') }}
  67. {% if postgres_secrets_enabled %}
  68. secrets:
  69. postgres_password:
  70. file: secret.postgres_password.txt
  71. {% endif %}
  72. volumes:
  73. postgres_data:
  74. driver: local
  75. {% if network_enabled %}
  76. networks:
  77. {{ network_name | default('bridge') }}:
  78. {% if network_external %}
  79. external: true
  80. {% endif %}
  81. {% endif %}