diff --git a/cmd/start.go b/cmd/start.go index bd1cc1f8a..21fec138c 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -14,7 +14,6 @@ import ( ) func validateExcludedContainers(excludedContainers []string) { - // Validate excluded containers validContainers := start.ExcludableContainers() var invalidContainers []string @@ -25,7 +24,7 @@ func validateExcludedContainers(excludedContainers []string) { } if len(invalidContainers) > 0 { - // Sort the names list so it's easier to visually spot the one you looking for + // Sort the names list so it's easier to visually spot the one you're looking for sort.Strings(validContainers) warning := fmt.Sprintf("%s The following container names are not valid to exclude: %s\nValid containers to exclude are: %s\n", utils.Yellow("WARNING:"), @@ -40,6 +39,7 @@ var ( excludedContainers []string ignoreHealthCheck bool preview bool + small bool startCmd = &cobra.Command{ GroupID: groupLocalDev, @@ -47,7 +47,7 @@ var ( Short: "Start containers for Supabase local development", RunE: func(cmd *cobra.Command, args []string) error { validateExcludedContainers(excludedContainers) - return start.Run(cmd.Context(), afero.NewOsFs(), excludedContainers, ignoreHealthCheck) + return start.Run(cmd.Context(), afero.NewOsFs(), excludedContainers, ignoreHealthCheck, small) }, } ) @@ -58,6 +58,7 @@ func init() { flags.StringSliceVarP(&excludedContainers, "exclude", "x", []string{}, "Names of containers to not start. ["+names+"]") flags.BoolVar(&ignoreHealthCheck, "ignore-health-check", false, "Ignore unhealthy services and exit 0") flags.BoolVar(&preview, "preview", false, "Connect to feature preview branch") + flags.BoolVar(&small, "small", false, "Use "+start.SmallImageName+" image") cobra.CheckErr(flags.MarkHidden("preview")) rootCmd.AddCommand(startCmd) } diff --git a/internal/start/start.go b/internal/start/start.go index 1184b6590..59e9fe7d3 100644 --- a/internal/start/start.go +++ b/internal/start/start.go @@ -44,12 +44,47 @@ import ( "github.com/supabase/cli/pkg/config" ) -func Run(ctx context.Context, fsys afero.Fs, excludedContainers []string, ignoreHealthCheck bool) error { +const ( + SmallImageName = "supabase/postgres:minimal" + graphqlPublicSchema = "graphql_public" +) + +// configureSmallMode configures the system for minimal resource usage by: +// - Using a smaller PostgreSQL image (minimal) +// - Disabling non-essential services (keeps only kong, postgrest, and auth) +// - Removing graphql_public schema from API schemas +func configureSmallMode() { + utils.Config.Db.Image = SmallImageName + + // Disable all services except kong, postgrest, and auth + // This ensures they won't be pulled or started regardless of config.toml settings + utils.Config.Realtime.Enabled = false + utils.Config.Storage.Enabled = false + utils.Config.Inbucket.Enabled = false + utils.Config.Studio.Enabled = false + utils.Config.EdgeRuntime.Enabled = false + utils.Config.Analytics.Enabled = false + utils.Config.Db.Pooler.Enabled = false + + // Remove graphql_public schema from API schemas when using --small + filteredSchemas := make([]string, 0, len(utils.Config.Api.Schemas)) + for _, schema := range utils.Config.Api.Schemas { + if schema != graphqlPublicSchema { + filteredSchemas = append(filteredSchemas, schema) + } + } + utils.Config.Api.Schemas = filteredSchemas +} + +func Run(ctx context.Context, fsys afero.Fs, excludedContainers []string, ignoreHealthCheck bool, useSmallImage bool) error { // Sanity checks. { if err := flags.LoadConfig(fsys); err != nil { return err } + if useSmallImage { + configureSmallMode() + } if err := utils.AssertSupabaseDbIsRunning(); err == nil { fmt.Fprintln(os.Stderr, utils.Aqua("supabase start")+" is already running.") names := status.CustomName{} diff --git a/internal/utils/docker.go b/internal/utils/docker.go index 6da0d5aa6..1bdfc1ea6 100644 --- a/internal/utils/docker.go +++ b/internal/utils/docker.go @@ -199,6 +199,10 @@ func GetRegistryImageUrl(imageName string) string { if registry == "docker.io" { return imageName } + // Skip registry transformation for minimal images (pulled locally from Docker Hub) + if strings.Contains(imageName, "minimal") { + return imageName + } // Configure mirror registry parts := strings.Split(imageName, "/") imageName = parts[len(parts)-1]