Skip to content

Commit 8c416da

Browse files
committed
chore: setup docker extension task
1 parent 8248f1f commit 8c416da

File tree

7 files changed

+84
-168
lines changed

7 files changed

+84
-168
lines changed

.github/workflows/ami-release.yml

+8-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- develop
7+
- ansi-dock
78
paths:
89
- '.github/workflows/ami-release.yml'
910
- 'common.vars.pkr.hcl'
@@ -25,7 +26,7 @@ jobs:
2526

2627
steps:
2728
- name: Checkout Repo
28-
uses: actions/checkout@v2
29+
uses: actions/checkout@v3
2930

3031
- id: args
3132
uses: mikefarah/yq@master
@@ -48,10 +49,10 @@ jobs:
4849
cache-to: type=gha,mode=max
4950
- name: Extract built packages
5051
run: |
51-
mkdir -p ansible/extensions/packages
52-
docker save supabase/postgres:extensions | tar xv -C ansible/extensions
53-
for layer in ansible/extensions/*/layer.tar; do
54-
tar xvf "$layer" -C ansible/extensions/packages --strip-components 1
52+
mkdir -p /tmp/extensions ansible/files/extensions
53+
docker save supabase/postgres:extensions | tar xv -C /tmp/extensions
54+
for layer in /tmp/extensions/*/layer.tar; do
55+
tar xvf "$layer" -C ansible/files/extensions --strip-components 1
5556
done
5657
5758
- name: Build AMI
@@ -82,7 +83,7 @@ jobs:
8283
- name: Upload pg binaries to s3 staging
8384
run: |
8485
aws s3 cp /tmp/pg_binaries.tar.gz s3://${{ secrets.ARTIFACTS_BUCKET }}/upgrades/postgres/supabase-postgres-${{ steps.process_release_version.outputs.version }}/20.04.tar.gz
85-
86+
8687
- name: configure aws credentials - prod
8788
uses: aws-actions/configure-aws-credentials@v1
8889
with:
@@ -100,7 +101,7 @@ jobs:
100101
- name: Upload pg binaries to s3 prod
101102
run: |
102103
aws s3 cp /tmp/pg_binaries.tar.gz s3://${{ secrets.PROD_ARTIFACTS_BUCKET }}/upgrades/postgres/supabase-postgres-${{ steps.process_release_version.outputs.version }}/20.04.tar.gz
103-
104+
104105
- name: Create release
105106
uses: softprops/action-gh-release@v1
106107
with:

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ RUN ./configure --with-sfcgal
179179
RUN --mount=type=cache,target=/ccache,from=public.ecr.aws/supabase/postgres:ccache \
180180
make -j$(nproc)
181181
# Create debian package
182-
RUN checkinstall -D --install=no --fstrans=no --backup=no --pakdir=/tmp --requires=libgeos-c1v5,libproj19,libjson-c5,libprotobuf-c1,libgdal28 --nodoc
182+
RUN checkinstall -D --install=no --fstrans=no --backup=no --pakdir=/tmp --requires=libgeos-c1v5,libproj15,libjson-c4,libprotobuf-c1,libgdal26 --nodoc
183183

