-
Notifications
You must be signed in to change notification settings - Fork 1
/
postgresql12-patroni-consul.pkr.hcl
127 lines (102 loc) · 3.52 KB
/
postgresql12-patroni-consul.pkr.hcl
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
variable "triton_url" {
type = string
}
variable "triton_account" {
type = string
}
variable "triton_key_id" {
type = string
}
variable "image_version" {
type = string
}
locals {
consul_version="1.10.1"
}
packer {
required_plugins {
triton = {
version = ">= 1.0.0"
source = "github.com/hashicorp/triton"
}
}
}
source "triton" "postgresql12-patroni-consul" {
image_name = "postgresql12-patroni-consul"
image_version = "${var.image_version}"
source_machine_image_filter {
most_recent = "true"
name = "base-64-lts"
type = "zone-dataset"
}
source_machine_name = "image_builder_${uuidv4()}"
source_machine_package = "k1-highcpu-512m"
ssh_username = "root"
triton_url = var.triton_url
triton_account = var.triton_account
triton_key_id = var.triton_key_id
}
build {
sources = ["source.triton.postgresql12-patroni-consul"]
provisioner "file" {
source = "${path.root}/smf_manifests/consul.xml"
destination = "/opt/consul.xml"
}
provisioner "file" {
source = "${path.root}/smf_manifests/patroni.xml"
destination = "/opt/patroni.xml"
}
provisioner "shell" {
inline = [
"pkgin -y update",
"pkgin -y install postgresql12-server",
# Install (but don't enable") consul.
"mkdir -p /opt/local/etc/consul.d/certificates",
"mkdir -p /opt/local/consul",
"useradd -d /opt/local/consul consul",
"groupadd consul",
"chown consul /opt/local/consul",
"chgrp consul /opt/local/consul",
"pkgin -y in wget unzip",
"cd /tmp ; wget --no-check-certificate https://releases.hashicorp.com/consul/${local.consul_version}/consul_${local.consul_version}_solaris_amd64.zip",
"cd /tmp ; unzip consul_${local.consul_version}_solaris_amd64.zip",
"cd /tmp ; rm consul_${local.consul_version}_solaris_amd64.zip",
"mv /tmp/consul /opt/local/bin/consul",
"svccfg import /opt/consul.xml",
# GCC 9 (required for Patroni)
"pkgin -y install gcc9",
# Psycopg2
"pkgin -y install py38-psycopg2",
# PIP
"python3.8 -m ensurepip --upgrade",
"python3.8 -m pip install --upgrade pip",
# Patroni
"pip3 install patroni[consul]",
# Postgresql sets up its own database - we delete it here so patroni has full control
"rm -rf /var/pgsql/data/*",
# Build postgresql by hand and install it over the top of the package version.
# This is done because the packaged version builds with Kerberos support which
# core dumps when running under Patroni.
"pkgin -y install gmake",
"wget https://ftp.postgresql.org/pub/source/v12.8/postgresql-12.8.tar.bz2 -O /tmp/postgresql-12.8.tar.bz2",
"tar xjvf /tmp/postgresql-12.8.tar.bz2 -C /root",
"mkdir -p /tmp/pgsql",
"cd /tmp/pgsql ; /root/postgresql-12.8/configure --prefix=/opt/local/",
"gmake -C /tmp/pgsql install",
"rm -rf /root/postgresql-12.8",
# Install the patroni service xml
"svccfg import /opt/patroni.xml",
# Build and install pgbackrest
"pkgin -y install git",
"pkgin -y install pkg-config",
"pkgin -y install libyaml",
"git clone https://github.com/CoolpeopleNetworks/pgbackrest.git /tmp/pgbackrest -b illumos_fixes",
"cd /tmp/pgbackrest/src && LIBS=-lsocket ./configure --prefix=/opt/local",
"cd /tmp/pgbackrest/src && LIBS=-lsocket make install",
]
}
provisioner "file" {
source = "${path.root}/postgresql12-patroni/patroni.yml"
destination = "/var/pgsql/patroni.yml"
}
}