Repository: supabase/cli
Pull request #378 (2022-08-17 17:14:43)

fix: remove registry prefix from docker hub image
## What kind of change does this PR introduce?

Bug fix

## What is the current behavior?

fails to pull docker hub image

## What is the new behavior?

pulls locally

## Additional context

Add any other context or screenshots.


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

* **5** of **5**   **(100.0%)**  changed or added relevant lines in **1** file are covered.
* **2** unchanged lines in **1** file lost coverage.
* Overall coverage increased (+**0.03%**) to **25.727%**

---


|  Files with Coverage Reduction | New Missed Lines | % |
| :-----|--------------|--: |
| [internal/utils/docker.go](https://coveralls.io/builds/51740543/source?filename=internal%2Futils%2Fdocker.go#L222) | 2 | 52.4% |
<!-- | **Total:** | **2** |  | -->

|  Totals | [![Coverage Status](https://coveralls.io/builds/51740543/badge)](https://coveralls.io/builds/51740543) |
| :-- | --: |
| Change from base [Build 2874587193](https://coveralls.io/builds/51726924): |  0.03% |
| Covered Lines: | 1274 |
| Relevant Lines: | 4952 |

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


Patch:
diff --git a/internal/utils/docker.go b/internal/utils/docker.go
index bfae8349..7d3093a1 100644
--- a/internal/utils/docker.go
+++ b/internal/utils/docker.go
@@ -146,8 +146,10 @@ func DockerAddFile(ctx context.Context, container string, fileName string, conte
 }
 
 func GetRegistryImageUrl(imageName string) string {
+	const hub = "docker.io"
 	const ecr = "public.ecr.aws/t3w2s2c9"
 	registry := viper.GetString("INTERNAL_IMAGE_REGISTRY")
+	registry = strings.ToLower(registry)
 	if registry == "" {
 		// Defaults to Supabase public ECR for faster image pull
 		registry = ecr
@@ -156,6 +158,9 @@ func GetRegistryImageUrl(imageName string) string {
 		parts := strings.Split(imageName, "/")
 		imageName = parts[len(parts)-1]
 	}
+	if registry == hub {
+		return imageName
+	}
 	return registry + "/" + imageName
 }
 


Test patch:
diff --git a/internal/utils/docker_test.go b/internal/utils/docker_test.go
index d7cb8eff..d1876494 100644
--- a/internal/utils/docker_test.go
+++ b/internal/utils/docker_test.go
@@ -37,7 +37,7 @@ func TestPullImage(t *testing.T) {
 			SetHeader("API-Version", version).
 			SetHeader("OSType", "linux")
 		gock.New("http:///var/run/docker.sock").
-			Get("/v" + version + "/images/docker.io/" + imageId + "/json").
+			Get("/v" + version + "/images/" + imageId + "/json").
 			Reply(http.StatusNotFound)
 		gock.New("http:///var/run/docker.sock").
 			Post("/v"+version+"/images/create").
@@ -60,7 +60,7 @@ func TestPullImage(t *testing.T) {
 			SetHeader("API-Version", version).
 			SetHeader("OSType", "linux")
 		gock.New("http:///var/run/docker.sock").
-			Get("/v" + version + "/images/docker.io/" + imageId + "/json").
+			Get("/v" + version + "/images/" + imageId + "/json").
 			Reply(http.StatusOK).
 			JSON(types.ImageInspect{})
 		// Run test
@@ -79,7 +79,7 @@ func TestPullImage(t *testing.T) {
 			SetHeader("API-Version", version).
 			SetHeader("OSType", "linux")
 		gock.New("http:///var/run/docker.sock").
-			Get("/v" + version + "/images/docker.io/" + imageId + "/json").
+			Get("/v" + version + "/images/" + imageId + "/json").
 			Reply(http.StatusServiceUnavailable)
 		// Run test
 		assert.Error(t, DockerPullImageIfNotCached(context.Background(), imageId))
@@ -97,7 +97,7 @@ func TestPullImage(t *testing.T) {
 			SetHeader("API-Version", version).
 			SetHeader("OSType", "linux")
 		gock.New("http:///var/run/docker.sock").
-			Get("/v" + version + "/images/docker.io/" + imageId + "/json").
+			Get("/v" + version + "/images/" + imageId + "/json").
 			Reply(http.StatusNotFound)
 		gock.New("http:///var/run/docker.sock").
 			Post("/v"+version+"/images/create").
@@ -124,7 +124,7 @@ func TestRunOnce(t *testing.T) {
 			SetHeader("API-Version", version).
 			SetHeader("OSType", "linux")
 		gock.New("http:///var/run/docker.sock").
-			Get("/v" + version + "/images/docker.io/" + imageId + "/json").
+			Get("/v" + version + "/images/" + imageId + "/json").
 			Reply(http.StatusOK).
 			JSON(types.ImageInspect{})
 		gock.New("http:///var/run/docker.sock").
@@ -171,7 +171,7 @@ func TestRunOnce(t *testing.T) {
 			SetHeader("API-Version", version).
 			SetHeader("OSType", "linux")
 		gock.New("http:///var/run/docker.sock").
-			Get("/v" + version + "/images/docker.io/" + imageId + "/json").
+			Get("/v" + version + "/images/" + imageId + "/json").
 			Reply(http.StatusOK).
 			JSON(types.ImageInspect{})
 		gock.New("http:///var/run/docker.sock").
@@ -198,7 +198,7 @@ func TestRunOnce(t *testing.T) {
 			SetHeader("API-Version", version).
 			SetHeader("OSType", "linux")
 		gock.New("http:///var/run/docker.sock").
-			Get("/v" + version + "/images/docker.io/" + imageId + "/json").
+			Get("/v" + version + "/images/" + imageId + "/json").
 			Reply(http.StatusOK).
 			JSON(types.ImageInspect{})
 		gock.New("http:///var/run/docker.sock").
@@ -229,7 +229,7 @@ func TestRunOnce(t *testing.T) {
 			SetHeader("API-Version", version).
 			SetHeader("OSType", "linux")
 		gock.New("http:///var/run/docker.sock").
-			Get("/v" + version + "/images/docker.io/" + imageId + "/json").
+			Get("/v" + version + "/images/" + imageId + "/json").
 			Reply(http.StatusOK).
 			JSON(types.ImageInspect{})
 		gock.New("http:///var/run/docker.sock").
@@ -270,7 +270,7 @@ func TestRunOnce(t *testing.T) {
 			SetHeader("API-Version", version).
 			SetHeader("OSType", "linux")
 		gock.New("http:///var/run/docker.sock").
-			Get("/v" + version + "/images/docker.io/" + imageId + "/json").
+			Get("/v" + version + "/images/" + imageId + "/json").
 			Reply(http.StatusOK).
 			JSON(types.ImageInspect{})
 		gock.New("http:///var/run/docker.sock").
@@ -306,7 +306,7 @@ func TestRunOnce(t *testing.T) {
 			SetHeader("API-Version", version).
 			SetHeader("OSType", "linux")
 		gock.New("http:///var/run/docker.sock").
-			Get("/v" + version + "/images/docker.io/" + imageId + "/json").
+			Get("/v" + version + "/images/" + imageId + "/json").
 			Reply(http.StatusOK).
 			JSON(types.ImageInspect{})
 		gock.New("http:///var/run/docker.sock").
@@ -350,7 +350,7 @@ func TestRunOnce(t *testing.T) {
 			SetHeader("API-Version", version).
 			SetHeader("OSType", "linux")
 		gock.New("http:///var/run/docker.sock").
-			Get("/v" + version + "/images/docker.io/" + imageId + "/json").
+			Get("/v" + version + "/images/" + imageId + "/json").
 			Reply(http.StatusOK).
 			JSON(types.ImageInspect{})
 		gock.New("http:///var/run/docker.sock").