aboutsummaryrefslogtreecommitdiff
path: root/cluster/prod/app/postgres/deploy/postgres.hcl
blob: c043d70acf22629e742a97f08d213d0ce02f6ef1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
job "postgres14" {
  datacenters = ["orion", "neptune", "bespin", "scorpio"]
  type = "system"
  priority = 90

  update {
    max_parallel = 1
    min_healthy_time  = "2m"
    healthy_deadline  = "5m"
    auto_revert = true
  }

  group "postgres" {
    network {
      port "psql_proxy_port" { static = 5432 }
      port "psql_port" { static = 5433 }
    }

    constraint {
      attribute = "${attr.unique.hostname}"
      operator = "set_contains_any"
	  # target: courgette,df-ymf,abricot (or ananas)
      value = "courgette,concombre,df-ymf,abricot"
    }

    restart {
      interval = "10m"
      attempts = 10
      delay    = "15s"
      mode     = "delay"
    }

    task "sentinel" {
      driver = "docker"

      config {
        image = "superboum/amd64_postgres:v11"
        network_mode = "host" 
        readonly_rootfs = false
        command = "/usr/local/bin/stolon-sentinel"
        args = [
          "--cluster-name", "chelidoine",
          "--store-backend", "consul",
          "--store-endpoints", "https://consul.service.prod.consul:8501",
          "--store-ca-file", "/certs/consul-ca.crt",
          "--store-cert-file", "/certs/consul-client.crt",
          "--store-key", "/certs/consul-client.key",
        ]
        volumes = [
          "secrets/certs:/certs",
        ]
      }
      resources {
        memory = 20
        memory_max = 100
      }

      template {
        data = "{{ key \"secrets/consul/consul-ca.crt\" }}"
        destination = "secrets/certs/consul-ca.crt"
      }
      template {
        data = "{{ key \"secrets/consul/consul-client.crt\" }}"
        destination = "secrets/certs/consul-client.crt"
      }
      template {
        data = "{{ key \"secrets/consul/consul-client.key\" }}"
        destination = "secrets/certs/consul-client.key"
      }
    }

    task "proxy" {
      driver = "docker"

      config {
        image = "superboum/amd64_postgres:v11"
        network_mode = "host" 
        readonly_rootfs = false
        command = "/usr/local/bin/stolon-proxy"
        args = [
          "--cluster-name", "chelidoine",
          "--store-backend", "consul",
          "--store-endpoints", "https://consul.service.prod.consul:8501",
          "--store-ca-file", "/certs/consul-ca.crt",
          "--store-cert-file", "/certs/consul-client.crt",
          "--store-key", "/certs/consul-client.key",
          "--port", "${NOMAD_PORT_psql_proxy_port}",
          "--listen-address", "0.0.0.0",
          "--log-level", "info"
        ]
        volumes = [
          "secrets/certs:/certs",
        ]
        ports = [ "psql_proxy_port" ]
      }

      resources {
        memory = 20
        memory_max = 100
      }

      template {
        data = "{{ key \"secrets/consul/consul-ca.crt\" }}"
        destination = "secrets/certs/consul-ca.crt"
      }
      template {
        data = "{{ key \"secrets/consul/consul-client.crt\" }}"
        destination = "secrets/certs/consul-client.crt"
      }
      template {
        data = "{{ key \"secrets/consul/consul-client.key\" }}"
        destination = "secrets/certs/consul-client.key"
      }

      service {
        tags = ["sql", "${meta.site}"]
        port = "psql_proxy_port"
        address_mode = "host"
        name = "psql-proxy"
        check {
          type = "tcp"
          port = "psql_proxy_port"
          interval = "60s"
          timeout = "5s"
          check_restart {
            limit = 3
            grace = "10m"
            ignore_warnings = false
          }
        }
      }
    }

    task "keeper" {
      driver = "docker"

      config {
        image = "superboum/amd64_postgres:v11"
        network_mode = "host" 
        readonly_rootfs = false
        command = "/usr/local/bin/stolon-keeper"
        args = [
          "--cluster-name", "chelidoine",
          "--store-backend", "consul",
          "--store-endpoints", "https://consul.service.prod.consul:8501",
          "--store-ca-file", "/certs/consul-ca.crt",
          "--store-cert-file", "/certs/consul-client.crt",
          "--store-key", "/certs/consul-client.key",
          "--data-dir", "/mnt/persist",
          "--pg-su-password", "${PG_SU_PWD}",
          "--pg-repl-username", "${PG_REPL_USER}",
          "--pg-repl-password", "${PG_REPL_PWD}",
          /*
	   The postgres daemon accepts 0.0.0.0, ::, and * here but not Stolon.
           Otherwise you will have the following error and your cluster will be broken (no replication)
           WARN	cmd/keeper.go:1979	provided --pg-listen-address "*": is not an ip address but a hostname. This will be advertized to the other components and may have undefined behaviors if resolved differently by other hosts
           WARN	cmd/keeper.go:1984	cannot resolve provided --pg-listen-address "*": lookup *: no such host
          */
          "--pg-listen-address", "${attr.unique.network.ip-address}",
          "--pg-port", "${NOMAD_PORT_psql_port}",
          "--pg-bin-path", "/usr/lib/postgresql/14/bin/"
        ]
        ports = [ "psql_port" ]
        volumes = [
          "/mnt/ssd/postgres:/mnt/persist",
          "/mnt/storage/postgres_extended:/mnt/slow",
          "secrets/certs:/certs"
        ]
      }

      template {
        data = file("../config/keeper/env.tpl")
        destination = "secrets/env"
        env = true
      }

      template {
        data = "{{ key \"secrets/consul/consul-ca.crt\" }}"
        destination = "secrets/certs/consul-ca.crt"
      }
      template {
        data = "{{ key \"secrets/consul/consul-client.crt\" }}"
        destination = "secrets/certs/consul-client.crt"
      }
      template {
        data = "{{ key \"secrets/consul/consul-client.key\" }}"
        destination = "secrets/certs/consul-client.key"
      }

      resources {
        memory = 400
        memory_max = 600
      }

      service {
        tags = ["sql", "${meta.site}"]
        port = "psql_port"
        address_mode = "host"
        name = "psql-keeper"
        check {
          type = "tcp"
          port = "psql_port"
          interval = "60s"
          timeout = "5s"
        }
      }
    }
  }
}