Skip to content

Commit 1d6d075

Browse files
committed
feat: use smaller supabase postgres and restrict started projects
adds a new --small flag to only startup postgres, kong, auth and postgrest as a PoC on how a smaller setup could look like. Note: relies on the existance of the image built by supabase/postgres#2009
1 parent c4b381a commit 1d6d075

3 files changed

Lines changed: 44 additions & 4 deletions

File tree

cmd/start.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
)
1515

1616
func validateExcludedContainers(excludedContainers []string) {
17-
// Validate excluded containers
1817
validContainers := start.ExcludableContainers()
1918
var invalidContainers []string
2019

@@ -25,7 +24,7 @@ func validateExcludedContainers(excludedContainers []string) {
2524
}
2625

2726
if len(invalidContainers) > 0 {
28-
// Sort the names list so it's easier to visually spot the one you looking for
27+
// Sort the names list so it's easier to visually spot the one you're looking for
2928
sort.Strings(validContainers)
3029
warning := fmt.Sprintf("%s The following container names are not valid to exclude: %s\nValid containers to exclude are: %s\n",
3130
utils.Yellow("WARNING:"),
@@ -40,14 +39,15 @@ var (
4039
excludedContainers []string
4140
ignoreHealthCheck bool
4241
preview bool
42+
small bool
4343

4444
startCmd = &cobra.Command{
4545
GroupID: groupLocalDev,
4646
Use: "start",
4747
Short: "Start containers for Supabase local development",
4848
RunE: func(cmd *cobra.Command, args []string) error {
4949
validateExcludedContainers(excludedContainers)
50-
return start.Run(cmd.Context(), afero.NewOsFs(), excludedContainers, ignoreHealthCheck)
50+
return start.Run(cmd.Context(), afero.NewOsFs(), excludedContainers, ignoreHealthCheck, small)
5151
},
5252
}
5353
)
@@ -58,6 +58,7 @@ func init() {
5858
flags.StringSliceVarP(&excludedContainers, "exclude", "x", []string{}, "Names of containers to not start. ["+names+"]")
5959
flags.BoolVar(&ignoreHealthCheck, "ignore-health-check", false, "Ignore unhealthy services and exit 0")
6060
flags.BoolVar(&preview, "preview", false, "Connect to feature preview branch")
61+
flags.BoolVar(&small, "small", false, "Use "+start.SmallImageName+" image")
6162
cobra.CheckErr(flags.MarkHidden("preview"))
6263
rootCmd.AddCommand(startCmd)
6364
}

internal/start/start.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,47 @@ import (
4444
"github.com/supabase/cli/pkg/config"
4545
)
4646

47-
func Run(ctx context.Context, fsys afero.Fs, excludedContainers []string, ignoreHealthCheck bool) error {
47+
const (
48+
SmallImageName = "supabase/postgres:minimal"
49+
graphqlPublicSchema = "graphql_public"
50+
)
51+
52+
// configureSmallMode configures the system for minimal resource usage by:
53+
// - Using a smaller PostgreSQL image (minimal)
54+
// - Disabling non-essential services (keeps only kong, postgrest, and auth)
55+
// - Removing graphql_public schema from API schemas
56+
func configureSmallMode() {
57+
utils.Config.Db.Image = SmallImageName
58+
59+
// Disable all services except kong, postgrest, and auth
60+
// This ensures they won't be pulled or started regardless of config.toml settings
61+
utils.Config.Realtime.Enabled = false
62+
utils.Config.Storage.Enabled = false
63+
utils.Config.Inbucket.Enabled = false
64+
utils.Config.Studio.Enabled = false
65+
utils.Config.EdgeRuntime.Enabled = false
66+
utils.Config.Analytics.Enabled = false
67+
utils.Config.Db.Pooler.Enabled = false
68+
69+
// Remove graphql_public schema from API schemas when using --small
70+
filteredSchemas := make([]string, 0, len(utils.Config.Api.Schemas))
71+
for _, schema := range utils.Config.Api.Schemas {
72+
if schema != graphqlPublicSchema {
73+
filteredSchemas = append(filteredSchemas, schema)
74+
}
75+
}
76+
utils.Config.Api.Schemas = filteredSchemas
77+
}
78+
79+
func Run(ctx context.Context, fsys afero.Fs, excludedContainers []string, ignoreHealthCheck bool, useSmallImage bool) error {
4880
// Sanity checks.
4981
{
5082
if err := flags.LoadConfig(fsys); err != nil {
5183
return err
5284
}
85+
if useSmallImage {
86+
configureSmallMode()
87+
}
5388
if err := utils.AssertSupabaseDbIsRunning(); err == nil {
5489
fmt.Fprintln(os.Stderr, utils.Aqua("supabase start")+" is already running.")
5590
names := status.CustomName{}

internal/utils/docker.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ func GetRegistryImageUrl(imageName string) string {
199199
if registry == "docker.io" {
200200
return imageName
201201
}
202+
// Skip registry transformation for minimal images (pulled locally from Docker Hub)
203+
if strings.Contains(imageName, "minimal") {
204+
return imageName
205+
}
202206
// Configure mirror registry
203207
parts := strings.Split(imageName, "/")
204208
imageName = parts[len(parts)-1]

0 commit comments

Comments
 (0)