diff --git a/internal/start/start.go b/internal/start/start.go index 9096f381d..f31a950cc 100644 --- a/internal/start/start.go +++ b/internal/start/start.go @@ -169,6 +169,8 @@ func run(p utils.Program, ctx context.Context, fsys afero.Fs, excludedContainers var started []string var isStorageEnabled = utils.Config.Storage.Enabled && !isContainerExcluded(utils.Config.Storage.Image, excluded) + var isImgProxyEnabled = utils.Config.Storage.ImageTransformation != nil && + utils.Config.Storage.ImageTransformation.Enabled && !isContainerExcluded(utils.Config.Storage.ImgProxyImage, excluded) p.Send(utils.StatusMsg("Starting containers...")) // Start Logflare @@ -833,7 +835,7 @@ EOF // TODO: https://github.com/supabase/storage-api/issues/55 "STORAGE_S3_REGION=" + utils.Config.Storage.S3Credentials.Region, "GLOBAL_S3_BUCKET=stub", - fmt.Sprintf("ENABLE_IMAGE_TRANSFORMATION=%t", utils.Config.Storage.ImageTransformation.Enabled), + fmt.Sprintf("ENABLE_IMAGE_TRANSFORMATION=%t", isImgProxyEnabled), fmt.Sprintf("IMGPROXY_URL=http://%s:5001", utils.ImgProxyId), "TUS_URL_PATH=/storage/v1/upload/resumable", "S3_PROTOCOL_ACCESS_KEY_ID=" + utils.Config.Storage.S3Credentials.AccessKeyId, @@ -872,11 +874,11 @@ EOF } // Start Storage ImgProxy. - if isStorageEnabled && utils.Config.Storage.ImageTransformation.Enabled && !isContainerExcluded(utils.Config.Storage.ImageTransformation.Image, excluded) { + if isStorageEnabled && isImgProxyEnabled { if _, err := utils.DockerStart( ctx, container.Config{ - Image: utils.Config.Storage.ImageTransformation.Image, + Image: utils.Config.Storage.ImgProxyImage, Env: []string{ "IMGPROXY_BIND=:5001", "IMGPROXY_LOCAL_FILESYSTEM_ROOT=/", diff --git a/internal/start/start_test.go b/internal/start/start_test.go index 079eb3c79..b61cb9cd4 100644 --- a/internal/start/start_test.go +++ b/internal/start/start_test.go @@ -133,7 +133,7 @@ func TestDatabaseStart(t *testing.T) { utils.StorageId = "test-storage" apitest.MockDockerStart(utils.Docker, utils.GetRegistryImageUrl(utils.Config.Storage.Image), utils.StorageId) utils.ImgProxyId = "test-imgproxy" - apitest.MockDockerStart(utils.Docker, utils.GetRegistryImageUrl(utils.Config.Storage.ImageTransformation.Image), utils.ImgProxyId) + apitest.MockDockerStart(utils.Docker, utils.GetRegistryImageUrl(utils.Config.Storage.ImgProxyImage), utils.ImgProxyId) utils.EdgeRuntimeId = "test-edge-runtime" apitest.MockDockerStart(utils.Docker, utils.GetRegistryImageUrl(utils.Config.EdgeRuntime.Image), utils.EdgeRuntimeId) utils.PgmetaId = "test-pgmeta" diff --git a/pkg/config/config.go b/pkg/config/config.go index 410bd7aa3..5c7fc0946 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -300,15 +300,13 @@ func NewConfig(editors ...ConfigEditor) config { SecretKeyBase: "EAx3IQ/wRG1v47ZD4NE4/9RzBI8Jmil3x0yhcW4V2NHBP6c2iPIzwjofi2Ep4HIG", }, Storage: storage{ - Image: storageImage, + Image: storageImage, + ImgProxyImage: imageProxyImage, S3Credentials: storageS3Credentials{ AccessKeyId: "625729a08b95bf1b7ff351a663f3a23c", SecretAccessKey: "850181e4652dd023b7a98c58ae0d2d34bd487ee0cc3254aed6eda37307425907", Region: "local", }, - ImageTransformation: imageTransformation{ - Image: imageProxyImage, - }, }, Auth: auth{ Image: gotrueImage, diff --git a/pkg/config/storage.go b/pkg/config/storage.go index b11b28a10..3b5696738 100644 --- a/pkg/config/storage.go +++ b/pkg/config/storage.go @@ -10,15 +10,15 @@ type ( storage struct { Enabled bool `toml:"enabled"` Image string `toml:"-"` + ImgProxyImage string `toml:"-"` FileSizeLimit sizeInBytes `toml:"file_size_limit"` + ImageTransformation *imageTransformation `toml:"image_transformation"` S3Credentials storageS3Credentials `toml:"-"` - ImageTransformation imageTransformation `toml:"image_transformation"` Buckets BucketConfig `toml:"buckets"` } imageTransformation struct { - Enabled bool `toml:"enabled"` - Image string `toml:"-"` + Enabled bool `toml:"enabled"` } storageS3Credentials struct { @@ -38,15 +38,26 @@ type ( ) func (s *storage) ToUpdateStorageConfigBody() v1API.UpdateStorageConfigBody { - body := v1API.UpdateStorageConfigBody{Features: &v1API.StorageFeatures{}} - body.FileSizeLimit = cast.Ptr(int64(s.FileSizeLimit)) - body.Features.ImageTransformation.Enabled = s.ImageTransformation.Enabled + body := v1API.UpdateStorageConfigBody{ + FileSizeLimit: cast.Ptr(int64(s.FileSizeLimit)), + } + // When local config is not set, we assume platform defaults should not change + if s.ImageTransformation != nil { + body.Features = &v1API.StorageFeatures{ + ImageTransformation: v1API.StorageFeatureImageTransformation{ + Enabled: s.ImageTransformation.Enabled, + }, + } + } return body } func (s *storage) FromRemoteStorageConfig(remoteConfig v1API.StorageConfigResponse) { s.FileSizeLimit = sizeInBytes(remoteConfig.FileSizeLimit) - s.ImageTransformation.Enabled = remoteConfig.Features.ImageTransformation.Enabled + // When local config is not set, we assume platform defaults should not change + if s.ImageTransformation != nil { + s.ImageTransformation.Enabled = remoteConfig.Features.ImageTransformation.Enabled + } } func (s *storage) DiffWithRemote(remoteConfig v1API.StorageConfigResponse) ([]byte, error) { diff --git a/pkg/config/templates/config.toml b/pkg/config/templates/config.toml index e3f55ae68..5345f4d0d 100644 --- a/pkg/config/templates/config.toml +++ b/pkg/config/templates/config.toml @@ -83,8 +83,8 @@ enabled = true file_size_limit = "50MiB" # Image transformation API is available to Supabase Pro plan. -[storage.image_transformation] -enabled = false +# [storage.image_transformation] +# enabled = true # Uncomment to configure local storage buckets # [storage.buckets.images] diff --git a/pkg/config/updater_test.go b/pkg/config/updater_test.go index 471e84963..f3eb0bcb4 100644 --- a/pkg/config/updater_test.go +++ b/pkg/config/updater_test.go @@ -336,7 +336,7 @@ func TestUpdateRemoteConfig(t *testing.T) { Storage: storage{ Enabled: true, FileSizeLimit: 100, - ImageTransformation: imageTransformation{ + ImageTransformation: &imageTransformation{ Enabled: true, }, },