Răsfoiți Sursa

Merge branch 'master' into nafees/hotfixes

Mohammed Nafees 4 ani în urmă
părinte
comite
c6f10d0e5c

+ 2 - 2
.github/workflows/dev.yaml

@@ -8,7 +8,7 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - name: Set up Cloud SDK
-        uses: google-github-actions/setup-gcloud@master
+        uses: google-github-actions/setup-gcloud@v0
         with:
           project_id: ${{ secrets.GCP_PROJECT_ID }}
           service_account_key: ${{ secrets.GCP_SA_KEY }}
@@ -55,7 +55,7 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - name: Set up Cloud SDK
-        uses: google-github-actions/setup-gcloud@master
+        uses: google-github-actions/setup-gcloud@v0
         with:
           project_id: ${{ secrets.GCP_PROJECT_ID }}
           service_account_key: ${{ secrets.GCP_SA_KEY }}

+ 2 - 2
.github/workflows/production.yaml

@@ -8,7 +8,7 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - name: Set up Cloud SDK
-        uses: google-github-actions/setup-gcloud@master
+        uses: google-github-actions/setup-gcloud@v0
         with:
           project_id: ${{ secrets.GCP_PROJECT_ID }}
           service_account_key: ${{ secrets.GCP_SA_KEY }}
@@ -57,7 +57,7 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - name: Set up Cloud SDK
-        uses: google-github-actions/setup-gcloud@master
+        uses: google-github-actions/setup-gcloud@v0
         with:
           project_id: ${{ secrets.GCP_PROJECT_ID }}
           service_account_key: ${{ secrets.GCP_SA_KEY }}

+ 2 - 2
.github/workflows/staging.yaml

@@ -8,7 +8,7 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - name: Set up Cloud SDK
-        uses: google-github-actions/setup-gcloud@master
+        uses: google-github-actions/setup-gcloud@v0
         with:
           project_id: ${{ secrets.GCP_PROJECT_ID }}
           service_account_key: ${{ secrets.GCP_SA_KEY }}
@@ -56,7 +56,7 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - name: Set up Cloud SDK
-        uses: google-github-actions/setup-gcloud@master
+        uses: google-github-actions/setup-gcloud@v0
         with:
           project_id: ${{ secrets.GCP_PROJECT_ID }}
           service_account_key: ${{ secrets.GCP_SA_KEY }}

+ 12 - 9
cli/cmd/bluegreen.go

