Просмотр исходного кода

Merge branch 'master' of github.com:porter-dev/porter into 0.8.0-pod-events-managment

jnfrati 4 лет назад
Родитель
Сommit
1eca29a5f2

+ 8 - 9
cli/cmd/api/github_action.go

@@ -11,15 +11,14 @@ import (
 // CreateGithubActionRequest represents the accepted fields for creating
 // CreateGithubActionRequest represents the accepted fields for creating
 // a Github action
 // a Github action
 type CreateGithubActionRequest struct {
 type CreateGithubActionRequest struct {
-	ReleaseID      uint              `json:"release_id" form:"required"`
-	GitRepo        string            `json:"git_repo" form:"required"`
-	GitBranch      string            `json:"git_branch"`
-	ImageRepoURI   string            `json:"image_repo_uri" form:"required"`
-	DockerfilePath string            `json:"dockerfile_path"`
-	FolderPath     string            `json:"folder_path"`
-	GitRepoID      uint              `json:"git_repo_id" form:"required"`
-	BuildEnv       map[string]string `json:"env"`
-	RegistryID     uint              `json:"registry_id"`
+	ReleaseID      uint   `json:"release_id" form:"required"`
+	GitRepo        string `json:"git_repo" form:"required"`
+	GitBranch      string `json:"git_branch"`
+	ImageRepoURI   string `json:"image_repo_uri" form:"required"`
+	DockerfilePath string `json:"dockerfile_path"`
+	FolderPath     string `json:"folder_path"`
+	GitRepoID      uint   `json:"git_repo_id" form:"required"`
+	RegistryID     uint   `json:"registry_id"`
 }
 }
 
 
 // CreateGithubAction creates a Github action with basic authentication
 // CreateGithubAction creates a Github action with basic authentication

+ 9 - 0
cli/cmd/create.go

@@ -74,6 +74,7 @@ var name string
 var values string
 var values string
 var source string
 var source string
 var image string
 var image string
+var registryURL string
 
 
 func init() {
 func init() {
 	rootCmd.AddCommand(createCmd)
 	rootCmd.AddCommand(createCmd)
@@ -137,6 +138,13 @@ func init() {
 		"",
 		"",
 		"if the source is \"registry\", the image to use, in repository:tag format",
 		"if the source is \"registry\", the image to use, in repository:tag format",
 	)
 	)
+
+	createCmd.PersistentFlags().StringVar(
+		&registryURL,
+		"registry-url",
+		"",
+		"the registry URL to use (must exist in \"porter registries list\")",
+	)
 }
 }
 
 
 var supportedKinds = map[string]string{"web": "", "job": "", "worker": ""}
 var supportedKinds = map[string]string{"web": "", "job": "", "worker": ""}
@@ -183,6 +191,7 @@ func createFull(resp *api.AuthCheckResponse, client *api.Client, args []string)
 			},
 			},
 			Kind:        args[0],
 			Kind:        args[0],
 			ReleaseName: name,
 			ReleaseName: name,
+			RegistryURL: registryURL,
 		},
 		},
 	}
 	}
 
 

+ 8 - 1
cli/cmd/deploy/create.go

@@ -25,6 +25,7 @@ type CreateOpts struct {
 
 
 	Kind        string
 	Kind        string
 	ReleaseName string
 	ReleaseName string
+	RegistryURL string
 }
 }
 
 
 // GithubOpts are the options for linking a Github source to the app
 // GithubOpts are the options for linking a Github source to the app
