|
| 1 | +ARG PG_VERSION=17.2 |
| 2 | +ARG PG_MAJOR_VERSION=17 |
| 3 | +ARG VERSION=custom |
| 4 | + |
| 5 | +FROM golang:1.23 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 | +ARG VERSION |
| 25 | +ARG PG_MAJOR_VERSION |
| 26 | +ARG PG_VERSION |
| 27 | +ARG POSTGIS_MAJOR=3 |
| 28 | +ARG HAPROXY_VERSION=2.8 |
| 29 | +ARG REPMGR_VERSION=5.5.0+debpgdg-1.pgdg24.04+1 |
| 30 | + |
| 31 | +ENV PGDATA=/data/postgresql |
| 32 | +ENV PGPASSFILE=/data/.pgpass |
| 33 | +ENV AWS_SHARED_CREDENTIALS_FILE=/data/.aws/credentials |
| 34 | +ENV PG_MAJOR_VERSION=${PG_MAJOR_VERSION} |
| 35 | +ENV PATH="/usr/lib/postgresql/${PG_MAJOR_VERSION}/bin:$PATH" |
| 36 | + |
| 37 | +LABEL fly.app_role=postgres_cluster |
| 38 | +LABEL fly.version=${VERSION} |
| 39 | +LABEL fly.pg-version=${PG_VERSION} |
| 40 | +LABEL fly.pg-manager=repmgr |
| 41 | + |
| 42 | +# make the "en_US.UTF-8" locale so postgres will be utf-8 enabled by default |
| 43 | +RUN set -eux; \ |
| 44 | + if [ -f /etc/dpkg/dpkg.cfg.d/docker ]; then \ |
| 45 | + # if this file exists, we're likely in "debian:xxx-slim", and locales are thus being excluded so we need to remove that exclusion (since we need locales) |
| 46 | + grep -q '/usr/share/locale' /etc/dpkg/dpkg.cfg.d/docker; \ |
| 47 | + sed -ri '/\/usr\/share\/locale/d' /etc/dpkg/dpkg.cfg.d/docker; \ |
| 48 | + ! grep -q '/usr/share/locale' /etc/dpkg/dpkg.cfg.d/docker; \ |
| 49 | + fi; \ |
| 50 | + apt-get update; apt-get install -y --no-install-recommends locales; rm -rf /var/lib/apt/lists/*; \ |
| 51 | + echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen; \ |
| 52 | + locale-gen; \ |
| 53 | + locale -a | grep 'en_US.utf8' |
| 54 | +ENV LANG en_US.utf8 |
| 55 | + |
| 56 | +RUN apt-get update && apt-get install --no-install-recommends -y \ |
| 57 | + ca-certificates iproute2 curl bash dnsutils vim socat procps ssh gnupg rsync barman-cli barman barman-cli-cloud python3-setuptools cron gosu \ |
| 58 | + && apt autoremove -y && apt clean && \ |
| 59 | + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* |
| 60 | + |
| 61 | +# Install PostgreSQL |
| 62 | +RUN curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /usr/share/keyrings/postgresql-archive-keyring.gpg && \ |
| 63 | + 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 && \ |
| 64 | + apt-get update && apt-get install --no-install-recommends -y \ |
| 65 | + postgresql-${PG_MAJOR_VERSION} \ |
| 66 | + postgresql-client-${PG_MAJOR_VERSION} \ |
| 67 | + postgresql-contrib-${PG_MAJOR_VERSION} \ |
| 68 | + postgresql-${PG_MAJOR_VERSION}-repmgr=${REPMGR_VERSION} |
| 69 | + |
| 70 | +# TimescaleDB and PostGIS |
| 71 | +RUN echo "deb https://packagecloud.io/timescale/timescaledb/ubuntu/ jammy main" > /etc/apt/sources.list.d/timescaledb.list \ |
| 72 | + && curl -L https://packagecloud.io/timescale/timescaledb/gpgkey | apt-key add - |
| 73 | + |
| 74 | +RUN apt-get update && apt-get install --no-install-recommends -y \ |
| 75 | + postgresql-$PG_MAJOR_VERSION-postgis-$POSTGIS_MAJOR \ |
| 76 | + postgresql-$PG_MAJOR_VERSION-postgis-$POSTGIS_MAJOR-scripts \ |
| 77 | + timescaledb-2-postgresql-$PG_MAJOR_VERSION \ |
| 78 | + && apt autoremove -y && apt clean |
| 79 | + |
| 80 | +# Haproxy |
| 81 | +RUN apt-get update && apt-get install --no-install-recommends -y \ |
| 82 | + haproxy=$HAPROXY_VERSION.\* \ |
| 83 | + && apt autoremove -y && apt clean |
| 84 | + |
| 85 | +# Copy Go binaries from the builder stage |
| 86 | +COPY --from=builder /fly/bin/* /usr/local/bin |
| 87 | + |
| 88 | +# Copy Postgres exporter |
| 89 | +COPY --from=wrouesnel/postgres_exporter:latest /postgres_exporter /usr/local/bin/ |
| 90 | + |
| 91 | +# Move pg_rewind into path. |
| 92 | +RUN ln -s /usr/lib/postgresql/${PG_MAJOR_VERSION}/bin/pg_rewind /usr/bin/pg_rewind |
| 93 | + |
| 94 | +ADD /config/* /fly/ |
| 95 | +RUN mkdir -p /run/haproxy/ |
| 96 | +RUN usermod -d /data postgres |
| 97 | + |
| 98 | +ENV TIMESCALEDB_ENABLED=true |
| 99 | + |
| 100 | +EXPOSE 5432 |
| 101 | + |
| 102 | +CMD ["start"] |
0 commit comments