compose.yaml.j2 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. services:
  2. {{ service_name }}:
  3. image: docker.io/library/postgres:17.6
  4. {% if not swarm_enabled %}
  5. restart: {{ restart_policy }}
  6. container_name: {{ container_name }}
  7. {% endif %}
  8. hostname: {{ container_hostname }}
  9. environment:
  10. - POSTGRES_INITDB_ARGS={{ postgres_initdb_args }}
  11. {% if postgres_host_auth_method %}
  12. - POSTGRES_HOST_AUTH_METHOD={{ postgres_host_auth_method }}
  13. {% endif %}
  14. - POSTGRES_USER={{ database_user }}
  15. {% if postgres_secrets_enabled %}
  16. - POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password
  17. {% else %}
  18. - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
  19. {% endif %}
  20. - POSTGRES_DB={{ database_name }}
  21. - TZ={{ container_timezone }}
  22. {% if network_mode == 'host' %}
  23. network_mode: host
  24. {% else %}
  25. networks:
  26. {% if network_mode == 'macvlan' %}
  27. {{ network_name }}:
  28. ipv4_address: {{ network_macvlan_ipv4_address }}
  29. {% elif network_mode == 'bridge' %}
  30. {{ network_name }}:
  31. {% endif %}
  32. {% endif %}
  33. {% if network_mode == 'bridge' %}
  34. ports:
  35. {% if swarm_enabled %}
  36. - target: 5432
  37. published: {{ database_port }}
  38. protocol: tcp
  39. mode: host
  40. {% else %}
  41. - "{{ database_port }}:5432"
  42. {% endif %}
  43. {% endif %}
  44. volumes:
  45. - postgres_data:/var/lib/postgresql/data
  46. {% if postgres_secrets_enabled %}
  47. secrets:
  48. - postgres_password
  49. {% endif %}
  50. healthcheck:
  51. test: ["CMD-SHELL", "pg_isready -U {{ database_user }}"]
  52. start_period: 30s
  53. interval: 10s
  54. timeout: 10s
  55. retries: 5
  56. {% if swarm_enabled %}
  57. deploy:
  58. replicas: 1
  59. {% endif %}
  60. {% if postgres_secrets_enabled %}
  61. secrets:
  62. postgres_password:
  63. file: secret.postgres_password.txt
  64. {% endif %}
  65. volumes:
  66. postgres_data:
  67. driver: local
  68. networks:
  69. {% if network_mode == 'macvlan' %}
  70. {{ network_name }}:
  71. driver: macvlan
  72. driver_opts:
  73. parent: {{ network_macvlan_parent_interface }}
  74. ipam:
  75. config:
  76. - subnet: {{ network_macvlan_subnet }}
  77. gateway: {{ network_macvlan_gateway }}
  78. {% elif network_mode == 'bridge' %}
  79. {{ network_name }}:
  80. driver: {% if swarm_enabled %}overlay{% else %}bridge{% endif %}
  81. {% endif %}