Ver Fonte

update command

Ivan Galakhov há 4 anos atrás
pai
commit
e13ad4e48e

+ 6 - 41
internal/integrations/ci/actions/actions.go

@@ -79,18 +79,6 @@ func (g *GithubActions) Setup() (string, error) {
 		return "", err
 	}
 
-	err = g.createGithubSecret(client, g.getProjectIDSecretName(), g.PorterToken)
-
-	if err != nil {
-		return "", err
-	}
-
-	err = g.createGithubSecret(client, g.getClusterIDSecretName(), g.PorterToken)
-
-	if err != nil {
-		return "", err
-	}
-
 	// create a new secret with the build variables
 	err = g.createEnvSecret(client)
 
@@ -144,19 +132,12 @@ 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"`
-	Timeout uint64                `yaml:"timeout-minutes,omitempty"`
-	Uses    string                `yaml:"uses,omitempty"`
-	Run     string                `yaml:"run,omitempty"`
-	Env     GithubActionEnvConfig `yaml:"env,omitempty"`
+	Name    string `yaml:"name,omitempty"`
+	ID      string `yaml:"id,omitempty"`
+	Timeout uint64 `yaml:"timeout-minutes,omitempty"`
+	Uses    string `yaml:"uses,omitempty"`
+	Run     string `yaml:"run,omitempty"`
 }
 
 type GithubActionYAMLOnPushBranches struct {
@@ -184,17 +165,9 @@ func (g *GithubActions) GetGithubActionYAML() ([]byte, error) {
 	gaSteps := []GithubActionYAMLStep{
 		getCheckoutCodeStep(),
 		getDownloadPorterStep(),
-		getConfigurePorterStep(g.ServerURL, g.getPorterTokenSecretName(), g.getProjectIDSecretName(), g.getClusterIDSecretName(), g.ReleaseName),
+		getConfigurePorterStep(g.ServerURL, g.getPorterTokenSecretName(), g.ProjectID, g.ClusterID, g.ReleaseName),
 	}
 
-	//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
 
 	if branch == "" {
@@ -366,14 +339,6 @@ func (g *GithubActions) getPorterTokenSecretName() string {
 	return fmt.Sprintf("PORTER_TOKEN_%d", g.ProjectID)
 }
 
-func (g *GithubActions) getProjectIDSecretName() string {
-	return fmt.Sprintf("PORTER_PROJECT_ID_%d", g.ProjectID)
-}
-
-func (g *GithubActions) getClusterIDSecretName() string {
-	return fmt.Sprintf("PORTER_CLUSTER_ID_%d", g.ProjectID)
-}
-
 func (g *GithubActions) commitGithubFile(
 	client *github.Client,
 	filename string,

+ 4 - 57
internal/integrations/ci/actions/steps.go

@@ -2,7 +2,6 @@ package actions
 
 import (
 	"fmt"
-	"path/filepath"
 )
 
 func getCheckoutCodeStep() GithubActionYAMLStep {
@@ -29,65 +28,13 @@ func getDownloadPorterStep() GithubActionYAMLStep {
 	}
 }
 
-const configure string = `sudo porter config set-host %s
-porter update --app %s
-`
+const configure string = `porter update --host %s --token %s --project %d --cluster %d --app %s`
 
-func getConfigurePorterStep(serverURL, porterTokenSecretName string, projectIDSecretName string, clusterIDSecretName string, appName string) GithubActionYAMLStep {
+func getConfigurePorterStep(serverURL, porterTokenSecretName string, projectID uint, clusterID uint, appName string) GithubActionYAMLStep {
 	return GithubActionYAMLStep{
 		Name:    "Update Porter App",
-		ID:      "configure_porter",
-		Run:     fmt.Sprintf(configure, serverURL, appName),
+		ID:      "update_porter",
+		Run:     fmt.Sprintf(configure, serverURL, fmt.Sprintf("${{ secrets.%s }}", porterTokenSecretName), projectID, clusterID, appName),
 		Timeout: 10,
-		Env: GithubActionEnvConfig{
-			PorterToken: fmt.Sprintf("{{ secrets.%s }}", porterTokenSecretName),
-			ProjectID:   fmt.Sprintf("{{ secrets.%s }}", projectIDSecretName),
-			ClusterID:   fmt.Sprintf("{{ secrets.%s }}", clusterIDSecretName),
-		},
-	}
-}
-
-const dockerBuildPush string = `
-export $(echo "${{secrets.%s}}" | xargs)
-echo "${{secrets.%s}}" > ./env_porter
-sudo docker build %s $(cat ./env_porter | awk 'NF' | sed 's@^@--build-arg @g' | paste -s -d " " -) --file %s -t %s:$(git rev-parse --short HEAD)
-sudo docker push %s:$(git rev-parse --short HEAD)
-`
-
-func getDockerBuildPushStep(envSecretName, dockerFilePath, repoURL string) GithubActionYAMLStep {
-	return GithubActionYAMLStep{
-		Name: "Docker build, push",
-		ID:   "docker_build_push",
-		Run:  fmt.Sprintf(dockerBuildPush, envSecretName, envSecretName, filepath.Dir(dockerFilePath), dockerFilePath, repoURL, repoURL),
-	}
-}
-
-const buildPackPush string = `
-export $(echo "${{secrets.%s}}" | xargs)
-echo "${{secrets.%s}}" > ./env_porter
-sudo add-apt-repository ppa:cncf-buildpacks/pack-cli
-sudo apt-get update
-sudo apt-get install pack-cli
-sudo pack build %s:$(git rev-parse --short HEAD) --path %s --builder heroku/buildpacks:18 --env-file ./env_porter
-sudo docker push %s:$(git rev-parse --short HEAD)
-`
-
-func getBuildPackPushStep(envSecretName, folderPath, repoURL string) GithubActionYAMLStep {
-	return GithubActionYAMLStep{
-		Name: "Docker build, push",
-		ID:   "docker_build_push",
-		Run:  fmt.Sprintf(buildPackPush, envSecretName, envSecretName, repoURL, folderPath, repoURL),
-	}
-}
-
-const deployPorter string = `
-curl -X POST "%s/api/webhooks/deploy/${{secrets.%s}}?commit=$(git rev-parse --short HEAD)"
-`
-
-func deployPorterWebhookStep(serverURL, webhookTokenSecretName string) GithubActionYAMLStep {
-	return GithubActionYAMLStep{
-		Name: "Deploy on Porter",
-		ID:   "deploy_porter",
-		Run:  fmt.Sprintf(deployPorter, serverURL, webhookTokenSecretName),
 	}
 }