Skip to content

Commit

Permalink
toggle skipping redeploys on linked apps (#4407)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianedwards authored Mar 13, 2024
1 parent 7f7bd45 commit b4263a4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 28 deletions.
22 changes: 12 additions & 10 deletions api/client/env_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion api/server/handlers/environment_groups/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
30 changes: 23 additions & 7 deletions cli/cmd/commands/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,32 @@ 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)
},
}
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)
},
}
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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 0 additions & 10 deletions dashboard/src/main/home/env-dashboard/tabs/EnvVarsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b4263a4

Please sign in to comment.