Explorar el Código

env variables and no newlines

Ivan Galakhov hace 4 años
padre
commit
57cce1e40c

+ 23 - 16
internal/integrations/ci/actions/actions.go

@@ -79,13 +79,13 @@ func (g *GithubActions) Setup() (string, error) {
 		return "", err
 	}
 
-	err = g.createGithubSecret(client, g.getPorterProjectIDSecretName(), g.PorterToken)
+	err = g.createGithubSecret(client, g.getProjectIDSecretName(), g.PorterToken)
 
 	if err != nil {
 		return "", err
 	}
 
-	err = g.createGithubSecret(client, g.getPorterClusterIDSecretName(), g.PorterToken)
+	err = g.createGithubSecret(client, g.getClusterIDSecretName(), g.PorterToken)
 
 	if err != nil {
 		return "", err
@@ -144,11 +144,18 @@ func (g *GithubActions) Cleanup() error {
 	return g.deleteGithubFile(client, g.getPorterYMLFileName())
 }
 
+type GithubActionEnvConfig struct {
+	PorterToken string `yaml:"PORTER_TOKEN"`
+	ProjectID   string `yaml:"PORTER_PROJECT"`
+	ClusterID   string `yaml:"PORTER_CLUSTER"`
+}
+
 type GithubActionYAMLStep struct {
-	Name string `yaml:"name,omitempty"`
-	ID   string `yaml:"id,omitempty"`
-	Uses string `yaml:"uses,omitempty"`
-	Run  string `yaml:"run,omitempty"`
+	Name string                `yaml:"name,omitempty"`
+	ID   string                `yaml:"id,omitempty"`
+	Uses string                `yaml:"uses,omitempty"`
+	Run  string                `yaml:"run,omitempty"`
+	Env  GithubActionEnvConfig `yaml:"env,omitempty"`
 }
 
 type GithubActionYAMLOnPushBranches struct {
@@ -176,16 +183,16 @@ func (g *GithubActions) GetGithubActionYAML() ([]byte, error) {
 	gaSteps := []GithubActionYAMLStep{
 		getCheckoutCodeStep(),
 		getDownloadPorterStep(),
-		getConfigurePorterStep(g.ServerURL, g.getPorterTokenSecretName()),
-	}
-
-	if g.DockerFilePath == "" {
-		gaSteps = append(gaSteps, getBuildPackPushStep(g.getBuildEnvSecretName(), g.FolderPath, g.ImageRepoURL))
-	} else {
-		gaSteps = append(gaSteps, getDockerBuildPushStep(g.getBuildEnvSecretName(), g.DockerFilePath, g.ImageRepoURL))
+		getConfigurePorterStep(g.ServerURL, g.getPorterTokenSecretName(), g.getProjectIDSecretName(), g.getClusterIDSecretName(), g.ReleaseName),
 	}
 
-	gaSteps = append(gaSteps, deployPorterWebhookStep(g.ServerURL, g.getWebhookSecretName()))
+	//if g.DockerFilePath == "" {
+	//	gaSteps = append(gaSteps, getBuildPackPushStep(g.getBuildEnvSecretName(), g.FolderPath, g.ImageRepoURL))
+	//} else {
+	//	gaSteps = append(gaSteps, getDockerBuildPushStep(g.getBuildEnvSecretName(), g.DockerFilePath, g.ImageRepoURL))
+	//}
+	//
+	//gaSteps = append(gaSteps, deployPorterWebhookStep(g.ServerURL, g.getWebhookSecretName()))
 
 	branch := g.GitBranch
 
@@ -358,11 +365,11 @@ func (g *GithubActions) getPorterTokenSecretName() string {
 	return fmt.Sprintf("PORTER_TOKEN_%d", g.ProjectID)
 }
 
-func (g *GithubActions) getPorterProjectIDSecretName() string {
+func (g *GithubActions) getProjectIDSecretName() string {
 	return fmt.Sprintf("PORTER_PROJECT_ID_%d", g.ProjectID)
 }
 
-func (g *GithubActions) getPorterClusterIDSecretName() string {
+func (g *GithubActions) getClusterIDSecretName() string {
 	return fmt.Sprintf("PORTER_CLUSTER_ID_%d", g.ProjectID)
 }
 

+ 10 - 8
internal/integrations/ci/actions/steps.go

@@ -12,8 +12,7 @@ func getCheckoutCodeStep() GithubActionYAMLStep {
 	}
 }
 
-const download string = `
-name=$(curl -s https://api.github.com/repos/porter-dev/porter/releases/latest | grep "browser_download_url.*/porter_.*_Linux_x86_64\.zip" | cut -d ":" -f 2,3 | tr -d \")
+const download string = `name=$(curl -s https://api.github.com/repos/porter-dev/porter/releases/latest | grep "browser_download_url.*/porter_.*_Linux_x86_64\.zip" | cut -d ":" -f 2,3 | tr -d \")
 name=$(basename $name)
 curl -L https://github.com/porter-dev/porter/releases/latest/download/$name --output $name
 unzip -a $name
@@ -30,17 +29,20 @@ func getDownloadPorterStep() GithubActionYAMLStep {
 	}
 }
 
-const configure string = `
-sudo porter config set-host %s
-sudo porter auth login --token ${{secrets.%s}}
-sudo porter docker configure
+const configure string = `sudo porter config set-host %s
+porter update --app %s
 `
 
-func getConfigurePorterStep(serverURL, porterTokenSecretName string) GithubActionYAMLStep {
+func getConfigurePorterStep(serverURL, porterTokenSecretName string, projectIDSecretName string, clusterIDSecretName string, appName string) GithubActionYAMLStep {
 	return GithubActionYAMLStep{
 		Name: "Configure Porter",
 		ID:   "configure_porter",
-		Run:  fmt.Sprintf(configure, serverURL, porterTokenSecretName),
+		Run:  fmt.Sprintf(configure, serverURL, appName),
+		Env: GithubActionEnvConfig{
+			PorterToken: fmt.Sprintf("{{ secrets.%s }}", porterTokenSecretName),
+			ProjectID:   fmt.Sprintf("{{ secrets.%s }}", projectIDSecretName),
+			ClusterID:   fmt.Sprintf("{{ secrets.%s }}", clusterIDSecretName),
+		},
 	}
 }