|
| 1 | +ARG postgres_version=15.1.0.83 |
| 2 | + |
| 3 | +ARG pgbouncer_release=1.18.0 |
| 4 | +ARG postgrest_release=10.1.2 |
| 5 | +ARG gotrue_release=2.47.0 |
| 6 | +ARG kong_release=2.8.1 |
| 7 | +ARG adminapi_release=0.44.3 |
| 8 | +ARG adminmgr_release=0.4.0 |
| 9 | +ARG vector_release=0.22.3 |
| 10 | +ARG postgres_exporter_release=0.9.0 |
| 11 | + |
| 12 | +FROM supabase/postgres:${postgres_version} as base |
| 13 | +ARG TARGETARCH |
| 14 | +ARG postgresql_major |
| 15 | + |
| 16 | +FROM base as builder |
| 17 | +# Install build dependencies |
| 18 | +RUN apt-get update && apt-get install -y \ |
| 19 | + postgresql-server-dev-${postgresql_major} \ |
| 20 | + build-essential \ |
| 21 | + checkinstall \ |
| 22 | + pkg-config \ |
| 23 | + cmake \ |
| 24 | + && rm -rf /var/lib/apt/lists/* |
| 25 | + |
| 26 | +#################### |
| 27 | +# Install pgbouncer |
| 28 | +#################### |
| 29 | +FROM builder as pgbouncer-source |
| 30 | +# Download and extract |
| 31 | +ARG pgbouncer_release |
| 32 | +ADD "https://www.pgbouncer.org/downloads/files/${pgbouncer_release}/pgbouncer-${pgbouncer_release}.tar.gz" /tmp/pgbouncer.tar.gz |
| 33 | +RUN tar -xvf /tmp/pgbouncer.tar.gz -C /tmp && \ |
| 34 | + rm -rf /tmp/pgbouncer.tar.gz |
| 35 | +# Install build dependencies |
| 36 | +RUN apt-get update && apt-get install -y \ |
| 37 | + libevent-dev \ |
| 38 | + && rm -rf /var/lib/apt/lists/* |
| 39 | +# Build from source |
| 40 | +WORKDIR /tmp/pgbouncer-${pgbouncer_release} |
| 41 | +RUN ./configure --prefix=/usr/local |
| 42 | +RUN make -j$(nproc) |
| 43 | +# Create debian package |
| 44 | +RUN checkinstall -D --install=no --fstrans=no --backup=no --pakdir=/tmp --requires=libevent-2.1-7 --nodoc |
| 45 | + |
| 46 | +FROM base as pgbouncer |
| 47 | +# Download pre-built packages |
| 48 | +RUN apt-get update && apt-get install -y --no-install-recommends --download-only \ |
| 49 | + pgbouncer \ |
| 50 | + && rm -rf /var/lib/apt/lists/* |
| 51 | +RUN mv /var/cache/apt/archives/*.deb /tmp/ |
| 52 | + |
| 53 | +#################### |
| 54 | +# Install PostgREST |
| 55 | +#################### |
| 56 | +FROM postgrest/postgrest:v${postgrest_release} as pgrst |
| 57 | + |
| 58 | +#################### |
| 59 | +# Install GoTrue |
| 60 | +#################### |
| 61 | +FROM supabase/gotrue:v${gotrue_release} as gotrue |
| 62 | + |
| 63 | +#################### |
| 64 | +# Install Kong |
| 65 | +#################### |
| 66 | +FROM base as kong |
| 67 | +ARG kong_release |
| 68 | +ADD "https://download.konghq.com/gateway-2.x-ubuntu-focal/pool/all/k/kong/kong_${kong_release}_${TARGETARCH}.deb" \ |
| 69 | + /tmp/kong.deb |
| 70 | + |
| 71 | +#################### |
| 72 | +# Install admin api |
| 73 | +#################### |
| 74 | +FROM base as adminapi |
| 75 | +ARG adminapi_release |
| 76 | +ADD "https://supabase-public-artifacts-bucket.s3.amazonaws.com/supabase-admin-api/v${adminapi_release}/supabase-admin-api_${adminapi_release}_linux_${TARGETARCH}.tar.gz" /tmp/supabase-admin-api.tar.gz |
| 77 | +RUN tar -xvf /tmp/supabase-admin-api.tar.gz -C /tmp && \ |
| 78 | + rm -rf /tmp/supabase-admin-api.tar.gz |
| 79 | + |
| 80 | +#################### |
| 81 | +# Install admin mgr |
| 82 | +#################### |
| 83 | +FROM base as adminmgr |
| 84 | +ARG adminmgr_release |
| 85 | +ADD "https://supabase-public-artifacts-bucket.s3.amazonaws.com/admin-mgr/v${adminmgr_release}/admin-mgr_${adminmgr_release}_linux_${TARGETARCH}.tar.gz" /tmp/admin-mgr.tar.gz |
| 86 | +RUN tar -xvf /tmp/admin-mgr.tar.gz -C /tmp && \ |
| 87 | + rm -rf /tmp/admin-mgr.tar.gz |
| 88 | + |
| 89 | +#################### |
| 90 | +# Install Prometheus Exporter |
| 91 | +#################### |
| 92 | +FROM base as exporter |
| 93 | +ARG postgres_exporter_release |
| 94 | +ADD "https://github.com/prometheus-community/postgres_exporter/releases/download/v${postgres_exporter_release}/postgres_exporter-${postgres_exporter_release}.linux-${TARGETARCH}.tar.gz" /tmp/postgres_exporter.tar.gz |
| 95 | +RUN tar -xvf /tmp/postgres_exporter.tar.gz -C /tmp --strip-components 1 && \ |
| 96 | + rm -rf /tmp/postgres_exporter.tar.gz |
| 97 | + |
| 98 | +#################### |
| 99 | +# Install vector |
| 100 | +#################### |
| 101 | +FROM base as vector |
| 102 | +ARG vector_release |
| 103 | +ADD "https://packages.timber.io/vector/${vector_release}/vector_${vector_release}-1_${TARGETARCH}.deb" /tmp/vector.deb |
| 104 | + |
| 105 | +#################### |
| 106 | +# Install supervisord |
| 107 | +#################### |
| 108 | +FROM base as supervisor |
| 109 | +# Download pre-built packages |
| 110 | +RUN apt-get update -y && apt-get install -y --no-install-recommends --download-only \ |
| 111 | + supervisor \ |
| 112 | + && rm -rf /var/lib/apt/lists/* |
| 113 | +RUN mv /var/cache/apt/archives/*.deb /tmp/ |
| 114 | + |
| 115 | +#################### |
| 116 | +# Create the final image for production |
| 117 | +#################### |
| 118 | +FROM base as production |
| 119 | + |
| 120 | +# Copy dependencies from previous build stages |
| 121 | +COPY --from=pgbouncer /tmp/*.deb /tmp/ |
| 122 | +COPY --from=vector /tmp/*.deb /tmp/ |
| 123 | +COPY --from=kong /tmp/*.deb /tmp/ |
| 124 | +COPY --from=supervisor /tmp/*.deb /tmp/ |
| 125 | + |
| 126 | +# Install runtime dependencies |
| 127 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 128 | + /tmp/*.deb \ |
| 129 | + # For health check |
| 130 | + curl \ |
| 131 | + # For parsing init payload |
| 132 | + jq \ |
| 133 | + # Security tools |
| 134 | + fail2ban \ |
| 135 | + # sudo |
| 136 | + sudo \ |
| 137 | + # reading files using cat sucks |
| 138 | + less \ |
| 139 | + && rm -rf /var/lib/apt/lists/* /tmp/* |
| 140 | + |
| 141 | +# Copy single binary dependencies |
| 142 | +COPY --from=pgrst /bin/postgrest /opt/ |
| 143 | +COPY --from=gotrue /usr/local/bin/gotrue /opt/gotrue/ |
| 144 | +COPY --from=gotrue /usr/local/etc/gotrue /opt/gotrue/ |
| 145 | +COPY --from=adminapi /tmp/supabase-admin-api /opt/ |
| 146 | +COPY --chown=root:root --from=adminmgr /tmp/admin-mgr /usr/bin/ |
| 147 | +COPY --from=exporter /tmp/postgres_exporter /opt/postgres_exporter/ |
| 148 | +COPY docker/all-in-one/opt/postgres_exporter /opt/postgres_exporter/ |
| 149 | + |
| 150 | +# Scripts for adminapi |
| 151 | +COPY ansible/files/admin_api_scripts /root |
| 152 | +COPY --chown=adminapi:adminapi docker/all-in-one/etc/adminapi /etc/adminapi |
| 153 | +COPY docker/all-in-one/etc/sudoers.d /etc/sudoers.d/ |
| 154 | + |
| 155 | +# Customizations for pgbouncer |
| 156 | +COPY docker/all-in-one/etc/pgbouncer /etc/pgbouncer |
| 157 | +COPY docker/all-in-one/etc/pgbouncer-custom /etc/pgbouncer-custom |
| 158 | +COPY docker/all-in-one/etc/tmpfiles.d /etc/tmpfiles.d |
| 159 | + |
| 160 | +# Customizations for postgres |
| 161 | +COPY --chown=postgres:postgres docker/all-in-one/etc/postgresql/pg_hba.conf /etc/postgresql/ |
| 162 | +COPY --chown=postgres:postgres docker/all-in-one/etc/postgresql/logging.conf /etc/postgresql/ |
| 163 | +COPY --chown=postgres:postgres docker/all-in-one/etc/postgresql-custom /etc/postgresql-custom |
| 164 | +COPY --chown=postgres:postgres docker/all-in-one/etc/postgresql.schema.sql /etc/postgresql.schema.sql |
| 165 | + |
| 166 | +# Customizations for postgres_exporter |
| 167 | +COPY --chown=postgres:postgres docker/all-in-one/opt/postgres_exporter/queries.yml /opt/postgres_exporter/queries.yml |
| 168 | + |
| 169 | +COPY docker/all-in-one/etc/fail2ban/filter.d /etc/fail2ban/filter.d/ |
| 170 | +COPY docker/all-in-one/etc/fail2ban/jail.d /etc/fail2ban/jail.d/ |
| 171 | + |
| 172 | +# Customizations for postgrest |
| 173 | +COPY --chown=postgrest:postgrest docker/all-in-one/etc/postgrest/base.conf /etc/postgrest/base.conf |
| 174 | +COPY --chown=postgrest:postgrest docker/all-in-one/etc/postgrest/generated.conf /etc/postgrest/generated.conf |
| 175 | + |
| 176 | +# Customizations for gotrue |
| 177 | +COPY docker/all-in-one/etc/gotrue.env /etc/gotrue.env |
| 178 | + |
| 179 | +# Customizations for kong |
| 180 | +COPY docker/all-in-one/etc/kong/kong.conf /etc/kong/kong.conf |
| 181 | +COPY docker/all-in-one/etc/kong/kong.yml /etc/kong/kong.yml |
| 182 | + |
| 183 | +# Customizations for vector |
| 184 | +COPY --chown=vector:vector docker/all-in-one/etc/vector/vector.yaml /etc/vector/vector.yaml |
| 185 | + |
| 186 | +# Customizations for supervisor |
| 187 | +COPY docker/all-in-one/etc/supervisor /etc/supervisor |
| 188 | + |
| 189 | +# Configure service ports |
| 190 | +ENV PGRST_SERVER_PORT=3000 |
| 191 | +ENV PGRST_ADMIN_SERVER_PORT=3001 |
| 192 | +EXPOSE ${PGRST_SERVER_PORT} |
| 193 | + |
| 194 | +ENV GOTRUE_SITE_URL=http://localhost:${PGRST_SERVER_PORT} |
| 195 | +ENV GOTRUE_API_PORT=9999 |
| 196 | +EXPOSE ${GOTRUE_API_PORT} |
| 197 | + |
| 198 | +ENV KONG_HTTP_PORT=8000 |
| 199 | +ENV KONG_HTTPS_PORT=8443 |
| 200 | +EXPOSE ${KONG_HTTP_PORT} ${KONG_HTTPS_PORT} |
| 201 | + |
| 202 | +ENV ADMIN_API_CERT_DIR=/etc/ssl/adminapi |
| 203 | +ENV ADMIN_API_PORT=8085 |
| 204 | +EXPOSE ${ADMIN_API_PORT} |
| 205 | + |
| 206 | +ENV PGBOUNCER_PORT=6543 |
| 207 | +EXPOSE ${PGBOUNCER_PORT} |
| 208 | + |
| 209 | +ENV PGEXPORTER_PORT=9187 |
| 210 | +EXPOSE ${PGEXPORTER_PORT} |
| 211 | + |
| 212 | +ENV VECTOR_API_PORT=9001 |
| 213 | + |
| 214 | +# Create system users |
| 215 | +RUN useradd --create-home --shell /bin/bash postgrest && \ |
| 216 | + useradd --create-home --shell /bin/bash gotrue && \ |
| 217 | + useradd --create-home --shell /bin/bash pgbouncer -G postgres,ssl-cert && \ |
| 218 | + # root,admin,kong,pgbouncer,postgres,postgrest,systemd-journal,wal-g |
| 219 | + useradd --create-home --shell /bin/bash adminapi -G root,kong,pgbouncer,postgres,postgrest,wal-g && \ |
| 220 | + usermod --append --shell /bin/bash -G postgres vector |
| 221 | +RUN mkdir -p /etc/wal-g && \ |
| 222 | + chown -R adminapi:adminapi /etc/wal-g && \ |
| 223 | + chmod g+w /etc/wal-g |
| 224 | +RUN mkdir -p /var/log/wal-g && chmod +x /usr/bin/admin-mgr && chmod ug+s /usr/bin/admin-mgr && touch /etc/wal-g/config.json && chown adminapi:adminapi /etc/wal-g/config.json |
| 225 | +RUN chown -R adminapi:adminapi /etc/adminapi |
| 226 | + |
| 227 | + |
| 228 | +# Add healthcheck and entrypoint scripts |
| 229 | +COPY docker/all-in-one/healthcheck.sh /usr/local/bin/ |
| 230 | +HEALTHCHECK --interval=3s --timeout=2s --start-period=4s --retries=10 CMD [ "healthcheck.sh" ] |
| 231 | + |
| 232 | +COPY docker/all-in-one/init /init |
| 233 | +COPY docker/all-in-one/entrypoint.sh /usr/local/bin/ |
| 234 | +ENTRYPOINT [ "entrypoint.sh" ] |
0 commit comments