Skip to content

Commit 23ce1bb

Browse files
committed
chore: build pg15 from source
1 parent eb24d46 commit 23ce1bb

File tree

4 files changed

+70
-5
lines changed

4 files changed

+70
-5
lines changed

.github/workflows/ami-release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
branches:
66
- develop
77
- ansi-dock
8+
- build-pg
89
paths:
910
- '.github/workflows/ami-release.yml'
1011
- 'common.vars.pkr.hcl'
@@ -110,7 +111,7 @@ jobs:
110111
target_commitish: ${{github.sha}}
111112

112113
- name: Slack Notification on Failure
113-
if: ${{ failure() }}
114+
if: ${{ false }}
114115
uses: rtCamp/action-slack-notify@v2
115116
env:
116117
SLACK_WEBHOOK: ${{ secrets.SLACK_NOTIFICATIONS_WEBHOOK }}

ansible/tasks/setup-docker.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55

66
# Builtin apt module does not support wildcard for deb paths
77
- name: Install extensions
8-
shell: apt-get install -y --no-install-recommends /tmp/extensions/*.deb
8+
shell: |
9+
set -e
10+
apt-get update
11+
apt-get install -y --no-install-recommends /tmp/extensions/*.deb
912
1013
- name: pg_cron - set cron.database_name
1114
become: yes

ansible/tasks/setup-postgres.yml

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,62 @@
1313
repo: "deb https://apt-archive.postgresql.org/pub/repos/apt {{ ansible_distribution_release }}-pgdg-archive main"
1414
state: present
1515

16+
# let's build binaries from their published source packages
17+
- name: Add Postgres PPA - source
18+
apt_repository:
19+
repo: "deb-src https://apt-archive.postgresql.org/pub/repos/apt {{ ansible_distribution_release }}-pgdg-archive main"
20+
state: present
21+
22+
- name: Create temporary build directory
23+
tempfile:
24+
state: directory
25+
register: pg_build_dir
26+
27+
- name: Setting mcpu (arm)
28+
set_fact:
29+
mcpu: "neoverse-n1"
30+
when: platform == "arm64"
31+
32+
- name: Postgres - build
33+
shell: |
34+
set -e
35+
export PYTHONDONTWRITEBYTECODE=1
36+
savedAptMark="$(apt-mark showmanual)"
37+
cd "{{ pg_build_dir.path }}"
38+
39+
# create a temporary local APT repo to install from (so that dependency resolution can be handled by APT, as it should be)
40+
apt-get update
41+
apt-get install -y --no-install-recommends dpkg-dev
42+
echo "deb [ trusted=yes ] file://{{ pg_build_dir.path }} ./" > /etc/apt/sources.list.d/temp.list
43+
_update_repo() {
44+
dpkg-scanpackages . > Packages
45+
apt-get -o Acquire::GzipIndexes=false update
46+
}
47+
_update_repo
48+
49+
# build .deb files from upstream's source packages (which are verified by apt-get)
50+
export DEB_BUILD_OPTIONS="nocheck parallel=$(nproc)"
51+
export DEB_CPPFLAGS_APPEND="-mcpu={{ mcpu }} -fsigned-char"
52+
53+
# we have to build postgresql-common first because postgresql-15 shares "debian/rules" logic with it: https://salsa.debian.org/postgresql/postgresql/-/commit/99f44476e258cae6bf9e919219fa2c5414fa2876
54+
# (and it "Depends: pgdg-keyring")
55+
apt-get build-dep -y postgresql-common pgdg-keyring
56+
apt-get source --compile postgresql-common pgdg-keyring
57+
_update_repo
58+
apt-get build-dep -y "postgresql-{{ postgresql_major }}={{ postgresql_release }}-1.pgdg20.04+1"
59+
apt-get source --compile "postgresql-{{ postgresql_major }}={{ postgresql_release }}-1.pgdg20.04+1"
60+
61+
# we don't remove APT lists here because they get re-downloaded and removed later
62+
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
63+
# (which is done after we install the built packages so we don't have to redownload any overlapping dependencies)
64+
apt-mark showmanual | xargs apt-mark auto > /dev/null
65+
apt-mark manual $savedAptMark
66+
_update_repo
67+
1668
- name: Postgres - install commons
1769
apt:
1870
name: postgresql-common
19-
state: latest
20-
update_cache: yes
71+
install_recommends: no
2172

2273
- name: Do not create main cluster
2374
shell:
@@ -26,6 +77,16 @@
2677
- name: Postgres - install server
2778
apt:
2879
name: postgresql-{{ postgresql_major }}={{ postgresql_release }}-1.pgdg20.04+1
80+
install_recommends: no
81+
82+
# if we have leftovers from building, let's purge them (including extra, unnecessary build deps)
83+
- name: Remove build dependencies
84+
shell: |
85+
set -e
86+
rm -rf /var/lib/apt/lists/*
87+
apt-get purge -y --auto-remove
88+
rm -rf "{{ pg_build_dir.path }}" /etc/apt/sources.list.d/temp.list
89+
find /usr -name '*.pyc' -type f -exec bash -c 'for pyc; do dpkg -S "$pyc" &> /dev/null || rm -vf "$pyc"; done' -- '{}' +
2990
3091
- name: Hold postgres {{ postgresql_release }} from apt upgrade
3192
shell: apt-mark hold postgresql-{{ postgresql_major }}

common.vars.pkr.hcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
postgres-version = "15.1.0.86-rc1"
1+
postgres-version = "15.1.0.89-rc0"

0 commit comments

Comments
 (0)