瀏覽代碼

add repo suffix option to cli create opts, use it during apply

Alexander Belanger 4 年之前
父節點
當前提交
0bda6ec09d
共有 2 個文件被更改,包括 27 次插入4 次删除
  1. 10 2
      cli/cmd/apply.go
  2. 17 2
      cli/cmd/deploy/create.go

+ 10 - 2
cli/cmd/apply.go

@@ -334,6 +334,15 @@ func (d *Driver) createApplication(resource *models.Resource, client *api.Client
 		registryURL = (*regList)[0].URL
 	}
 
+	// attempt to get repo suffix from environment variables
+	var repoSuffix string
+
+	if repoName := os.Getenv("PORTER_REPO_NAME"); repoName != "" {
+		if repoOwner := os.Getenv("PORTER_REPO_OWNER"); repoOwner != "" {
+			repoSuffix = fmt.Sprintf("%s-%s", repoOwner, repoName)
+		}
+	}
+
 	createAgent := &deploy.CreateAgent{
 		Client: client,
 		CreateOpts: &deploy.CreateOpts{
@@ -341,6 +350,7 @@ func (d *Driver) createApplication(resource *models.Resource, client *api.Client
 			Kind:        d.source.Name,
 			ReleaseName: resource.Name,
 			RegistryURL: registryURL,
+			RepoSuffix:  repoSuffix,
 		},
 	}
 
@@ -818,8 +828,6 @@ func (t *DeploymentHook) PostApply(populatedData map[string]interface{}) error {
 }
 
 func (t *DeploymentHook) OnError(err error) {
-	fmt.Println("running error hook for deployment")
-
 	// if the deployment exists, throw an error for that deployment
 	_, getDeplErr := t.client.GetDeployment(
 		context.Background(),

+ 17 - 2
cli/cmd/deploy/create.go

@@ -27,6 +27,10 @@ type CreateOpts struct {
 	Kind        string
 	ReleaseName string
 	RegistryURL string
+
+	// Suffix for the name of the image in the repository. By default the suffix is the
+	// target namespace.
+	RepoSuffix string
 }
 
 // GithubOpts are the options for linking a Github source to the app
@@ -376,12 +380,23 @@ func (c *CreateAgent) GetImageRepoURL(name, namespace string) (uint, string, err
 		if c.CreateOpts.RegistryURL != "" {
 			if c.CreateOpts.RegistryURL == reg.URL {
 				regID = reg.ID
-				imageURI = fmt.Sprintf("%s/%s-%s", reg.URL, name, namespace)
+				if c.CreateOpts.RepoSuffix != "" {
+					imageURI = fmt.Sprintf("%s/%s-%s", reg.URL, name, c.CreateOpts.RepoSuffix)
+				} else {
+					imageURI = fmt.Sprintf("%s/%s-%s", reg.URL, name, namespace)
+				}
+
 				break
 			}
 		} else if reg.URL != "" {
 			regID = reg.ID
-			imageURI = fmt.Sprintf("%s/%s-%s", reg.URL, name, namespace)
+
+			if c.CreateOpts.RepoSuffix != "" {
+				imageURI = fmt.Sprintf("%s/%s-%s", reg.URL, name, c.CreateOpts.RepoSuffix)
+			} else {
+				imageURI = fmt.Sprintf("%s/%s-%s", reg.URL, name, namespace)
+			}
+
 			break
 		}
 	}