Browse Source

add option to set instance name, to uniquely identify secrets/action names

Alexander Belanger 4 năm trước cách đây
mục cha
commit
27875a0d98

+ 1 - 0
api/server/handlers/release/create.go

@@ -247,6 +247,7 @@ func createGitAction(
 
 
 	// create the commit in the git repo
 	// create the commit in the git repo
 	gaRunner := &actions.GithubActions{
 	gaRunner := &actions.GithubActions{
+		InstanceName:           config.ServerConf.InstanceName,
 		ServerURL:              config.ServerConf.ServerURL,
 		ServerURL:              config.ServerConf.ServerURL,
 		GithubOAuthIntegration: nil,
 		GithubOAuthIntegration: nil,
 		GithubAppID:            config.GithubAppConf.AppID,
 		GithubAppID:            config.GithubAppConf.AppID,

+ 8 - 1
api/server/shared/config/env/envconfs.go

@@ -6,7 +6,14 @@ import "time"
 type ServerConf struct {
 type ServerConf struct {
 	Debug bool `env:"DEBUG,default=false"`
 	Debug bool `env:"DEBUG,default=false"`
 
 
-	ServerURL            string        `env:"SERVER_URL,default=http://localhost:8080"`
+	ServerURL string `env:"SERVER_URL,default=http://localhost:8080"`
+
+	// The instance name is used to set a name for integrations linked only by a project ID,
+	// in order to differentiate between the same project ID on different instances. For example,
+	// when writing a Github secret with `PORTER_TOKEN_<PROJECT_ID>`, setting this value will change
+	// this to `PORTER_TOKEN_<INSTANCE_NAME>_<PROJECT_ID>`
+	InstanceName string `env:"INSTANCE_NAME"`
+
 	Port                 int           `env:"SERVER_PORT,default=8080"`
 	Port                 int           `env:"SERVER_PORT,default=8080"`
 	StaticFilePath       string        `env:"STATIC_FILE_PATH,default=/porter/static"`
 	StaticFilePath       string        `env:"STATIC_FILE_PATH,default=/porter/static"`
 	CookieName           string        `env:"COOKIE_NAME,default=porter"`
 	CookieName           string        `env:"COOKIE_NAME,default=porter"`

+ 13 - 1
internal/integrations/ci/actions/actions.go

@@ -21,7 +21,8 @@ import (
 )
 )
 
 
 type GithubActions struct {
 type GithubActions struct {
-	ServerURL string
+	ServerURL    string
+	InstanceName string
 
 
 	GithubOAuthIntegration *models.GitRepo
 	GithubOAuthIntegration *models.GitRepo
 	GitRepoName            string
 	GitRepoName            string
@@ -339,12 +340,23 @@ func (g *GithubActions) getBuildEnvSecretName() string {
 }
 }
 
 
 func (g *GithubActions) getPorterYMLFileName() string {
 func (g *GithubActions) getPorterYMLFileName() string {
+	if g.InstanceName != "" {
+		return fmt.Sprintf("porter_%s_%s.yml", strings.Replace(
+			strings.ToLower(g.ReleaseName), "-", "_", -1),
+			strings.ToLower(g.InstanceName),
+		)
+	}
+
 	return fmt.Sprintf("porter_%s.yml", strings.Replace(
 	return fmt.Sprintf("porter_%s.yml", strings.Replace(
 		strings.ToLower(g.ReleaseName), "-", "_", -1),
 		strings.ToLower(g.ReleaseName), "-", "_", -1),
 	)
 	)
 }
 }
 
 
 func (g *GithubActions) getPorterTokenSecretName() string {
 func (g *GithubActions) getPorterTokenSecretName() string {
+	if g.InstanceName != "" {
+		return fmt.Sprintf("PORTER_TOKEN_%s_%d", strings.ToUpper(g.InstanceName), g.ProjectID)
+	}
+
 	return fmt.Sprintf("PORTER_TOKEN_%d", g.ProjectID)
 	return fmt.Sprintf("PORTER_TOKEN_%d", g.ProjectID)
 }
 }