@@ -141,17 +141,19 @@ func bluegreenSwitch(_ *types.GetAuthenticatedUserResponse, client *api.Client,
 					if currActiveImage == "" {
 						err = deployAgent.UpdateImageAndValues(map[string]interface{}{
 							"bluegreen": map[string]interface{}{
-								"enabled":        true,
-								"activeImageTag": tag,
-								"imageTags":      []string{tag},
+								"enabled":                  true,
+								"disablePrimaryDeployment": true,
+								"activeImageTag":           tag,
+								"imageTags":                []string{tag},
 							},
 						})
 					} else {
 						err = deployAgent.UpdateImageAndValues(map[string]interface{}{
 							"bluegreen": map[string]interface{}{
-								"enabled":        true,
-								"activeImageTag": tag,
-								"imageTags":      []string{currActiveImage, tag},
+								"enabled":                  true,
+								"disablePrimaryDeployment": true,
+								"activeImageTag":           tag,
+								"imageTags":                []string{currActiveImage, tag},
 							},
 						})
 					}
@@ -192,9 +194,10 @@ func bluegreenSwitch(_ *types.GetAuthenticatedUserResponse, client *api.Client,
 
 	err = deployAgent.UpdateImageAndValues(map[string]interface{}{
 		"bluegreen": map[string]interface{}{
-			"enabled":        true,
-			"activeImageTag": tag,
-			"imageTags":      []string{tag},
+			"enabled":                  true,
+			"disablePrimaryDeployment": true,
+			"activeImageTag":           tag,
+			"imageTags":                []string{tag},
 		},
 	})
 

+ 18 - 4
cli/cmd/create.go

@@ -12,7 +12,9 @@ import (
 	"github.com/porter-dev/porter/api/types"
 	"github.com/porter-dev/porter/cli/cmd/deploy"
 	"github.com/porter-dev/porter/cli/cmd/gitutils"
+	"github.com/porter-dev/porter/cli/cmd/utils"
 	"github.com/spf13/cobra"
+	"k8s.io/client-go/util/homedir"
 	"sigs.k8s.io/yaml"
 )
 
@@ -175,20 +177,32 @@ func createFull(_ *types.GetAuthenticatedUserResponse, client *api.Client, args
 
 	var err error
 
-	// read the values if necessary
-	valuesObj, err := readValuesFile()
+	fullPath, err := filepath.Abs(localPath)
+
 	if err != nil {
 		return err
 	}
 
-	color.New(color.FgGreen).Printf("Creating %s release: %s\n", args[0], name)
+	if os.Getenv("GITHUB_ACTIONS") == "" && source == "local" && fullPath == homedir.HomeDir() {
+		proceed, err := utils.PromptConfirm("You are deploying your home directory. Do you want to continue?", false)
 
-	fullPath, err := filepath.Abs(localPath)
+		if err != nil {
+			return err
+		}
 
+		if !proceed {
+			return nil
+		}
+	}
+
+	// read the values if necessary
+	valuesObj, err := readValuesFile()
 	if err != nil {
 		return err
 	}
 
+	color.New(color.FgGreen).Printf("Creating %s release: %s\n", args[0], name)
+
 	var buildMethod deploy.DeployBuildType
 
 	if method != "" {

+ 21 - 0
cli/cmd/deploy.go

@@ -3,13 +3,16 @@ package cmd
 import (
 	"fmt"
 	"os"
+	"path/filepath"
 	"strings"
 
 	"github.com/fatih/color"
 	api "github.com/porter-dev/porter/api/client"
 	"github.com/porter-dev/porter/api/types"
 	"github.com/porter-dev/porter/cli/cmd/deploy"
+	"github.com/porter-dev/porter/cli/cmd/utils"
 	"github.com/spf13/cobra"
+	"k8s.io/client-go/util/homedir"
 )
 
 // updateCmd represents the "porter update" base command when called
@@ -318,6 +321,24 @@ func init() {
 }
 
 func updateFull(_ *types.GetAuthenticatedUserResponse, client *api.Client, args []string) error {
+	fullPath, err := filepath.Abs(localPath)
+
+	if err != nil {
+		return err
+	}
+
+	if os.Getenv("GITHUB_ACTIONS") == "" && source == "local" && fullPath == homedir.HomeDir() {
+		proceed, err := utils.PromptConfirm("You are deploying your home directory. Do you want to continue?", false)
+
+		if err != nil {
+			return err
+		}
+
+		if !proceed {
+			return nil
+		}
+	}
+
 	color.New(color.FgGreen).Println("Deploying app:", app)
 
 	updateAgent, err := updateGetAgent(client)

+ 4 - 3
cli/cmd/deploy/deploy.go

@@ -347,9 +347,10 @@ func (d *DeployAgent) UpdateImageAndValues(overrideValues map[string]interface{}
 	// this has been modified already and inserted into overrideValues.
 	if activeBlueGreenTagVal != "" && activeBlueGreenTagVal != d.tag {
 		mergedValues["bluegreen"] = map[string]interface{}{
-			"enabled":        true,
-			"activeImageTag": activeBlueGreenTagVal,
-			"imageTags":      []string{activeBlueGreenTagVal, d.tag},
+			"enabled":                  true,
+			"disablePrimaryDeployment": true,
+			"activeImageTag":           activeBlueGreenTagVal,
+			"imageTags":                []string{activeBlueGreenTagVal, d.tag},
 		}
 	}
 

+ 17 - 0
cli/cmd/utils/prompt.go

@@ -92,3 +92,20 @@ func PromptMultiselect(prompt string, options []string) ([]string, error) {
 
 	return ans, err
 }
+
+func PromptConfirm(message string, defaultVal bool) (bool, error) {
+	value := false
+
+	prompt := &survey.Confirm{
+		Message: message,
+		Default: defaultVal,
+	}
+
+	err := survey.AskOne(prompt, &value)
+
+	if err != nil {
+		return false, err
+	}
+
+	return value, nil
+}

+ 26 - 21
dashboard/src/main/home/project-settings/InviteList.tsx

@@ -44,7 +44,7 @@ const InvitePage: React.FunctionComponent<Props> = ({}) => {
 
   useEffect(() => {
     api
-      .getAvailableRoles("<token>", {}, { project_id: currentProject.id })
+      .getAvailableRoles("<token>", {}, { project_id: currentProject?.id })
       .then(({ data }: { data: string[] }) => {
         const availableRoleList = data?.map((role) => ({
           value: role,
@@ -69,7 +69,7 @@ const InvitePage: React.FunctionComponent<Props> = ({}) => {
         "<token>",
         {},
         {
-          id: currentProject.id,
+          id: currentProject?.id,
         }
       );
       invites = response.data.filter((i: InviteType) => !i.accepted);
@@ -82,7 +82,7 @@ const InvitePage: React.FunctionComponent<Props> = ({}) => {
         "<token>",
         {},
         {
-          project_id: currentProject.id,
+          project_id: currentProject?.id,
         }
       );
       collaborators = parseCollaboratorsResponse(response.data);
@@ -96,24 +96,25 @@ const InvitePage: React.FunctionComponent<Props> = ({}) => {
   const parseCollaboratorsResponse = (
     collaborators: Array<Collaborator>
   ): Array<InviteType> => {
-    return (
-      collaborators
-        // Parse role id to number
-        .map((c) => ({ ...c, id: Number(c.id) }))
-        // Sort them so the owner will be first allways
-        .sort((curr, prev) => curr.id - prev.id)
-        // Remove the owner from list
-        .slice(1)
-        // Parse the remainings to InviteType
-        .map((c) => ({
-          email: c.email,
-          expired: false,
-          id: Number(c.user_id),
-          kind: c.kind,
-          accepted: true,
-          token: "",
-        }))
-    );
+    const admins = collaborators
+      .filter((c) => c.kind === "admin")
+      .map((c) => ({ ...c, id: Number(c.id) }))
+      .sort((curr, prev) => curr.id - prev.id)
+      .slice(1);
+
+    const nonAdmins = collaborators
+      .filter((c) => c.kind !== "admin")
+      .map((c) => ({ ...c, id: Number(c.id) }))
+      .sort((curr, prev) => curr.id - prev.id);
+
+    return [...admins, ...nonAdmins].map((c) => ({
+      email: c.email,
+      expired: false,
+      id: Number(c.user_id),
+      kind: c.kind,
+      accepted: true,
+      token: "",
+    }));
   };
 
   const createInvite = () => {
@@ -333,6 +334,10 @@ const InvitePage: React.FunctionComponent<Props> = ({}) => {
     }/invites/${token}
     `;
 
+    if (!user) {
+      return [];
+    }
+
     const mappedInviteList = inviteList.map(
       ({ accepted, expired, token, ...rest }) => {
         const currentUser: boolean = user.email === rest.email;