-
Notifications
You must be signed in to change notification settings - Fork 374
Expand file tree
/
Copy pathpostgres.yml
More file actions
173 lines (166 loc) · 6.51 KB
/
postgres.yml
File metadata and controls
173 lines (166 loc) · 6.51 KB
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
# Comes from example at
# https://github.com/controlplane-com/examples/blob/main/examples/postgres/manifest.yaml
kind: volumeset
name: postgres-poc-vs
description: postgres-poc-vs
spec:
autoscaling:
maxCapacity: 1000
minFreePercentage: 1
scalingFactor: 1.1
fileSystemType: ext4
initialCapacity: 10
performanceClass: general-purpose-ssd
snapshots:
createFinalSnapshot: true
retentionDuration: 7d
---
kind: secret
name: postgres-poc-credentials
description: ''
type: dictionary
data:
password: the_password #Replace this with a real password
username: the_user #Replace this with a real username
---
kind: secret
name: postgres-poc-entrypoint-script
type: opaque
data:
encoding: base64
payload: >-
IyEvdXNyL2Jpbi9lbnYgYmFzaAoKc291cmNlIC91c3IvbG9jYWwvYmluL2RvY2tlci1lbnRyeXBvaW50LnNoCgppbnN0YWxsX2RlcHMoKSB7CiAgYXB0LWdldCB1cGRhdGUgLXkgPiAvZGV2L251bGwKICBhcHQtZ2V0IGluc3RhbGwgY3VybCAteSA+IC9kZXYvbnVsbAogIGFwdC1nZXQgaW5zdGFsbCB1bnppcCAteSA+IC9kZXYvbnVsbAogIGN1cmwgImh0dHBz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JDEiIC1VICIkUE9TVEdSRVNfVVNFUiIKCSAgZWNobyAiJChkYXRlKTogJDIgLT4gJDEiIHwgY2F0ID4+ICIkUEdEQVRBL0NQTE5fUkVTVE9SRUQiCgllbHNlCgkgIGVjaG8gIkRiICckMScgYWxyZWFkeSBleGlzdHMuIFJlYWR5ISIKICBmaQp9CgpfbWFpbiAiJEAiICYKYmFja2dyb3VuZFByb2Nlc3M9JCEKCmlmIFsgLW4gIiRQT1NUR1JFU19BUkNISVZFX1VSSSIgXTsgdGhlbgogIHJlc3RvcmVfZGIgIiRQT1NUR1JFU19EQiIgIiRQT1NUR1JFU19BUkNISVZFX1VSSSIKZWxzZQogIGVjaG8gIkRlY2xpbmluZyB0byByZXN0b3JlIHRoZSBkYiBiZWNhdXNlIG5vIGFyY2hpdmUgdXJpIHdhcyBwcm92aWRlZCIKZmkKCndhaXQgJGJhY2tncm91bmRQcm9jZXNzCgoK
#Here is the ASCII-encoded version of the script in the secret above
#!/usr/bin/env bash
#
#source /usr/local/bin/docker-entrypoint.sh
#
#install_deps() {
# apt-get update -y > /dev/null
# apt-get install curl -y > /dev/null
# apt-get install unzip -y > /dev/null
# curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" > /dev/null
# unzip awscliv2.zip > /dev/null
# ./aws/install > /dev/null
#}
#
#db_has_been_restored() {
# if [ ! -f "$PGDATA/CPLN_RESTORED" ]; then
# return 1
# fi
#
# if ! grep -q "\-> $1$" "$PGDATA/CPLN_RESTORED"; then
# return 1
# else
# return 0
# fi
#}
#
#restore_db() {
# while [ ! -S /var/run/postgresql/.s.PGSQL.5432 ]
# do
# echo "Waiting 5s for db socket to be available"
# sleep 5s
# done
#
#
# if ! db_has_been_restored "$1"; then
# echo "It appears db '$1' has not yet been restored from S3. Attempting to restore $1 from $2"
# install_deps
# docker_setup_db #Ensures $POSTGRES_DB exists (defined in the entrypoint script from the postgres docker image)
# aws s3 cp "$2" - | pg_restore --clean --no-acl --no-owner -d "$1" -U "$POSTGRES_USER"
# echo "$(date): $2 -> $1" | cat >> "$PGDATA/CPLN_RESTORED"
# else
# echo "Db '$1' already exists. Ready!"
# fi
#}
#
#_main "$@" &
#backgroundProcess=$!
#
#if [ -n "$POSTGRES_ARCHIVE_URI" ]; then
# restore_db "$POSTGRES_DB" "$POSTGRES_ARCHIVE_URI"
#else
# echo "Declining to restore the db because no archive uri was provided"
#fi
#
#wait $backgroundProcess
---
kind: identity
name: postgres-poc-identity
description: postgres-poc-identity
---
kind: policy
name: postgres-poc-access
description: postgres-poc-access
bindings:
- permissions:
- reveal
# Uncomment these two
# - use
# - view
principalLinks:
- //gvc/{{APP_NAME}}/identity/postgres-poc-identity
targetKind: secret
targetLinks:
- //secret/postgres-poc-credentials
- //secret/postgres-poc-entrypoint-script
---
kind: workload
name: postgres
description: postgres
spec:
type: stateful
containers:
- cpu: 1000m
memory: 512Mi
env:
# Uncomment next two envs will cause the db to be restored from the archive uri
# - name: POSTGRES_ARCHIVE_URI #Use this var to control the automatic restore behavior. If you leave it out, the db will start empty.
# value: s3://YOUR_BUCKET/PATH_TO_ARCHIVE_FILE
# - name: POSTGRES_DB #The name of the initial db in case of doing a restore
# value: test
- name: PGDATA #The location postgres stores the db. This can be anything other than /var/lib/postgresql/data, but it must be inside the mount point for the volume set
value: "/var/lib/postgresql/data/pg_data"
- name: POSTGRES_PASSWORD #The password for the default user
value: cpln://secret/postgres-poc-credentials.password
- name: POSTGRES_USER #The name of the default user
value: cpln://secret/postgres-poc-credentials.username
name: stateful
image: postgres:15
command: /bin/bash
args:
- "-c"
- "cat /usr/local/bin/cpln-entrypoint.sh >> ./cpln-entrypoint.sh && chmod u+x ./cpln-entrypoint.sh && ./cpln-entrypoint.sh postgres"
ports:
- number: 5432
protocol: tcp
volumes:
- uri: cpln://volumeset/postgres-poc-vs
path: "/var/lib/postgresql/data"
# Make the ENV value for the entry script a file
- uri: cpln://secret/postgres-poc-entrypoint-script
path: "/usr/local/bin/cpln-entrypoint.sh"
inheritEnv: false
livenessProbe:
tcpSocket:
port: 5432
failureThreshold: 1
readinessProbe:
tcpSocket:
port: 5432
failureThreshold: 1
identityLink: //identity/postgres-poc-identity
defaultOptions:
capacityAI: false
autoscaling:
metric: cpu
target: 95
maxScale: 1
firewallConfig:
external:
inboundAllowCIDR: []
outboundAllowCIDR:
- 0.0.0.0/0
internal:
inboundAllowType: same-gvc