Skip to content

Commit d8ec52d

Browse files
davissp14ndarilek
andauthored
PG16 Support (#233)
* Allow PG16 to be built with its own dockerfile * This will need more testing * Don't bump haproxy version here * Install python3-setuptools to get distutils module needed by barman. * Integrate flexctl. * Inject AWS shared credentials file into environment. --------- Co-authored-by: Nolan Darilek <[email protected]>
1 parent 8f5e645 commit d8ec52d

File tree

6 files changed

+214
-4
lines changed

6 files changed

+214
-4
lines changed

.github/workflows/ci.yaml

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ jobs:
77
release:
88
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
99
runs-on: ubuntu-latest
10-
# env:
11-
# DOCKER_BUILDKIT: 0
10+
1211
steps:
1312
-
1413
name: Set up QEMU
@@ -41,7 +40,7 @@ jobs:
4140
PG_MAJOR_VERSION=15
4241
VERSION=${{ steps.get-latest-tag.outputs.tag }}
4342
context: .
44-
file: ./Dockerfile
43+
file: ./pg15/Dockerfile
4544
push: true
4645
tags: |
4746
flyio/postgres-flex:15
@@ -56,14 +55,52 @@ jobs:
5655
PG_MAJOR_VERSION=15
5756
VERSION=${{ steps.get-latest-tag.outputs.tag }}
5857
context: .
59-
file: ./Dockerfile-timescaledb
58+
file: ./pg15/Dockerfile-timescaledb
6059
push: true
6160
tags: |
6261
flyio/postgres-flex-timescaledb:15
6362
flyio/postgres-flex-timescaledb:15.6
63+
64+
-
65+
name: Build and push Postgres 16
66+
id: docker_build_16
67+
uses: docker/build-push-action@v3
68+
with:
69+
build-args: |
70+
PG_VERSION=16.3
71+
PG_MAJOR_VERSION=16
72+
VERSION=${{ steps.get-latest-tag.outputs.tag }}
73+
context: .
74+
file: ./pg16/Dockerfile
75+
push: true
76+
tags: |
77+
flyio/postgres-flex:16
78+
flyio/postgres-flex:16.3
79+
-
80+
name: Build and push Postgres 16 Timescale DB
81+
id: docker_build_16_timescaledb
82+
uses: docker/build-push-action@v3
83+
with:
84+
build-args: |
85+
PG_VERSION=16.3
86+
PG_MAJOR_VERSION=16
87+
VERSION=${{ steps.get-latest-tag.outputs.tag }}
88+
context: .
89+
file: ./pg16/Dockerfile-timescaledb
90+
push: true
91+
tags: |
92+
flyio/postgres-flex-timescaledb:16
93+
flyio/postgres-flex-timescaledb:16.3
6494
-
6595
name: Postgres 15 Image digest
6696
run: echo ${{ steps.docker_build_15.outputs.digest }}
6797
-
6898
name: Postgres 15 TimescaleDB Image digest
6999
run: echo ${{ steps.docker_build_15_timescaledb.outputs.digest }}
100+
-
101+
name: Postgres 16 Image digest
102+
run: echo ${{ steps.docker_build_16.outputs.digest }}
103+
-
104+
name: Postgres 16 TimescaleDB Image digest
105+
run: echo ${{ steps.docker_build_16_timescaledb.outputs.digest }}
106+

internal/flypg/pg.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ func (c *PGConfig) SetDefaults(store *state.Store) error {
159159
}
160160

161161
c.internalConfig = ConfigMap{
162+
"listen_addresses": "'*'",
162163
"random_page_cost": "1.1",
163164
"port": c.Port,
164165
"shared_buffers": fmt.Sprintf("%dMB", sharedBuffersMb),
File renamed without changes.
File renamed without changes.

pg16/Dockerfile

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
ARG PG_VERSION=16.3
2+
ARG PG_MAJOR_VERSION=16
3+
ARG VERSION=custom
4+
5+
FROM golang:1.20 AS builder
6+
7+
WORKDIR /go/src/github.com/fly-apps/fly-postgres
8+
COPY . .
9+
10+
RUN CGO_ENABLED=0 GOOS=linux \
11+
go build -v -o /fly/bin/event_handler ./cmd/event_handler && \
12+
go build -v -o /fly/bin/failover_validation ./cmd/failover_validation && \
13+
go build -v -o /fly/bin/pg_unregister ./cmd/pg_unregister && \
14+
go build -v -o /fly/bin/start_monitor ./cmd/monitor && \
15+
go build -v -o /fly/bin/start_admin_server ./cmd/admin_server && \
16+
go build -v -o /fly/bin/start ./cmd/start && \
17+
go build -v -o /fly/bin/flexctl ./cmd/flexctl
18+
19+
20+
COPY ./bin/* /fly/bin/
21+
22+
FROM ubuntu:24.04
23+
24+
ENV PGDATA=/data/postgresql
25+
ENV PGPASSFILE=/data/.pgpass
26+
ENV AWS_SHARED_CREDENTIALS_FILE=/data/.aws/credentials
27+
ARG VERSION
28+
ARG PG_MAJOR_VERSION
29+
ARG POSTGIS_MAJOR=3
30+
ARG HAPROXY_VERSION=2.8
31+
ARG REPMGR_VERSION=5.4.1-1build2
32+
33+
LABEL fly.app_role=postgres_cluster
34+
LABEL fly.version=${VERSION}
35+
LABEL fly.pg-version=${PG_VERSION}
36+
LABEL fly.pg-manager=repmgr
37+
38+
RUN apt-get update && apt-get install --no-install-recommends -y \
39+
ca-certificates iproute2 curl bash dnsutils vim socat procps ssh gnupg rsync barman-cli barman barman-cli-cloud python3-setuptools cron gosu \
40+
&& apt autoremove -y && apt clean && \
41+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
42+
43+
# Install PostgreSQL
44+
RUN curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /usr/share/keyrings/postgresql-archive-keyring.gpg && \
45+
echo "deb [signed-by=/usr/share/keyrings/postgresql-archive-keyring.gpg] http://apt.postgresql.org/pub/repos/apt/ noble-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \
46+
apt-get update && apt-get install --no-install-recommends -y \
47+
postgresql-${PG_MAJOR_VERSION} \
48+
postgresql-client-${PG_MAJOR_VERSION} \
49+
postgresql-contrib-${PG_MAJOR_VERSION}
50+
51+
# Repmgr
52+
RUN curl -L http://launchpadlibrarian.net/722514158/postgresql-${PG_MAJOR_VERSION}-repmgr_${REPMGR_VERSION}_amd64.deb -o postgresql-${PG_MAJOR_VERSION}-repmgr_${REPMGR_VERSION}_amd64.deb && \
53+
apt-get install -y ./postgresql-${PG_MAJOR_VERSION}-repmgr_${REPMGR_VERSION}_amd64.deb \
54+
&& rm ./postgresql-${PG_MAJOR_VERSION}-repmgr_${REPMGR_VERSION}_amd64.deb
55+
56+
# PostGIS
57+
RUN apt-get update && apt-get install --no-install-recommends -y \
58+
postgresql-${PG_MAJOR_VERSION}-postgis-$POSTGIS_MAJOR \
59+
postgresql-${PG_MAJOR_VERSION}-postgis-$POSTGIS_MAJOR-scripts
60+
61+
# Haproxy
62+
RUN apt-get update && apt-get install --no-install-recommends -y \
63+
haproxy=$HAPROXY_VERSION.\* \
64+
&& apt autoremove -y && apt clean
65+
66+
67+
# Add PostgreSQL bin directory to PATH
68+
ENV PATH="/usr/lib/postgresql/${PG_MAJOR_VERSION}/bin:$PATH"
69+
70+
# Copy Go binaries from the builder stage
71+
COPY --from=builder /fly/bin/* /usr/local/bin
72+
73+
# Copy Postgres exporter
74+
COPY --from=wrouesnel/postgres_exporter:latest /postgres_exporter /usr/local/bin/
75+
76+
ADD /config/* /fly/
77+
RUN mkdir -p /run/haproxy/
78+
RUN usermod -d /data postgres
79+
80+
EXPOSE 5432
81+
82+
CMD ["start"]

pg16/Dockerfile-timescaledb

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
ARG PG_VERSION=16.3
2+
ARG PG_MAJOR_VERSION=16
3+
ARG VERSION=custom
4+
5+
FROM golang:1.20 AS builder
6+
7+
WORKDIR /go/src/github.com/fly-apps/fly-postgres
8+
COPY . .
9+
10+
RUN CGO_ENABLED=0 GOOS=linux \
11+
go build -v -o /fly/bin/event_handler ./cmd/event_handler && \
12+
go build -v -o /fly/bin/failover_validation ./cmd/failover_validation && \
13+
go build -v -o /fly/bin/pg_unregister ./cmd/pg_unregister && \
14+
go build -v -o /fly/bin/start_monitor ./cmd/monitor && \
15+
go build -v -o /fly/bin/start_admin_server ./cmd/admin_server && \
16+
go build -v -o /fly/bin/start ./cmd/start && \
17+
go build -v -o /fly/bin/flexctl ./cmd/flexctl
18+
19+
20+
COPY ./bin/* /fly/bin/
21+
22+
FROM ubuntu:24.04
23+
24+
ENV PGDATA=/data/postgresql
25+
ENV PGPASSFILE=/data/.pgpass
26+
ENV AWS_SHARED_CREDENTIALS_FILE=/data/.aws/credentials
27+
ARG VERSION
28+
ARG PG_MAJOR_VERSION
29+
ARG POSTGIS_MAJOR=3
30+
ARG HAPROXY_VERSION=2.8
31+
ARG REPMGR_VERSION=5.4.1-1build2
32+
33+
LABEL fly.app_role=postgres_cluster
34+
LABEL fly.version=${VERSION}
35+
LABEL fly.pg-version=${PG_VERSION}
36+
LABEL fly.pg-manager=repmgr
37+
38+
RUN apt-get update && apt-get install --no-install-recommends -y \
39+
ca-certificates iproute2 curl bash dnsutils vim socat procps ssh gnupg rsync barman-cli barman barman-cli-cloud python3-setuptools cron gosu \
40+
&& apt autoremove -y && apt clean && \
41+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
42+
43+
# Install PostgreSQL
44+
RUN curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /usr/share/keyrings/postgresql-archive-keyring.gpg && \
45+
echo "deb [signed-by=/usr/share/keyrings/postgresql-archive-keyring.gpg] http://apt.postgresql.org/pub/repos/apt/ noble-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \
46+
apt-get update && apt-get install --no-install-recommends -y \
47+
postgresql-${PG_MAJOR_VERSION} \
48+
postgresql-client-${PG_MAJOR_VERSION} \
49+
postgresql-contrib-${PG_MAJOR_VERSION}
50+
51+
# Repmgr
52+
RUN curl -L http://launchpadlibrarian.net/722514158/postgresql-${PG_MAJOR_VERSION}-repmgr_${REPMGR_VERSION}_amd64.deb -o postgresql-${PG_MAJOR_VERSION}-repmgr_${REPMGR_VERSION}_amd64.deb && \
53+
apt-get install -y ./postgresql-${PG_MAJOR_VERSION}-repmgr_${REPMGR_VERSION}_amd64.deb \
54+
&& rm ./postgresql-${PG_MAJOR_VERSION}-repmgr_${REPMGR_VERSION}_amd64.deb
55+
56+
57+
# TimescaleDB and PostGIS
58+
RUN echo "deb https://packagecloud.io/timescale/timescaledb/ubuntu/ jammy main" > /etc/apt/sources.list.d/timescaledb.list \
59+
&& curl -L https://packagecloud.io/timescale/timescaledb/gpgkey | apt-key add -
60+
61+
RUN apt-get update && apt-get install --no-install-recommends -y \
62+
postgresql-$PG_MAJOR_VERSION-postgis-$POSTGIS_MAJOR \
63+
postgresql-$PG_MAJOR_VERSION-postgis-$POSTGIS_MAJOR-scripts \
64+
timescaledb-2-postgresql-$PG_MAJOR_VERSION \
65+
&& apt autoremove -y && apt clean
66+
67+
# Haproxy
68+
RUN apt-get update && apt-get install --no-install-recommends -y \
69+
haproxy=$HAPROXY_VERSION.\* \
70+
&& apt autoremove -y && apt clean
71+
72+
73+
# Add PostgreSQL bin directory to PATH
74+
ENV PATH="/usr/lib/postgresql/${PG_MAJOR_VERSION}/bin:$PATH"
75+
76+
# Copy Go binaries from the builder stage
77+
COPY --from=builder /fly/bin/* /usr/local/bin
78+
79+
# Copy Postgres exporter
80+
COPY --from=wrouesnel/postgres_exporter:latest /postgres_exporter /usr/local/bin/
81+
82+
ADD /config/* /fly/
83+
RUN mkdir -p /run/haproxy/
84+
RUN usermod -d /data postgres
85+
86+
ENV TIMESCALEDB_ENABLED=true
87+
88+
EXPOSE 5432
89+
90+
CMD ["start"]

0 commit comments

Comments
 (0)