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

toggle skipping redeploys on linked apps (#4407)

ianedwards 2 лет назад
Родитель
Сommit
b4263a4751

+ 12 - 10
api/client/env_groups.go

@@ -26,12 +26,13 @@ func (c *Client) GetLatestEnvGroupVariables(
 
 // UpdateEnvGroupInput is the input for the UpdateEnvGroup method
 type UpdateEnvGroupInput struct {
-	ProjectID    uint
-	ClusterID    uint
-	EnvGroupName string
-	Variables    map[string]string
-	Secrets      map[string]string
-	Deletions    environment_groups.EnvVariableDeletions
+	ProjectID     uint
+	ClusterID     uint
+	EnvGroupName  string
+	Variables     map[string]string
+	Secrets       map[string]string
+	Deletions     environment_groups.EnvVariableDeletions
+	SkipRedeploys bool
 }
 
 // UpdateEnvGroup creates or updates an environment group with the provided variables
@@ -40,10 +41,11 @@ func (c *Client) UpdateEnvGroup(
 	inp UpdateEnvGroupInput,
 ) error {
 	req := &environment_groups.UpdateEnvironmentGroupRequest{
-		Name:            inp.EnvGroupName,
-		Variables:       inp.Variables,
-		SecretVariables: inp.Secrets,
-		Deletions:       inp.Deletions,
+		Name:              inp.EnvGroupName,
+		Variables:         inp.Variables,
+		SecretVariables:   inp.Secrets,
+		Deletions:         inp.Deletions,
+		SkipAppAutoDeploy: inp.SkipRedeploys,
 	}
 
 	return c.postRequest(

+ 4 - 1
api/server/handlers/environment_groups/create.go

@@ -62,6 +62,9 @@ type UpdateEnvironmentGroupRequest struct {
 
 	// Deletions is a set of keys to delete from the environment group
 	Deletions EnvVariableDeletions `json:"deletions"`
+
+	// SkipAppAutoDeploy is a flag to determine if the app should be auto deployed
+	SkipAppAutoDeploy bool `json:"skip_app_auto_deploy"`
 }
 type UpdateEnvironmentGroupResponse struct {
 	// Name of the env group to create or update
@@ -121,7 +124,7 @@ func (c *UpdateEnvironmentGroupHandler) ServeHTTP(w http.ResponseWriter, r *http
 				Secrets:   request.Deletions.Secrets,
 			},
 			IsEnvOverride:     request.IsEnvOverride,
-			SkipAppAutoDeploy: true, // switch to false once CCP changes are in, so as to not miss any redeploys
+			SkipAppAutoDeploy: request.SkipAppAutoDeploy,
 		}))
 		if err != nil {
 			err := telemetry.Error(ctx, span, err, "unable to create environment group")

+ 23 - 7
cli/cmd/commands/env.go

@@ -78,7 +78,8 @@ Optionally, specify a file to write the environment variables to. Otherwise the
 		Short: "Set environment variables for an app or environment group",
 		Long: `Set environment variables for an app or environment group.
 
-Both variables and secrets can be specified as key-value pairs.`,
+Both variables and secrets can be specified as key-value pairs.
+When updating an environment group, all apps linked to the environment group will be re-deployed, unless the --skip-redeploys flag is used.`,
 		Args: cobra.NoArgs,
 		RunE: func(cmd *cobra.Command, args []string) error {
 			return checkLoginAndRunWithConfig(cmd, cliConf, args, setEnv)
@@ -86,13 +87,15 @@ Both variables and secrets can be specified as key-value pairs.`,
 	}
 	setCommand.Flags().StringToStringP("variables", "v", nil, "variables to set")
 	setCommand.Flags().StringToStringP("secrets", "s", nil, "secrets to set")
+	setCommand.Flags().Bool("skip-redeploys", false, "skip re-deploying apps linked to the environment group")
 
 	unsetCommand := &cobra.Command{
 		Use:   "unset",
 		Short: "Unset environment variables for an app or environment group",
 		Long: `Unset environment variables for an app or environment group.
 
-Both variables and secrets can be specified as keys.`,
+Both variables and secrets can be specified as keys.
+When updating an environment group, all apps linked to the environment group will be re-deployed, unless the --skip-redeploys flag is used.`,
 		Args: cobra.NoArgs,
 		RunE: func(cmd *cobra.Command, args []string) error {
 			return checkLoginAndRunWithConfig(cmd, cliConf, args, unsetEnv)
@@ -100,6 +103,7 @@ Both variables and secrets can be specified as keys.`,
 	}
 	unsetCommand.Flags().StringSliceP("variables", "v", nil, "variables to unset")
 	unsetCommand.Flags().StringSliceP("secrets", "s", nil, "secrets to unset")
+	unsetCommand.Flags().Bool("skip-redeploys", false, "skip re-deploying apps linked to the environment group")
 
 	envCmd.AddCommand(pullCommand)
 	envCmd.AddCommand(setCommand)
@@ -176,6 +180,11 @@ func setEnv(ctx context.Context, user *types.GetAuthenticatedUserResponse, clien
 		return fmt.Errorf("could not get secrets: %w", err)
 	}
 
+	skipRedeploys, err := cmd.Flags().GetBool("skip-redeploys")
+	if err != nil {
+		return fmt.Errorf("could not get skip-redeploys: %w", err)
+	}
+
 	envVars = envVariables{
 		Variables: variables,
 		Secrets:   secrets,
@@ -209,11 +218,12 @@ func setEnv(ctx context.Context, user *types.GetAuthenticatedUserResponse, clien
 
 		s.Start()
 		err := client.UpdateEnvGroup(ctx, api.UpdateEnvGroupInput{
-			ProjectID:    cliConf.Project,
-			ClusterID:    cliConf.Cluster,
-			EnvGroupName: envGroupName,
-			Variables:    envVars.Variables,
-			Secrets:      envVars.Secrets,
+			ProjectID:     cliConf.Project,
+			ClusterID:     cliConf.Cluster,
+			EnvGroupName:  envGroupName,
+			Variables:     envVars.Variables,
+			Secrets:       envVars.Secrets,
+			SkipRedeploys: skipRedeploys,
 		})
 		if err != nil {
 			return fmt.Errorf("could not set env group env variables: %w", err)
@@ -246,6 +256,11 @@ func unsetEnv(ctx context.Context, user *types.GetAuthenticatedUserResponse, cli
 		return fmt.Errorf("could not get secrets: %w", err)
 	}
 
+	skipRedeploys, err := cmd.Flags().GetBool("skip-redeploys")
+	if err != nil {
+		return fmt.Errorf("could not get skip-redeploys: %w", err)
+	}
+
 	envVarDeletions = envVariableDeletions{
 		Variables: variables,
 		Secrets:   secrets,
@@ -289,6 +304,7 @@ func unsetEnv(ctx context.Context, user *types.GetAuthenticatedUserResponse, cli
 				Variables: envVarDeletions.Variables,
 				Secrets:   envVarDeletions.Secrets,
 			},
+			SkipRedeploys: skipRedeploys,
 		})
 		if err != nil {
 			return fmt.Errorf("could not unset env group env variables: %w", err)

+ 0 - 10
dashboard/src/main/home/env-dashboard/tabs/EnvVarsTab.tsx

@@ -148,16 +148,6 @@ const EnvVarsTab: React.FC<Props> = ({ envGroup, fetchEnvGroup }) => {
         );
       };
      
-      await api.updateAppsLinkedToEnvironmentGroup(
-        "<token>",
-        {
-          name: envGroup?.name,
-        },
-        {
-          id: currentProject?.id || -1,
-          cluster_id: currentCluster?.id || -1,
-        }
-      );
       fetchEnvGroup();
       setButtonStatus("success");
     } catch (err) {