Repository: supabase/cli
Pull request #685 (2022-12-11 11:20:45)

feat: add image transforms

coveralls: ## Pull Request Test Coverage Report for [Build 3669718613](https://coveralls.io/builds/55045848)

* **23** of **25**   **(92.0%)**  changed or added relevant lines in **2** files are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage increased (+**0.1%**) to **56.509%**

---

|  Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
| :-----|--------------|--------|---: |
| [internal/start/start.go](https://coveralls.io/builds/55045848/source?filename=internal%2Fstart%2Fstart.go#L400) | 22 | 24 | 91.67%
<!-- | **Total:** | **23** | **25** | **92.0%** | -->


|  Totals | [![Coverage Status](https://coveralls.io/builds/55045848/badge)](https://coveralls.io/builds/55045848) |
| :-- | --: |
| Change from base [Build 3667636465](https://coveralls.io/builds/55042064): |  0.1% |
| Covered Lines: | 3377 |
| Relevant Lines: | 5976 |

---
##### 💛  - [Coveralls](https://coveralls.io)


Patch:
diff --git a/internal/start/start.go b/internal/start/start.go
index b61f3a7f..d3960c73 100644
--- a/internal/start/start.go
+++ b/internal/start/start.go
@@ -350,6 +350,9 @@ EOF
 			ctx,
 			container.Config{
 				Image: utils.StorageImage,
+				Volumes: map[string]struct{}{
+					"/var/lib/storage": {},
+				},
 				Env: []string{
 					"ANON_KEY=" + utils.AnonKey,
 					"SERVICE_KEY=" + utils.ServiceRoleKey,
@@ -363,6 +366,8 @@ EOF
 					// TODO: https://github.com/supabase/storage-api/issues/55
 					"REGION=stub",
 					"GLOBAL_S3_BUCKET=stub",
+					"ENABLE_IMAGE_TRANSFORMATION=true",
+					"IMGPROXY_URL=http://" + utils.ImgProxyId + ":5001",
 				},
 			},
 			container.HostConfig{
@@ -374,6 +379,28 @@ EOF
 		}
 	}
 
+	// Start Storage ImgProxy.
+	if !isContainerExcluded(utils.ImageProxyImage, excluded) {
+		if _, err := utils.DockerStart(
+			ctx,
+			container.Config{
+				Image: utils.ImageProxyImage,
+				Env: []string{
+					"IMGPROXY_BIND=:5001",
+					"IMGPROXY_LOCAL_FILESYSTEM_ROOT=/",
+					"IMGPROXY_USE_ETAG=/",
+				},
+			},
+			container.HostConfig{
+				VolumesFrom:   []string{utils.StorageId},
+				RestartPolicy: container.RestartPolicy{Name: "always"},
+			},
+			utils.ImgProxyId,
+		); err != nil {
+			return err
+		}
+	}
+
 	// Start diff tool.
 	if !isContainerExcluded(utils.DifferImage, excluded) {
 		if _, err := utils.DockerStart(
diff --git a/internal/utils/config.go b/internal/utils/config.go
index 0d407237..04f88105 100644
--- a/internal/utils/config.go
+++ b/internal/utils/config.go
@@ -25,6 +25,7 @@ var (
 	RealtimeId  string
 	RestId      string
 	StorageId   string
+	ImgProxyId  string
 	DifferId    string
 	PgmetaId    string
 	StudioId    string
@@ -168,6 +169,7 @@ func LoadConfigFS(fsys afero.Fs) error {
 			RealtimeId = "realtime-demo.supabase_realtime_" + Config.ProjectId
 			RestId = "supabase_rest_" + Config.ProjectId
 			StorageId = "supabase_storage_" + Config.ProjectId
+			ImgProxyId = "storage_imgproxy_" + Config.ProjectId
 			DifferId = "supabase_differ_" + Config.ProjectId
 			PgmetaId = "supabase_pg_meta_" + Config.ProjectId
 			StudioId = "supabase_studio_" + Config.ProjectId
diff --git a/internal/utils/misc.go b/internal/utils/misc.go
index a9950657..a6e071c6 100644
--- a/internal/utils/misc.go
+++ b/internal/utils/misc.go
@@ -27,25 +27,27 @@ const (
 	Pg13Image = "supabase/postgres:13.3.0"
 	Pg14Image = "supabase/postgres:14.1.0.89"
 	// Append to ServiceImages when adding new dependencies below
-	KongImage      = "library/kong:2.8.1"
-	InbucketImage  = "inbucket/inbucket:3.0.3"
-	PostgrestImage = "postgrest/postgrest:v9.0.1.20220717"
-	DifferImage    = "supabase/pgadmin-schema-diff:cli-0.0.5"
-	MigraImage     = "djrobstep/migra:3.0.1621480950"
-	PgmetaImage    = "supabase/postgres-meta:v0.53.1"
-	StudioImage    = "supabase/studio:0.22.08"
-	DenoRelayImage = "supabase/deno-relay:v1.5.0"
+	KongImage       = "library/kong:2.8.1"
+	InbucketImage   = "inbucket/inbucket:3.0.3"
+	PostgrestImage  = "postgrest/postgrest:v9.0.1.20220717"
+	DifferImage     = "supabase/pgadmin-schema-diff:cli-0.0.5"
+	MigraImage      = "djrobstep/migra:3.0.1621480950"
+	PgmetaImage     = "supabase/postgres-meta:v0.53.1"
+	StudioImage     = "supabase/studio:0.22.08"
+	DenoRelayImage  = "supabase/deno-relay:v1.5.0"
+	ImageProxyImage = "supabase/imgproxy:v1.0.4"
 	// Update initial schemas in internal/utils/templates/initial_schemas when
 	// updating any one of these.
 	GotrueImage   = "supabase/gotrue:v2.25.1"
 	RealtimeImage = "supabase/realtime:v1.0.0-rc.11"
-	StorageImage  = "supabase/storage-api:v0.21.4"
+	StorageImage  = "supabase/storage-api:v0.26.1"
 )
 
 var ServiceImages = []string{
 	GotrueImage,
 	RealtimeImage,
 	StorageImage,
+	ImageProxyImage,
 	KongImage,
 	InbucketImage,
 	PostgrestImage,


Test patch:
diff --git a/internal/start/start_test.go b/internal/start/start_test.go
index 09ae7ab7..8c25feae 100644
--- a/internal/start/start_test.go
+++ b/internal/start/start_test.go
@@ -217,6 +217,8 @@ func TestDatabaseStart(t *testing.T) {
 		apitest.MockDockerStart(utils.Docker, utils.GetRegistryImageUrl(utils.PostgrestImage), utils.RestId)
 		utils.StorageId = "test-storage"
 		apitest.MockDockerStart(utils.Docker, utils.GetRegistryImageUrl(utils.StorageImage), utils.StorageId)
+		utils.StudioId = "test-imgproxy"
+		apitest.MockDockerStart(utils.Docker, utils.GetRegistryImageUrl(utils.ImageProxyImage), utils.ImgProxyId)
 		utils.DifferId = "test-differ"
 		apitest.MockDockerStart(utils.Docker, utils.GetRegistryImageUrl(utils.DifferImage), utils.DifferId)
 		utils.PgmetaId = "test-pgmeta"