From 5de49820df77074d14965994486dd44b77272321 Mon Sep 17 00:00:00 2001 From: Shaun Davis Date: Sat, 6 Jul 2024 15:25:10 -0500 Subject: [PATCH] Allow PG16 to be built with its own dockerfile --- .github/workflows/ci.yaml | 45 ++++++++++- internal/flypg/pg.go | 1 + Dockerfile => pg15/Dockerfile | 0 .../Dockerfile-timescaledb | 0 pg16/Dockerfile | 79 ++++++++++++++++++ pg16/Dockerfile-timescaledb | 81 +++++++++++++++++++ 6 files changed, 202 insertions(+), 4 deletions(-) rename Dockerfile => pg15/Dockerfile (100%) rename Dockerfile-timescaledb => pg15/Dockerfile-timescaledb (100%) create mode 100644 pg16/Dockerfile create mode 100644 pg16/Dockerfile-timescaledb diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 8f7de033..8d4d63e9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -7,8 +7,7 @@ jobs: release: if: ${{ startsWith(github.ref, 'refs/tags/v') }} runs-on: ubuntu-latest - # env: - # DOCKER_BUILDKIT: 0 + steps: - name: Set up QEMU @@ -41,7 +40,7 @@ jobs: PG_MAJOR_VERSION=15 VERSION=${{ steps.get-latest-tag.outputs.tag }} context: . - file: ./Dockerfile + file: ./pg15/Dockerfile push: true tags: | flyio/postgres-flex:15 @@ -56,14 +55,52 @@ jobs: PG_MAJOR_VERSION=15 VERSION=${{ steps.get-latest-tag.outputs.tag }} context: . - file: ./Dockerfile-timescaledb + file: ./pg15/Dockerfile-timescaledb push: true tags: | flyio/postgres-flex-timescaledb:15 flyio/postgres-flex-timescaledb:15.6 + + - + name: Build and push Postgres 16 + id: docker_build_16 + uses: docker/build-push-action@v3 + with: + build-args: | + PG_VERSION=16.3 + PG_MAJOR_VERSION=16 + VERSION=${{ steps.get-latest-tag.outputs.tag }} + context: . + file: ./pg16/Dockerfile + push: true + tags: | + flyio/postgres-flex:16 + flyio/postgres-flex:16.3 + - + name: Build and push Postgres 16 Timescale DB + id: docker_build_16_timescaledb + uses: docker/build-push-action@v3 + with: + build-args: | + PG_VERSION=16.3 + PG_MAJOR_VERSION=16 + VERSION=${{ steps.get-latest-tag.outputs.tag }} + context: . + file: ./pg16/Dockerfile-timescaledb + push: true + tags: | + flyio/postgres-flex-timescaledb:16 + flyio/postgres-flex-timescaledb:16.3 - name: Postgres 15 Image digest run: echo ${{ steps.docker_build_15.outputs.digest }} - name: Postgres 15 TimescaleDB Image digest run: echo ${{ steps.docker_build_15_timescaledb.outputs.digest }} + - + name: Postgres 16 Image digest + run: echo ${{ steps.docker_build_16.outputs.digest }} + - + name: Postgres 16 TimescaleDB Image digest + run: echo ${{ steps.docker_build_16_timescaledb.outputs.digest }} + diff --git a/internal/flypg/pg.go b/internal/flypg/pg.go index 730cbd5b..94a294ab 100644 --- a/internal/flypg/pg.go +++ b/internal/flypg/pg.go @@ -159,6 +159,7 @@ func (c *PGConfig) SetDefaults(store *state.Store) error { } c.internalConfig = ConfigMap{ + "listen_addresses": "'*'", "random_page_cost": "1.1", "port": c.Port, "shared_buffers": fmt.Sprintf("%dMB", sharedBuffersMb), diff --git a/Dockerfile b/pg15/Dockerfile similarity index 100% rename from Dockerfile rename to pg15/Dockerfile diff --git a/Dockerfile-timescaledb b/pg15/Dockerfile-timescaledb similarity index 100% rename from Dockerfile-timescaledb rename to pg15/Dockerfile-timescaledb diff --git a/pg16/Dockerfile b/pg16/Dockerfile new file mode 100644 index 00000000..5a46074d --- /dev/null +++ b/pg16/Dockerfile @@ -0,0 +1,79 @@ +ARG PG_VERSION=16.3 +ARG PG_MAJOR_VERSION=16 +ARG VERSION=custom + +FROM golang:1.20 AS builder + +WORKDIR /go/src/github.com/fly-apps/fly-postgres +COPY . . + +RUN CGO_ENABLED=0 GOOS=linux \ + go build -v -o /fly/bin/event_handler ./cmd/event_handler && \ + go build -v -o /fly/bin/failover_validation ./cmd/failover_validation && \ + go build -v -o /fly/bin/pg_unregister ./cmd/pg_unregister && \ + go build -v -o /fly/bin/start_monitor ./cmd/monitor && \ + go build -v -o /fly/bin/start_admin_server ./cmd/admin_server && \ + go build -v -o /fly/bin/start ./cmd/start + +COPY ./bin/* /fly/bin/ + +FROM ubuntu:24.10 + +ENV PGDATA=/data/postgresql +ENV PGPASSFILE=/data/.pgpass +ARG VERSION +ARG PG_MAJOR_VERSION +ARG POSTGIS_MAJOR=3 +ARG HAPROXY_VERSION=2.9 +ARG REPMGR_VERSION=5.4.1-1build2 + +LABEL fly.app_role=postgres_cluster +LABEL fly.version=${VERSION} +LABEL fly.pg-version=${PG_VERSION} +LABEL fly.pg-manager=repmgr + +RUN apt-get update && apt-get install --no-install-recommends -y \ + ca-certificates iproute2 curl bash dnsutils vim socat procps ssh gnupg rsync barman-cli barman barman-cli-cloud cron gosu \ + && apt autoremove -y && apt clean && \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +# Install PostgreSQL +RUN curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /usr/share/keyrings/postgresql-archive-keyring.gpg && \ + 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 && \ + apt-get update && apt-get install --no-install-recommends -y \ + postgresql-${PG_MAJOR_VERSION} \ + postgresql-client-${PG_MAJOR_VERSION} \ + postgresql-contrib-${PG_MAJOR_VERSION} + +# Repmgr +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 && \ + apt-get install -y ./postgresql-${PG_MAJOR_VERSION}-repmgr_${REPMGR_VERSION}_amd64.deb \ + && rm ./postgresql-${PG_MAJOR_VERSION}-repmgr_${REPMGR_VERSION}_amd64.deb + +# PostGIS +RUN apt-get update && apt-get install --no-install-recommends -y \ + postgresql-${PG_MAJOR_VERSION}-postgis-$POSTGIS_MAJOR \ + postgresql-${PG_MAJOR_VERSION}-postgis-$POSTGIS_MAJOR-scripts + +# Haproxy +RUN apt-get update && apt-get install --no-install-recommends -y \ + haproxy=$HAPROXY_VERSION.\* \ + && apt autoremove -y && apt clean + + +# Add PostgreSQL bin directory to PATH +ENV PATH="/usr/lib/postgresql/${PG_MAJOR_VERSION}/bin:$PATH" + +# Copy Go binaries from the builder stage +COPY --from=builder /fly/bin/* /usr/local/bin + +# Copy Postgres exporter +COPY --from=wrouesnel/postgres_exporter:latest /postgres_exporter /usr/local/bin/ + +ADD /config/* /fly/ +RUN mkdir -p /run/haproxy/ +RUN usermod -d /data postgres + +EXPOSE 5432 + +CMD ["start"] diff --git a/pg16/Dockerfile-timescaledb b/pg16/Dockerfile-timescaledb new file mode 100644 index 00000000..16e79b48 --- /dev/null +++ b/pg16/Dockerfile-timescaledb @@ -0,0 +1,81 @@ +ARG PG_VERSION=15.6 +ARG PG_MAJOR_VERSION=15 +ARG VERSION=custom + +FROM golang:1.20 + +WORKDIR /go/src/github.com/fly-apps/fly-postgres +COPY . . + +RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/event_handler ./cmd/event_handler +RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/failover_validation ./cmd/failover_validation +RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/pg_unregister ./cmd/pg_unregister +RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/start_monitor ./cmd/monitor +RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/start_admin_server ./cmd/admin_server +RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/start ./cmd/start + +COPY ./bin/* /fly/bin/ + +FROM wrouesnel/postgres_exporter:latest AS postgres_exporter + +FROM postgres:${PG_VERSION} +ENV PGDATA=/data/postgresql +ENV PGPASSFILE=/data/.pgpass +ARG VERSION +ARG PG_MAJOR_VERSION +ARG POSTGIS_MAJOR=3 +ARG HAPROXY_VERSION=2.8 + +LABEL fly.app_role=postgres_cluster +LABEL fly.version=${VERSION} +LABEL fly.pg-version=${PG_VERSION} +LABEL fly.pg-manager=repmgr + +RUN apt-get update && apt-get install --no-install-recommends -y \ + ca-certificates iproute2 curl bash dnsutils vim haproxy socat procps ssh gnupg rsync barman-cli barman barman-cli-cloud cron \ + && apt autoremove -y + +# Repmgr +RUN curl -L https://launchpad.net/ubuntu/+archive/primary/+files/postgresql-${PG_MAJOR_VERSION}-repmgr_5.3.3-2_amd64.deb -o postgresql-${PG_MAJOR_VERSION}-repmgr_5.3.3-2_amd64.deb + +RUN apt-get update && \ + apt-get install -y ./postgresql-${PG_MAJOR_VERSION}-repmgr_5.3.3-2_amd64.deb \ + && rm ./postgresql-${PG_MAJOR_VERSION}-repmgr_5.3.3-2_amd64.deb + +RUN echo "deb https://packagecloud.io/timescale/timescaledb/debian/ $(cat /etc/os-release | grep VERSION_CODENAME | cut -d'=' -f2) main" > /etc/apt/sources.list.d/timescaledb.list \ + && curl -L https://packagecloud.io/timescale/timescaledb/gpgkey | apt-key add - + +# TimescaleDB and PostGIS +RUN apt-get update && apt-get install --no-install-recommends -y \ + postgresql-$PG_MAJOR_VERSION-postgis-$POSTGIS_MAJOR \ + postgresql-$PG_MAJOR_VERSION-postgis-$POSTGIS_MAJOR-scripts \ + timescaledb-2-postgresql-$PG_MAJOR_VERSION \ + timescaledb-toolkit-postgresql-$PG_MAJOR_VERSION \ + && apt autoremove -y + +# Haproxy +RUN curl https://haproxy.debian.net/bernat.debian.org.gpg \ + | gpg --dearmor > /usr/share/keyrings/haproxy.debian.net.gpg + +RUN echo deb "[signed-by=/usr/share/keyrings/haproxy.debian.net.gpg]" \ + http://haproxy.debian.net bookworm-backports-${HAPROXY_VERSION} main \ + > /etc/apt/sources.list.d/haproxy.list + +RUN apt-get update && apt-get install --no-install-recommends -y \ + haproxy=$HAPROXY_VERSION.\* \ + && apt autoremove -y + +COPY --from=0 /fly/bin/* /usr/local/bin +COPY --from=postgres_exporter /postgres_exporter /usr/local/bin/ + +ADD /config/* /fly/ + +RUN mkdir -p /run/haproxy/ +RUN usermod -d /data postgres + +ENV TIMESCALEDB_ENABLED=true + +EXPOSE 5432 + + +CMD ["start"]