Skip to content

chore: build pg15 with docker #655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion .github/workflows/ami-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- develop
- ansi-dock
- build-pg
paths:
- '.github/workflows/ami-release.yml'
- 'common.vars.pkr.hcl'
Expand Down Expand Up @@ -55,6 +56,25 @@ jobs:
tar xvf "$layer" -C ansible/files/extensions --strip-components 1
done

- name: Build Postgres deb
uses: docker/build-push-action@v3
with:
push: false
load: true
file: docker/Dockerfile
target: pg-deb
tags: supabase/postgres:deb
platforms: linux/${{ matrix.arch }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Extract Postgres deb
run: |
mkdir -p /tmp/build ansible/files/postgres
docker save supabase/postgres:deb | tar xv -C /tmp/build
for layer in /tmp/build/*/layer.tar; do
tar xvf "$layer" -C ansible/files/postgres --strip-components 1
done

- name: Build AMI
run: |
GIT_SHA=${{github.sha}}
Expand Down Expand Up @@ -110,7 +130,7 @@ jobs:
target_commitish: ${{github.sha}}

- name: Slack Notification on Failure
if: ${{ failure() }}
if: ${{ false }}
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_NOTIFICATIONS_WEBHOOK }}
Expand Down
5 changes: 4 additions & 1 deletion ansible/tasks/setup-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

# Builtin apt module does not support wildcard for deb paths
- name: Install extensions
shell: apt-get install -y --no-install-recommends /tmp/extensions/*.deb
shell: |
set -e
apt-get update
apt-get install -y --no-install-recommends /tmp/extensions/*.deb

- name: pg_cron - set cron.database_name
become: yes
Expand Down
32 changes: 17 additions & 15 deletions ansible/tasks/setup-postgres.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
# Downloading dependencies
- name: GPG dependencies
apt:
name: gnupg

- name: Add Postgres GPG key
apt_key:
keyserver: keyserver.ubuntu.com
id: B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
- name: Postgres - copy package
copy:
src: files/postgres/
dest: /tmp/build/

- name: Add Postgres PPA
- name: Postgres - add PPA
apt_repository:
repo: "deb https://apt-archive.postgresql.org/pub/repos/apt {{ ansible_distribution_release }}-pgdg-archive main"
repo: "deb [ trusted=yes ] file:///tmp/build ./"
state: present

- name: Postgres - install commons
apt:
name: postgresql-common
state: latest
update_cache: yes
install_recommends: no

- name: Do not create main cluster
shell:
Expand All @@ -26,9 +20,17 @@
- name: Postgres - install server
apt:
name: postgresql-{{ postgresql_major }}={{ postgresql_release }}-1.pgdg20.04+1
install_recommends: no

- name: Hold postgres {{ postgresql_release }} from apt upgrade
shell: apt-mark hold postgresql-{{ postgresql_major }}
- name: Postgres - remove PPA
apt_repository:
repo: "deb [ trusted=yes ] file:///tmp/build ./"
state: absent

- name: Postgres - cleanup package
file:
path: /tmp/build
state: absent

- name: Create symlink to /usr/lib/postgresql/bin
shell:
Expand Down
2 changes: 1 addition & 1 deletion common.vars.pkr.hcl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
postgres-version = "15.1.0.86-rc1"
postgres-version = "15.1.0.89-rc1"
71 changes: 71 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
ARG ubuntu_release=focal
FROM ubuntu:${ubuntu_release} as base

ARG ubuntu_release
ARG postgresql_major=15
ARG postgresql_release=${postgresql_major}.1

FROM base as pg-source

# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
gnupg \
dpkg-dev \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*

# Add Postgres PPA
ARG postgresql_gpg_key=B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys "${postgresql_gpg_key}" && \
echo "deb https://apt-archive.postgresql.org/pub/repos/apt ${ubuntu_release}-pgdg-archive main" > /etc/apt/sources.list.d/pgdg.list && \
echo "deb-src https://apt-archive.postgresql.org/pub/repos/apt ${ubuntu_release}-pgdg-archive main" > /etc/apt/sources.list.d/pgdg.list

# Create local PPA
WORKDIR /tmp/build
RUN echo "deb [ trusted=yes ] file:///tmp/build ./" > /etc/apt/sources.list.d/temp.list && \
dpkg-scanpackages . > Packages && \
apt-get -o Acquire::GzipIndexes=false update

ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONDONTWRITEBYTECODE=1
ENV DEB_BUILD_OPTIONS="nocheck parallel=$(nproc)"

# Configure processor optimised build
ARG CPPFLAGS="-mcpu=neoverse-n1"
ENV DEB_CPPFLAGS_APPEND="${CPPFLAGS} -fsigned-char"

RUN apt-get build-dep -y postgresql-common pgdg-keyring && \
apt-get source --compile postgresql-common pgdg-keyring && \
dpkg-scanpackages . > Packages && \
apt-get -o Acquire::GzipIndexes=false update

RUN apt-get build-dep -y "postgresql-${postgresql_major}=${postgresql_release}-1.pgdg20.04+1" && \
apt-get source --compile "postgresql-${postgresql_major}=${postgresql_release}-1.pgdg20.04+1" && \
dpkg-scanpackages . > Packages && \
apt-get -o Acquire::GzipIndexes=false update

# Remove source directories
RUN rm -rf /tmp/build/*/

FROM base as pg

# Inherit args from base stage
ARG postgresql_major
ARG postgresql_release

COPY --from=pg-source /tmp/build /tmp/build

ENV DEBIAN_FRONTEND=noninteractive
RUN echo "deb [ trusted=yes ] file:///tmp/build ./" > /etc/apt/sources.list.d/temp.list && \
apt-get -o Acquire::GzipIndexes=false update && \
apt-get install -y --no-install-recommends postgresql-common && \
sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf && \
apt-get install -y --no-install-recommends "postgresql-${postgresql_major}=${postgresql_release}-1.pgdg20.04+1" && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /tmp/build /etc/apt/sources.list.d/temp.list

ENV PATH $PATH:/usr/lib/postgresql/${postgresql_major}/bin

FROM scratch as pg-deb

COPY --from=pg-source /tmp/build /tmp