@@ -367,7 +368,13 @@ func (c *CreateAgent) GetImageRepoURL(name, namespace string) (uint, string, err
 	var regID uint
 	var regID uint
 
 
 	for _, reg := range registries {
 	for _, reg := range registries {
-		if reg.URL != "" {
+		if c.CreateOpts.RegistryURL != "" {
+			if c.CreateOpts.RegistryURL == reg.URL {
+				regID = reg.ID
+				imageURI = fmt.Sprintf("%s/%s-%s", reg.URL, name, namespace)
+				break
+			}
+		} else if reg.URL != "" {
 			regID = reg.ID
 			regID = reg.ID
 			imageURI = fmt.Sprintf("%s/%s-%s", reg.URL, name, namespace)
 			imageURI = fmt.Sprintf("%s/%s-%s", reg.URL, name, namespace)
 			break
 			break

+ 1 - 1
cli/cmd/version.go

@@ -7,7 +7,7 @@ import (
 )
 )
 
 
 // Version will be linked by an ldflag during build
 // Version will be linked by an ldflag during build
-var Version string = "v0.5.0"
+var Version string = "v0.8.0"
 
 
 var versionCmd = &cobra.Command{
 var versionCmd = &cobra.Command{
 	Use:     "version",
 	Use:     "version",

+ 2 - 4
dashboard/src/main/home/launch/launch-flow/LaunchFlow.tsx

@@ -73,7 +73,7 @@ class LaunchFlow extends Component<PropsType, StateType> {
     selectedRegistry: null as any,
     selectedRegistry: null as any,
   };
   };
 
 
-  createGHAction = (chartName: string, chartNamespace: string, env?: any) => {
+  createGHAction = (chartName: string, chartNamespace: string) => {
     let { currentProject, currentCluster, setCurrentError } = this.context;
     let { currentProject, currentCluster, setCurrentError } = this.context;
     let {
     let {
       actionConfig,
       actionConfig,
@@ -100,7 +100,6 @@ class LaunchFlow extends Component<PropsType, StateType> {
           folder_path: folderPath,
           folder_path: folderPath,
           image_repo_uri: imageRepoUri,
           image_repo_uri: imageRepoUri,
           git_repo_id: actionConfig.git_repo_id,
           git_repo_id: actionConfig.git_repo_id,
-          env: env,
         },
         },
         {
         {
           project_id: currentProject.id,
           project_id: currentProject.id,
@@ -314,8 +313,7 @@ class LaunchFlow extends Component<PropsType, StateType> {
       )
       )
       .then((res: any) => {
       .then((res: any) => {
         if (sourceType === "repo") {
         if (sourceType === "repo") {
-          let env = rawValues["container.env.normal"];
-          this.createGHAction(name, selectedNamespace, env);
+          this.createGHAction(name, selectedNamespace);
         }
         }
         // this.props.setCurrentView('cluster-dashboard');
         // this.props.setCurrentView('cluster-dashboard');
         this.setState({ saveValuesStatus: "successful" }, () => {
         this.setState({ saveValuesStatus: "successful" }, () => {

+ 0 - 1
dashboard/src/shared/api.tsx

@@ -122,7 +122,6 @@ const createGHAction = baseApi<
     dockerfile_path: string;
     dockerfile_path: string;
     folder_path: string;
     folder_path: string;
     git_repo_id: number;
     git_repo_id: number;
-    env: any;
   },
   },
   {
   {
     project_id: number;
     project_id: number;

+ 10 - 10
internal/forms/git_action.go

@@ -7,19 +7,18 @@ import (
 // CreateGitAction represents the accepted values for creating a
 // CreateGitAction represents the accepted values for creating a
 // github action integration
 // github action integration
 type CreateGitAction struct {
 type CreateGitAction struct {
-	ReleaseID      uint              `json:"release_id" form:"required"`
-	GitRepo        string            `json:"git_repo" form:"required"`
-	GitBranch      string            `json:"git_branch"`
-	ImageRepoURI   string            `json:"image_repo_uri" form:"required"`
-	DockerfilePath string            `json:"dockerfile_path"`
-	FolderPath     string            `json:"folder_path"`
-	GitRepoID      uint              `json:"git_repo_id" form:"required"`
-	BuildEnv       map[string]string `json:"env"`
-	RegistryID     uint              `json:"registry_id"`
+	ReleaseID      uint   `json:"release_id" form:"required"`
+	GitRepo        string `json:"git_repo" form:"required"`
+	GitBranch      string `json:"git_branch"`
+	ImageRepoURI   string `json:"image_repo_uri" form:"required"`
+	DockerfilePath string `json:"dockerfile_path"`
+	FolderPath     string `json:"folder_path"`
+	GitRepoID      uint   `json:"git_repo_id" form:"required"`
+	RegistryID     uint   `json:"registry_id"`
 }
 }
 
 
 // ToGitActionConfig converts the form to a gorm git action config model
 // ToGitActionConfig converts the form to a gorm git action config model
-func (ca *CreateGitAction) ToGitActionConfig() (*models.GitActionConfig, error) {
+func (ca *CreateGitAction) ToGitActionConfig(version string) (*models.GitActionConfig, error) {
 	return &models.GitActionConfig{
 	return &models.GitActionConfig{
 		ReleaseID:            ca.ReleaseID,
 		ReleaseID:            ca.ReleaseID,
 		GitRepo:              ca.GitRepo,
 		GitRepo:              ca.GitRepo,
@@ -29,6 +28,7 @@ func (ca *CreateGitAction) ToGitActionConfig() (*models.GitActionConfig, error)
 		FolderPath:           ca.FolderPath,
 		FolderPath:           ca.FolderPath,
 		GithubInstallationID: ca.GitRepoID,
 		GithubInstallationID: ca.GitRepoID,
 		IsInstallation:       true,
 		IsInstallation:       true,
+		Version:              version,
 	}, nil
 	}, nil
 }
 }
 
 

+ 10 - 26
internal/integrations/ci/actions/actions.go

@@ -32,12 +32,11 @@ type GithubActions struct {
 	GithubAppSecretPath  string
 	GithubAppSecretPath  string
 	GithubInstallationID uint
 	GithubInstallationID uint
 
 
-	WebhookToken string
-	PorterToken  string
-	BuildEnv     map[string]string
-	ProjectID    uint
-	ClusterID    uint
-	ReleaseName  string
+	PorterToken string
+	BuildEnv    map[string]string
+	ProjectID   uint
+	ClusterID   uint
+	ReleaseName string
 
 
 	GitBranch      string
 	GitBranch      string
 	DockerFilePath string
 	DockerFilePath string
@@ -45,6 +44,7 @@ type GithubActions struct {
 	ImageRepoURL   string
 	ImageRepoURL   string
 
 
 	defaultBranch string
 	defaultBranch string
+	Version       string
 }
 }
 
 
 func (g *GithubActions) Setup() (string, error) {
 func (g *GithubActions) Setup() (string, error) {
@@ -67,24 +67,8 @@ func (g *GithubActions) Setup() (string, error) {
 
 
 	g.defaultBranch = repo.GetDefaultBranch()
 	g.defaultBranch = repo.GetDefaultBranch()
 
 
-	// create a new secret with a webhook token
-	err = g.createGithubSecret(client, g.getWebhookSecretName(), g.WebhookToken)
-
-	if err != nil {
-		return "", err
-	}
-
-	// create new secrets porter token, project id, and cluster id
-	err = g.createGithubSecret(client, g.getPorterTokenSecretName(), g.PorterToken)
-
-	if err != nil {
-		return "", err
-	}
-
-	// create a new secret with the build variables
-	err = g.createEnvSecret(client)
-
-	if err != nil {
+	// create porter token secret
+	if err := g.createGithubSecret(client, g.getPorterTokenSecretName(), g.PorterToken); err != nil {
 		return "", err
 		return "", err
 	}
 	}
 
 
@@ -140,6 +124,7 @@ type GithubActionYAMLStep struct {
 	Timeout uint64            `yaml:"timeout-minutes,omitempty"`
 	Timeout uint64            `yaml:"timeout-minutes,omitempty"`
 	Uses    string            `yaml:"uses,omitempty"`
 	Uses    string            `yaml:"uses,omitempty"`
 	Run     string            `yaml:"run,omitempty"`
 	Run     string            `yaml:"run,omitempty"`
+	With    map[string]string `yaml:"with,omitempty"`
 	Env     map[string]string `yaml:"env,omitempty"`
 	Env     map[string]string `yaml:"env,omitempty"`
 }
 }
 
 
@@ -167,8 +152,7 @@ type GithubActionYAML struct {
 func (g *GithubActions) GetGithubActionYAML() ([]byte, error) {
 func (g *GithubActions) GetGithubActionYAML() ([]byte, error) {
 	gaSteps := []GithubActionYAMLStep{
 	gaSteps := []GithubActionYAMLStep{
 		getCheckoutCodeStep(),
 		getCheckoutCodeStep(),
-		getDownloadPorterStep(),
-		getConfigurePorterStep(g.ServerURL, g.getPorterTokenSecretName(), g.ProjectID, g.ClusterID, g.ReleaseName),
+		getUpdateAppStep(g.ServerURL, g.getPorterTokenSecretName(), g.ProjectID, g.ClusterID, g.ReleaseName, g.Version),
 	}
 	}
 
 
 	branch := g.GitBranch
 	branch := g.GitBranch

+ 12 - 29
internal/integrations/ci/actions/steps.go

@@ -4,6 +4,8 @@ import (
 	"fmt"
 	"fmt"
 )
 )
 
 
+const updateAppActionName = "porter-dev/porter-update-action"
+
 func getCheckoutCodeStep() GithubActionYAMLStep {
 func getCheckoutCodeStep() GithubActionYAMLStep {
 	return GithubActionYAMLStep{
 	return GithubActionYAMLStep{
 		Name: "Checkout code",
 		Name: "Checkout code",
@@ -11,36 +13,17 @@ 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 \")
-name=$(basename $name)
-curl -L https://github.com/porter-dev/porter/releases/latest/download/$name --output $name
-unzip -a $name
-rm $name
-chmod +x ./porter
-sudo mv ./porter /usr/local/bin/porter
-`
-
-func getDownloadPorterStep() GithubActionYAMLStep {
+func getUpdateAppStep(serverURL, porterTokenSecretName string, projectID uint, clusterID uint, appName string, actionVersion string) GithubActionYAMLStep {
 	return GithubActionYAMLStep{
 	return GithubActionYAMLStep{
-		Name: "Download Porter",
-		ID:   "download_porter",
-		Run:  download,
-	}
-}
-
-const configure string = `porter update --app %s`
-
-func getConfigurePorterStep(serverURL, porterTokenSecretName string, projectID uint, clusterID uint, appName string) GithubActionYAMLStep {
-	return GithubActionYAMLStep{
-		Name:    "Update Porter App",
-		ID:      "update_porter",
-		Run:     fmt.Sprintf(configure, appName),
-		Timeout: 20,
-		Env: map[string]string{
-			"PORTER_TOKEN":   fmt.Sprintf("${{ secrets.%s }}", porterTokenSecretName),
-			"PORTER_HOST":    serverURL,
-			"PORTER_PROJECT": fmt.Sprintf("%d", projectID),
-			"PORTER_CLUSTER": fmt.Sprintf("%d", clusterID),
+		Name: "Update Porter App",
+		Uses: fmt.Sprintf("%s@%s", updateAppActionName, actionVersion),
+		With: map[string]string{
+			"app":     appName,
+			"cluster": fmt.Sprintf("%d", clusterID),
+			"host":    serverURL,
+			"project": fmt.Sprintf("%d", projectID),
+			"token":   fmt.Sprintf("${{ secrets.%s }}", porterTokenSecretName),
 		},
 		},
+		Timeout: 20,
 	}
 	}
 }
 }

+ 2 - 0
internal/models/gitrepo.go

@@ -75,6 +75,8 @@ type GitActionConfig struct {
 
 
 	// Determines on how authentication is performed on this action
 	// Determines on how authentication is performed on this action
 	IsInstallation bool `json:"is_installation"`
 	IsInstallation bool `json:"is_installation"`
+
+	Version string `json:"version" gorm:"default:v0.0.1"`
 }
 }
 
 
 // GitActionConfigExternal is an external GitActionConfig to be shared over REST
 // GitActionConfigExternal is an external GitActionConfig to be shared over REST

+ 5 - 1
server/api/api.go

@@ -316,7 +316,11 @@ func (app *App) getTokenFromRequest(r *http.Request) *token.Token {
 
 
 	reqToken = strings.TrimSpace(splitToken[1])
 	reqToken = strings.TrimSpace(splitToken[1])
 
 
-	tok, _ := token.GetTokenFromEncoded(reqToken, app.tokenConf)
+	tok, err := token.GetTokenFromEncoded(reqToken, app.tokenConf)
+
+	if err != nil {
+		return nil
+	}
 
 
 	return tok
 	return tok
 }
 }

+ 0 - 2
server/api/deploy_handler.go

@@ -167,7 +167,6 @@ func (app *App) HandleDeployTemplate(w http.ResponseWriter, r *http.Request) {
 			ImageRepoURI:   form.GithubActionConfig.ImageRepoURI,
 			ImageRepoURI:   form.GithubActionConfig.ImageRepoURI,
 			DockerfilePath: form.GithubActionConfig.DockerfilePath,
 			DockerfilePath: form.GithubActionConfig.DockerfilePath,
 			GitRepoID:      form.GithubActionConfig.GitRepoID,
 			GitRepoID:      form.GithubActionConfig.GitRepoID,
-			BuildEnv:       form.GithubActionConfig.BuildEnv,
 			RegistryID:     form.GithubActionConfig.RegistryID,
 			RegistryID:     form.GithubActionConfig.RegistryID,
 		}
 		}
 
 
@@ -381,7 +380,6 @@ func (app *App) HandleUninstallTemplate(w http.ResponseWriter, r *http.Request)
 					GitRepoOwner:           repoSplit[0],
 					GitRepoOwner:           repoSplit[0],
 					Repo:                   *app.Repo,
 					Repo:                   *app.Repo,
 					GithubConf:             app.GithubProjectConf,
 					GithubConf:             app.GithubProjectConf,
-					WebhookToken:           release.WebhookToken,
 					ProjectID:              uint(projID),
 					ProjectID:              uint(projID),
 					ReleaseName:            name,
 					ReleaseName:            name,
 					GitBranch:              gitAction.GitBranch,
 					GitBranch:              gitAction.GitBranch,

+ 6 - 3
server/api/git_action_handler.go

@@ -16,6 +16,10 @@ import (
 	"github.com/porter-dev/porter/internal/registry"
 	"github.com/porter-dev/porter/internal/registry"
 )
 )
 
 
+const (
+	updateAppActionVersion = "v0.1.0"
+)
+
 // HandleCreateGitAction creates a new Github action in a repository for a given
 // HandleCreateGitAction creates a new Github action in a repository for a given
 // release
 // release
 func (app *App) HandleCreateGitAction(w http.ResponseWriter, r *http.Request) {
 func (app *App) HandleCreateGitAction(w http.ResponseWriter, r *http.Request) {
@@ -108,7 +112,7 @@ func (app *App) createGitActionFromForm(
 	}
 	}
 
 
 	// convert the form to a git action config
 	// convert the form to a git action config
-	gitAction, err := form.ToGitActionConfig()
+	gitAction, err := form.ToGitActionConfig(updateAppActionVersion)
 
 
 	if err != nil {
 	if err != nil {
 		app.handleErrorFormDecoding(err, ErrProjectDecode, w)
 		app.handleErrorFormDecoding(err, ErrProjectDecode, w)
@@ -165,7 +169,6 @@ func (app *App) createGitActionFromForm(
 		GitRepoOwner:           repoSplit[0],
 		GitRepoOwner:           repoSplit[0],
 		Repo:                   *app.Repo,
 		Repo:                   *app.Repo,
 		GithubConf:             app.GithubProjectConf,
 		GithubConf:             app.GithubProjectConf,
-		WebhookToken:           release.WebhookToken,
 		ProjectID:              uint(projID),
 		ProjectID:              uint(projID),
 		ReleaseName:            name,
 		ReleaseName:            name,
 		GitBranch:              gitAction.GitBranch,
 		GitBranch:              gitAction.GitBranch,
@@ -173,8 +176,8 @@ func (app *App) createGitActionFromForm(
 		FolderPath:             gitAction.FolderPath,
 		FolderPath:             gitAction.FolderPath,
 		ImageRepoURL:           gitAction.ImageRepoURI,
 		ImageRepoURL:           gitAction.ImageRepoURI,
 		PorterToken:            encoded,
 		PorterToken:            encoded,
-		BuildEnv:               form.BuildEnv,
 		ClusterID:              release.ClusterID,
 		ClusterID:              release.ClusterID,
+		Version:                gitAction.Version,
 	}
 	}
 
 
 	_, err = gaRunner.Setup()
 	_, err = gaRunner.Setup()

+ 8 - 3
server/api/git_repo_handler.go

@@ -4,8 +4,6 @@ import (
 	"context"
 	"context"
 	"encoding/json"
 	"encoding/json"
 	"fmt"
 	"fmt"
-	"github.com/porter-dev/porter/internal/models"
-	"golang.org/x/oauth2"
 	"net/http"
 	"net/http"
 	"net/url"
 	"net/url"
 	"regexp"
 	"regexp"
@@ -13,6 +11,9 @@ import (
 	"strings"
 	"strings"
 	"sync"
 	"sync"
 
 
+	"github.com/porter-dev/porter/internal/models"
+	"golang.org/x/oauth2"
+
 	"github.com/bradleyfalzon/ghinstallation"
 	"github.com/bradleyfalzon/ghinstallation"
 	"github.com/go-chi/chi"
 	"github.com/go-chi/chi"
 	"github.com/google/go-github/github"
 	"github.com/google/go-github/github"
@@ -20,10 +21,13 @@ import (
 
 
 // HandleListProjectGitRepos returns a list of git repos for a project
 // HandleListProjectGitRepos returns a list of git repos for a project
 func (app *App) HandleListProjectGitRepos(w http.ResponseWriter, r *http.Request) {
 func (app *App) HandleListProjectGitRepos(w http.ResponseWriter, r *http.Request) {
-
 	tok, err := app.getGithubAppOauthTokenFromRequest(r)
 	tok, err := app.getGithubAppOauthTokenFromRequest(r)
 
 
 	if err != nil {
 	if err != nil {
+		app.Logger.Warn().Err(err).
+			Str("info", "github app oauth token error").
+			Msg("")
+
 		json.NewEncoder(w).Encode(make([]*models.GitRepoExternal, 0))
 		json.NewEncoder(w).Encode(make([]*models.GitRepoExternal, 0))
 		return
 		return
 	}
 	}
@@ -35,6 +39,7 @@ func (app *App) HandleListProjectGitRepos(w http.ResponseWriter, r *http.Request
 	AuthUser, _, err := client.Users.Get(context.Background(), "")
 	AuthUser, _, err := client.Users.Get(context.Background(), "")
 
 
 	if err != nil {
 	if err != nil {
+
 		app.handleErrorInternal(err, w)
 		app.handleErrorInternal(err, w)
 		return
 		return
 	}
 	}

+ 8 - 7
server/api/integration_handler.go

@@ -7,12 +7,6 @@ import (
 	"encoding/hex"
 	"encoding/hex"
 	"encoding/json"
 	"encoding/json"
 	"fmt"
 	"fmt"
-	"github.com/go-chi/chi"
-	"github.com/google/go-github/github"
-	"github.com/porter-dev/porter/internal/forms"
-	"github.com/porter-dev/porter/internal/oauth"
-	"golang.org/x/oauth2"
-	"gorm.io/gorm"
 	"io/ioutil"
 	"io/ioutil"
 	"net/http"
 	"net/http"
 	"net/url"
 	"net/url"
@@ -20,6 +14,13 @@ import (
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
 
 
+	"github.com/go-chi/chi"
+	"github.com/google/go-github/github"
+	"github.com/porter-dev/porter/internal/forms"
+	"github.com/porter-dev/porter/internal/oauth"
+	"golang.org/x/oauth2"
+	"gorm.io/gorm"
+
 	"github.com/porter-dev/porter/internal/models/integrations"
 	"github.com/porter-dev/porter/internal/models/integrations"
 	ints "github.com/porter-dev/porter/internal/models/integrations"
 	ints "github.com/porter-dev/porter/internal/models/integrations"
 )
 )
@@ -583,7 +584,7 @@ func (app *App) getGithubAppOauthTokenFromRequest(r *http.Request) (*oauth2.Toke
 	oauthInt, err := app.Repo.GithubAppOAuthIntegration.ReadGithubAppOauthIntegration(user.GithubAppIntegrationID)
 	oauthInt, err := app.Repo.GithubAppOAuthIntegration.ReadGithubAppOauthIntegration(user.GithubAppIntegrationID)
 
 
 	if err != nil {
 	if err != nil {
-		return nil, err
+		return nil, fmt.Errorf("Could not get GH app integration for user %d: %s", user.ID, err.Error())
 	}
 	}
 
 
 	_, _, err = oauth.GetAccessToken(oauthInt.SharedOAuthModel,
 	_, _, err = oauth.GetAccessToken(oauthInt.SharedOAuthModel,

+ 28 - 14
server/api/release_handler.go

@@ -40,6 +40,10 @@ const (
 	ErrReleaseDeploy
 	ErrReleaseDeploy
 )
 )
 
 
+var (
+	createEnvSecretConstraint, _ = semver.NewConstraint(" < 0.1.0")
+)
+
 // HandleListReleases retrieves a list of releases for a cluster
 // HandleListReleases retrieves a list of releases for a cluster
 // with various filter options
 // with various filter options
 func (app *App) HandleListReleases(w http.ResponseWriter, r *http.Request) {
 func (app *App) HandleListReleases(w http.ResponseWriter, r *http.Request) {
@@ -1117,7 +1121,6 @@ func (app *App) HandleUpgradeRelease(w http.ResponseWriter, r *http.Request) {
 					GitRepoOwner:           repoSplit[0],
 					GitRepoOwner:           repoSplit[0],
 					Repo:                   *app.Repo,
 					Repo:                   *app.Repo,
 					GithubConf:             app.GithubProjectConf,
 					GithubConf:             app.GithubProjectConf,
-					WebhookToken:           release.WebhookToken,
 					ProjectID:              uint(projID),
 					ProjectID:              uint(projID),
 					ReleaseName:            name,
 					ReleaseName:            name,
 					GitBranch:              gitAction.GitBranch,
 					GitBranch:              gitAction.GitBranch,
@@ -1126,15 +1129,21 @@ func (app *App) HandleUpgradeRelease(w http.ResponseWriter, r *http.Request) {
 					ImageRepoURL:           gitAction.ImageRepoURI,
 					ImageRepoURL:           gitAction.ImageRepoURI,
 					BuildEnv:               cEnv.Container.Env.Normal,
 					BuildEnv:               cEnv.Container.Env.Normal,
 					ClusterID:              release.ClusterID,
 					ClusterID:              release.ClusterID,
+					Version:                gitAction.Version,
 				}
 				}
 
 
-				err = gaRunner.CreateEnvSecret()
-
+				actionVersion, err := semver.NewVersion(gaRunner.Version)
 				if err != nil {
 				if err != nil {
-					app.sendExternalError(err, http.StatusInternalServerError, HTTPError{
-						Code:   ErrReleaseReadData,
-						Errors: []string{"could not update github secret"},
-					}, w)
+					app.handleErrorInternal(err, w)
+				}
+
+				if createEnvSecretConstraint.Check(actionVersion) {
+					if err := gaRunner.CreateEnvSecret(); err != nil {
+						app.sendExternalError(err, http.StatusInternalServerError, HTTPError{
+							Code:   ErrReleaseReadData,
+							Errors: []string{"could not update github secret"},
+						}, w)
+					}
 				}
 				}
 			}
 			}
 		}
 		}
@@ -1536,7 +1545,6 @@ func (app *App) HandleRollbackRelease(w http.ResponseWriter, r *http.Request) {
 					GitRepoOwner:           repoSplit[0],
 					GitRepoOwner:           repoSplit[0],
 					Repo:                   *app.Repo,
 					Repo:                   *app.Repo,
 					GithubConf:             app.GithubProjectConf,
 					GithubConf:             app.GithubProjectConf,
-					WebhookToken:           release.WebhookToken,
 					ProjectID:              uint(projID),
 					ProjectID:              uint(projID),
 					ReleaseName:            name,
 					ReleaseName:            name,
 					GitBranch:              gitAction.GitBranch,
 					GitBranch:              gitAction.GitBranch,
@@ -1545,15 +1553,21 @@ func (app *App) HandleRollbackRelease(w http.ResponseWriter, r *http.Request) {
 					ImageRepoURL:           gitAction.ImageRepoURI,
 					ImageRepoURL:           gitAction.ImageRepoURI,
 					BuildEnv:               cEnv.Container.Env.Normal,
 					BuildEnv:               cEnv.Container.Env.Normal,
 					ClusterID:              release.ClusterID,
 					ClusterID:              release.ClusterID,
+					Version:                gitAction.Version,
 				}
 				}
 
 
-				err = gaRunner.CreateEnvSecret()
-
+				actionVersion, err := semver.NewVersion(gaRunner.Version)
 				if err != nil {
 				if err != nil {
-					app.sendExternalError(err, http.StatusInternalServerError, HTTPError{
-						Code:   ErrReleaseReadData,
-						Errors: []string{"could not update github secret"},
-					}, w)
+					app.handleErrorInternal(err, w)
+				}
+
+				if createEnvSecretConstraint.Check(actionVersion) {
+					if err := gaRunner.CreateEnvSecret(); err != nil {
+						app.sendExternalError(err, http.StatusInternalServerError, HTTPError{
+							Code:   ErrReleaseReadData,
+							Errors: []string{"could not update github secret"},
+						}, w)
+					}
 				}
 				}
 			}
 			}
 		}
 		}

+ 1 - 1
server/api/user_handler.go

@@ -848,7 +848,7 @@ func (app *App) getUserIDFromRequest(r *http.Request) (uint, error) {
 	session, err := app.Store.Get(r, app.ServerConf.CookieName)
 	session, err := app.Store.Get(r, app.ServerConf.CookieName)
 
 
 	if err != nil {
 	if err != nil {
-		return 0, err
+		return 0, fmt.Errorf("could not get session: %s", err.Error())
 	}
 	}
 
 
 	sessID, ok := session.Values["user_id"]
 	sessID, ok := session.Values["user_id"]