/** * Opt-in Postgres image with hypopg + index_advisor (PGXS). * * Pin `oke-postgres-advisor:18-alpine` — do not change the default * `postgres:18-alpine` pull. Driver id stays `postgres`. */ import { POSTGRES_STAT_STATEMENTS_COMMAND, postgresEnv, postgresHealth } from "../helpers.ts"; import type { ImageRecipe } from "../types.ts"; /** Compose-dir Dockerfile name emitted by `oke docker`. */ export const POSTGRES_ADVISOR_DOCKERFILE = "Dockerfile.postgres-advisor"; /** Local image tag operators pin as `images["store.sql"]`. */ export const POSTGRES_ADVISOR_IMAGE = "oke-postgres-advisor:18-alpine"; /** HypoPG git tag (C/PGXS). */ export const HYPOPG_GIT_TAG = "1.4.1"; /** index_advisor git tag (DATA-only PGXS). */ export const INDEX_ADVISOR_GIT_TAG = "0.2.0"; /** * Dockerfile that extends official Alpine Postgres with advisor extensions. * * @param baseImage - Official postgres alpine tag */ export function emitPostgresAdvisorDockerfile(baseImage: string = "postgres:18-alpine"): string { return `# generated by oke docker — do not edit FROM ${baseImage} ARG DOCKER_PG_LLVM_DEPS="llvm19-dev clang19" RUN apk add --no-cache --virtual .build-deps \\ $DOCKER_PG_LLVM_DEPS \\ build-base \\ git \\ && git clone --depth 1 --branch ${HYPOPG_GIT_TAG} https://github.com/HypoPG/hypopg.git /tmp/hypopg \\ && make -C /tmp/hypopg && make -C /tmp/hypopg install \\ && git clone --depth 1 --branch ${INDEX_ADVISOR_GIT_TAG} https://github.com/supabase/index_advisor.git /tmp/index_advisor \\ && make -C /tmp/index_advisor install \\ && apk del --no-network .build-deps \\ && rm -rf /tmp/hypopg /tmp/index_advisor `; } /** Opt-in advisor Postgres — matched ahead of generic postgres. */ export const postgresAdvisor: ImageRecipe = { id: "postgres-advisor", port: 5432, match: (i) => /oke-postgres-advisor|postgres-advisor/i.test(i), apply: (s) => ({ environment: postgresEnv(s), healthcheck: postgresHealth, command: [...POSTGRES_STAT_STATEMENTS_COMMAND], build: { context: ".", dockerfile: POSTGRES_ADVISOR_DOCKERFILE }, }), url: (_s, c) => `postgres://${c.user}:${encodeURIComponent(c.password)}@${c.host}:${c.port}/${c.database}`, };