184184
FROM ppa as postgis
185185
# Latest available is 3.3.2
@@ -818,7 +818,7 @@ RUN arch=$([ "$TARGETARCH" = "arm64" ] && echo "aarch64" || echo "$TARGETARCH")
818818
# Collect extension packages
819819
####################
820820
FROM scratch as extensions
821-
COPY --from=postgis /tmp/*.deb /tmp/
821+
COPY --from=postgis-source /tmp/*.deb /tmp/
822822
COPY --from=pgrouting-source /tmp/*.deb /tmp/
823823
COPY --from=pgtap-source /tmp/*.deb /tmp/
824824
COPY --from=pg_cron-source /tmp/*.deb /tmp/

ansible/playbook.yml

+3-17
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
- name: Install Postgres from source
3131
import_tasks: tasks/setup-postgres.yml
3232

33-
- name: Install Postgres extensions
34-
import_tasks: tasks/setup-extensions.yml
35-
3633
- name: Install PgBouncer
3734
import_tasks: tasks/setup-pgbouncer.yml
3835
tags:
@@ -79,7 +76,7 @@
7976
become: yes
8077
become_user: postgres
8178
shell:
82-
cmd: /usr/bin/pg_ctl -D /var/lib/postgresql/data start
79+
cmd: /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data start
8380
when: ebssurrogate_mode
8481

8582
- name: Adjust APT update intervals
@@ -138,25 +135,14 @@
138135
update_cache: yes
139136
cache_valid_time: 3600
140137

141-
# Put PG binaries in a directory under $PATH
142-
- name: Find all files in /usr/lib/postgresql/bin
143-
find:
144-
paths: /usr/lib/postgresql/bin
145-
register: postgresql_bin
146-
147138
- name: Clean out build dependencies
148139
import_tasks: tasks/clean-build-dependencies.yml
149140

150-
- name: Create symbolic links for Postgres binaries to /usr/bin/
151-
become: yes
152-
shell:
153-
cmd: "for fl in /usr/lib/postgresql/bin/* ; do ln -sf $fl /usr/bin/$(basename $fl) ; done"
154-
155141
- name: Restart Postgres Database without Systemd
156142
become: yes
157143
become_user: postgres
158144
shell:
159-
cmd: /usr/bin/pg_ctl -D /var/lib/postgresql/data restart "-o -c shared_preload_libraries='pg_tle'"
145+
cmd: /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data restart -o "-c shared_preload_libraries='pg_tle'"
160146
when: ebssurrogate_mode
161147

162148
- name: Run migrations
@@ -168,7 +154,7 @@
168154
become: yes
169155
become_user: postgres
170156
shell:
171-
cmd: /usr/bin/pg_ctl -D /var/lib/postgresql/data stop
157+
cmd: /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data stop
172158
when: ebssurrogate_mode
173159

174160
- name: Run unit tests

ansible/tasks/setup-docker.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
- name: Copy extension packages
2+
copy:
3+
src: files/extensions/
4+
dest: /tmp/extensions/
5+
6+
- name: Install extensions
7+
apt:
8+
deb: "/tmp/extensions/{{ item | basename }}"
9+
with_fileglob: "files/extensions/*.deb"
10+
11+
- name: pg_cron - set cron.database_name
12+
become: yes
13+
lineinfile:
14+
path: /etc/postgresql/postgresql.conf
15+
state: present
16+
line: cron.database_name = 'postgres'
17+
18+
- name: pgsodium - determine postgres bin directory
19+
shell: pg_config --bindir
20+
register: pg_bindir_output
21+
- set_fact:
22+
pg_bindir: "{{ pg_bindir_output.stdout }}"
23+
24+
- name: pgsodium - set pgsodium.getkey_script
25+
become: yes
26+
lineinfile:
27+
path: /etc/postgresql/postgresql.conf
28+
state: present
29+
# script is expected to be placed by finalization tasks for different target platforms
30+
line: pgsodium.getkey_script= '{{ pg_bindir }}/pgsodium_getkey.sh'
31+
32+
- name: auto_explain - set auto_explain.log_min_duration
33+
become: yes
34+
lineinfile:
35+
path: /etc/postgresql/postgresql.conf
36+
state: present
37+
line: auto_explain.log_min_duration = 10s
38+
39+
- name: Cleanup - extension packages
40+
file:
41+
path: /tmp/extensions
42+
state: absent

ansible/tasks/setup-postgres.yml

+26-129
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,35 @@
11
# Downloading dependencies
2-
- name: Postgres dependencies
2+
- name: GPG dependencies
33
apt:
4-
pkg:
5-
- build-essential
6-
- pkg-config
7-
- libreadline-dev
8-
- zlib1g-dev
9-
- flex
10-
- bison
11-
- libxml2-dev
12-
- libxslt-dev
13-
- libssl-dev
14-
- libsystemd-dev
15-
- libxml2-utils
16-
- uuid-dev
17-
- xsltproc
18-
- ssl-cert
19-
- liblz4-dev
20-
- libicu-dev
21-
22-
- name: Download LLVM & Clang
23-
apt:
24-
pkg:
25-
- llvm-11-dev
26-
- clang-11
27-
when: ansible_distribution_version != "18.04"
4+
name: gnupg
285

29-
- name: Download LLVM & Clang - Ubuntu 18.04
30-
apt:
31-
pkg:
32-
- llvm-12-dev
33-
- clang-12
34-
when: ansible_distribution_version == "18.04"
6+
- name: Add Postgres GPG key
7+
apt_key:
8+
keyserver: keyserver.ubuntu.com
9+
id: B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
3510

36-
- name: Download GCC 10
11+
- name: Add Postgres PPA
12+
apt_repository:
13+
repo: "deb https://apt-archive.postgresql.org/pub/repos/apt {{ ansible_distribution_release }}-pgdg-archive main"
14+
state: present
15+
16+
- name: Postgres - install commons
3717
apt:
38-
pkg:
39-
- gcc-10
40-
- g++-10
18+
name: postgresql-common
19+
state: latest
20+
update_cache: yes
4121

42-
- name: Switch to GCC 10
22+
- name: Do not create main cluster
4323
shell:
44-
cmd: update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100 --slave /usr/bin/g++ g++ /usr/bin/g++-10 --slave /usr/bin/gcov gcov /usr/bin/gcov-10
24+
cmd: sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf
4525

46-
# Setup permissions
47-
- name: Update permissions for /var/tmp directory
48-
file:
49-
path: /var/tmp/
50-
owner: root
51-
group: root
52-
mode: '1777'
53-
become: yes
26+
- name: Postgres - install server
27+
apt:
28+
name: postgresql-{{ postgresql_major }}={{ postgresql_release }}-1.pgdg20.04+1
5429

55-
# Building Postgres from source
56-
- name: Postgres - download latest release
57-
get_url:
58-
url: https://ftp.postgresql.org/pub/source/v{{ postgresql_release }}/postgresql-{{ postgresql_release }}.tar.gz
59-
dest: /tmp
60-
checksum: "{{ postgresql_release_checksum }}"
61-
timeout: 60
62-
63-
- name: Postgres - unpack archive
64-
unarchive:
65-
remote_src: yes
66-
src: /tmp/postgresql-{{ postgresql_release }}.tar.gz
67-
dest: /tmp
68-
69-
- name: Setting CFLAGS (arm)
70-
set_fact:
71-
cflags: "-moutline-atomics -mtune=native -march=native -mcpu=native -fsigned-char -O2"
72-
when: platform == "arm64" and ansible_distribution_version != "18.04"
73-
74-
- name: Setting CFLAGS (arm) - Ubuntu 18.04
75-
set_fact:
76-
cflags: "-moutline-atomics -fsigned-char -O2"
77-
when: platform == "arm64" and ansible_distribution_version == "18.04"
78-
79-
- name: Setting CFLAGS (x86)
80-
set_fact:
81-
cflags: "-fsigned-char"
82-
when: platform == "amd64"
83-
84-
- name: Setting LLVM_CONFIG
85-
set_fact:
86-
llvm_config: "/usr/bin/llvm-config-11"
87-
clang: "/usr/bin/clang-11"
88-
when: ansible_distribution_version != "18.04"
89-
90-
- name: Setting LLVM_CONFIG - Ubuntu 18.04
91-
set_fact:
92-
llvm_config: "/usr/bin/llvm-config-12"
93-
clang: "/usr/bin/clang-12"
94-
when: ansible_distribution_version == "18.04"
95-
96-
- name: Postgres - configure
30+
- name: Create symlink to /usr/lib/postgresql/bin
9731
shell:
98-
cmd: CFLAGS='{{ cflags }}' LLVM_CONFIG='{{ llvm_config }}' CLANG='{{ clang }}' ./configure --with-llvm --with-openssl --with-systemd --with-uuid=e2fs --with-libxml --with-icu --with-lz4 --exec-prefix=/usr/lib/postgresql --datarootdir=/var/lib/postgresql
99-
chdir: /tmp/postgresql-{{ postgresql_release }}
100-
101-
- name: Postgres - build
102-
community.general.make:
103-
target: world-bin
104-
chdir: /tmp/postgresql-{{ postgresql_release }}
105-
jobs: "{{ parallel_jobs | default(omit) }}"
106-
107-
- name: Postgres - install
108-
make:
109-
target: install-world-bin
110-
chdir: /tmp/postgresql-{{ postgresql_release }}
111-
112-
- name: Create postgres group
113-
group:
114-
name: postgres
115-
state: present
116-
117-
# Create postgres user
118-
- name: Create postgres user
119-
user:
120-
name: postgres
121-
shell: /bin/false
122-
comment: Postgres user
123-
group: postgres
124-
groups: postgres,ssl-cert
32+
cmd: ln -s /usr/lib/postgresql/{{ postgresql_major }}/bin /usr/lib/postgresql/bin
12533

12634
- name: Create relevant directories
12735
file:
@@ -131,8 +39,7 @@
13139
owner: postgres
13240
group: postgres
13341
with_items:
134-
- '/etc/postgresql'
135-
- '/etc/postgresql-custom'
42+
- '/home/postgres'
13643
- '/var/log/postgresql'
13744
- '/var/lib/postgresql'
13845

@@ -181,19 +88,9 @@
18188
dest: /etc/postgresql/pg_ident.conf
18289
group: postgres
18390

184-
- name: Find all files in /usr/lib/postgresql/bin
185-
find:
186-
paths: /usr/lib/postgresql/bin
187-
register: postgresql_bin
188-
189-
- name: Create symbolic links for Postgres binaries to /usr/bin/
190-
become: yes
191-
file:
192-
src: "{{ item.path }}"
193-
path: "/usr/bin/{{ item.path | basename }}"
194-
state: link
195-
force: yes
196-
with_items: "{{ postgresql_bin.files }}"
91+
# Install extensions before init
92+
- name: Install Postgres extensions
93+
import_tasks: tasks/setup-docker.yml
19794

19895
# init DB
19996
- name: Create directory on data volume

ansible/tasks/test-image.yml

+2-12
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
become: yes
1515
become_user: postgres
1616
shell:
17-
cmd: /usr/bin/pg_ctl -D /var/lib/postgresql/data start "-o -c config_file=/etc/postgresql/postgresql.conf"
17+
cmd: /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data start "-o -c config_file=/etc/postgresql/postgresql.conf"
1818
when: ebssurrogate_mode
1919

2020
- name: Run Unit tests (with filename unit-test-*) on Postgres Database
@@ -49,19 +49,9 @@
4949
state: absent
5050
autoremove: yes
5151

52-
- name: Get pg_config file details
53-
ansible.builtin.stat:
54-
path: /usr/bin/pg_config
55-
register: st
56-
57-
- name: Ensure pg_config points to our install of PG
58-
ansible.builtin.fail:
59-
msg: "Incorrect symlink for pg_config"
60-
when: st.stat.lnk_target != '/usr/lib/postgresql/bin/pg_config'
61-
6252
- name: Stop Postgres Database
6353
become: yes
6454
become_user: postgres
6555
shell:
66-
cmd: /usr/bin/pg_ctl -D /var/lib/postgresql/data stop
56+
cmd: /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data stop
6757
when: ebssurrogate_mode

common.vars.pkr.hcl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
postgres-version = "15.1.0.84"
1+
postgres-version = "15.1.0.85-rc0"

0 commit comments

Comments
 (0)