Skip to content

Commit 1c4ad2a

Browse files
committed
build(postgres): add SUPABASE_POSTGRES_TAG support for image builds
Introduces the SUPABASE_POSTGRES_TAG variable to allow explicit control over the Supabase Postgres base image tag in Docker builds. Updates the Makefile, Dockerfile, and documentation to support and document this new build argument, improving flexibility for building custom images.
1 parent 0d3b3fa commit 1c4ad2a

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

docker/Makefile.postgresql

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ DOCKER_TAG ?= latest
123123
DOCKER_BUILD_ARGS ?=
124124
SUPABASE_CLI_IMAGE ?= $(shell docker ps --format '{{.Image}} {{.Names}}' | awk '/supabase_db/ {print $$1; exit}')
125125
SUPABASE_CLI_DOCKERFILE ?= docker/postgresql/Dockerfile.supabase
126+
SUPABASE_POSTGRES_TAG ?= 17.6.1.071
126127
SUPABASE_WORKDIR ?=
127128
SUPABASE_WORKDIR_ARG = $(if $(SUPABASE_WORKDIR),--workdir $(SUPABASE_WORKDIR),)
128129
SUPABASE_DB_HOST ?= 127.0.0.1
@@ -237,13 +238,17 @@ postgres-docker-shell:
237238
# Build CloudSync into the Supabase CLI postgres image tag
238239
postgres-supabase-build:
239240
@echo "Building CloudSync image for Supabase CLI..."
240-
@if [ -z "$(SUPABASE_CLI_IMAGE)" ]; then \
241+
@tmp_dockerfile="$$(mktemp /tmp/cloudsync-supabase-cli.XXXXXX)"; \
242+
src_dockerfile="$(SUPABASE_CLI_DOCKERFILE)"; \
243+
supabase_cli_image="$(SUPABASE_CLI_IMAGE)"; \
244+
if [ -z "$$supabase_cli_image" ]; then \
245+
supabase_cli_image="public.ecr.aws/supabase/postgres:$(SUPABASE_POSTGRES_TAG)"; \
246+
fi; \
247+
if [ -z "$$supabase_cli_image" ]; then \
241248
echo "Error: Supabase CLI postgres image not found."; \
242249
echo "Run 'supabase start' first, or set SUPABASE_CLI_IMAGE=public.ecr.aws/supabase/postgres:<tag>."; \
243250
exit 1; \
244-
fi
245-
@tmp_dockerfile="$$(mktemp /tmp/cloudsync-supabase-cli.XXXXXX)"; \
246-
src_dockerfile="$(SUPABASE_CLI_DOCKERFILE)"; \
251+
fi; \
247252
if [ ! -f "$$src_dockerfile" ]; then \
248253
if [ -f "docker/postgresql/Dockerfile.supabase" ]; then \
249254
src_dockerfile="docker/postgresql/Dockerfile.supabase"; \
@@ -253,18 +258,18 @@ postgres-supabase-build:
253258
exit 1; \
254259
fi; \
255260
fi; \
256-
sed -e "s|^FROM supabase/postgres:[^ ]*|FROM $(SUPABASE_CLI_IMAGE)|" \
257-
-e "s|^FROM public.ecr.aws/supabase/postgres:[^ ]*|FROM $(SUPABASE_CLI_IMAGE)|" \
261+
sed -e "s|^FROM supabase/postgres:[^ ]*|FROM $$supabase_cli_image|" \
262+
-e "s|^FROM public.ecr.aws/supabase/postgres:[^ ]*|FROM $$supabase_cli_image|" \
258263
"$$src_dockerfile" > "$$tmp_dockerfile"; \
259264
if [ ! -s "$$tmp_dockerfile" ]; then \
260265
echo "Error: Generated Dockerfile is empty."; \
261266
rm -f "$$tmp_dockerfile"; \
262267
exit 1; \
263268
fi; \
264-
echo "Using base image: $(SUPABASE_CLI_IMAGE)"; \
265-
docker build -f "$$tmp_dockerfile" -t "$(SUPABASE_CLI_IMAGE)" .; \
269+
echo "Using base image: $$supabase_cli_image"; \
270+
docker build --build-arg SUPABASE_POSTGRES_TAG="$(SUPABASE_POSTGRES_TAG)" -f "$$tmp_dockerfile" -t "$$supabase_cli_image" .; \
266271
rm -f "$$tmp_dockerfile"; \
267-
echo "Build complete: $(SUPABASE_CLI_IMAGE)"
272+
echo "Build complete: $$supabase_cli_image"
268273

269274
# Rebuild CloudSync image and restart Supabase CLI stack
270275
postgres-supabase-rebuild: postgres-supabase-build

docker/README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,17 @@ enabling the extension in the CLI-managed Postgres container.
136136
make postgres-supabase-build
137137
```
138138
This auto-detects the running `supabase_db` image tag and rebuilds it with
139-
CloudSync installed. If you need to override the tag, set
139+
CloudSync installed. If you need to override the full image tag, set
140140
`SUPABASE_CLI_IMAGE=public.ecr.aws/supabase/postgres:<tag>`.
141141
Example:
142142
```bash
143143
SUPABASE_CLI_IMAGE=public.ecr.aws/supabase/postgres:17.6.1.071 make postgres-supabase-build
144144
```
145+
You can also set the Supabase base image tag explicitly (defaults to
146+
`17.6.1.071`). This only affects the base image used in the Dockerfile:
147+
```bash
148+
SUPABASE_POSTGRES_TAG=17.6.1.071 make postgres-supabase-build
149+
```
145150

146151
4. Restart the stack:
147152
```bash
@@ -156,7 +161,10 @@ manually.
156161

157162
Migration-based (notes for CLI): Supabase CLI migrations run as the `postgres`
158163
role, which cannot create C extensions by default. Use manual enable or grant
159-
`USAGE` on language `c` once, then migrations will work.
164+
`USAGE` on language `c` once, then migrations will work. Note: `c` is an
165+
untrusted language, so `GRANT USAGE ON LANGUAGE c` is only allowed for
166+
superusers. On the CLI/local stack, the simplest approach is to enable the
167+
extension manually as `supabase_admin` after `supabase db reset`.
160168

161169
If you still want a migration file, add:
162170
```bash

docker/postgresql/Dockerfile.supabase

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Build stage for CloudSync extension (match Supabase runtime)
2-
FROM public.ecr.aws/supabase/postgres:17.6.1.071 AS cloudsync-builder
2+
ARG SUPABASE_POSTGRES_TAG=17.6.1.071
3+
FROM public.ecr.aws/supabase/postgres:${SUPABASE_POSTGRES_TAG} AS cloudsync-builder
34

45
# Install build dependencies
56
RUN apt-get update && apt-get install -y \
@@ -32,7 +33,8 @@ RUN mkdir -p /tmp/cloudsync-artifacts/lib /tmp/cloudsync-artifacts/extension &&
3233
cp /tmp/cloudsync/docker/postgresql/cloudsync.control /tmp/cloudsync-artifacts/extension/
3334

3435
# Runtime image based on Supabase Postgres
35-
FROM public.ecr.aws/supabase/postgres:17.6.1.071
36+
ARG SUPABASE_POSTGRES_TAG=17.6.1.071
37+
FROM public.ecr.aws/supabase/postgres:${SUPABASE_POSTGRES_TAG}
3638

3739
# Match builder pg_config path
3840
ENV CLOUDSYNC_PG_CONFIG=/root/.nix-profile/bin/pg_config

0 commit comments

Comments
 (0)