-
Notifications
You must be signed in to change notification settings - Fork 24
/
application_update.go
118 lines (98 loc) · 4.07 KB
/
application_update.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package cmd
import (
"context"
"fmt"
"os"
"github.com/pterm/pterm"
"github.com/qovery/qovery-client-go"
"github.com/spf13/cobra"
"github.com/qovery/qovery-cli/utils"
)
var applicationUpdateCmd = &cobra.Command{
Use: "update",
Short: "Update an application",
Run: func(cmd *cobra.Command, args []string) {
utils.Capture(cmd)
tokenType, token, err := utils.GetAccessToken()
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}
client := utils.GetQoveryClient(tokenType, token)
_, _, envId, err := getOrganizationProjectEnvironmentContextResourcesIds(client)
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}
applications, _, err := client.ApplicationsAPI.ListApplication(context.Background(), envId).Execute()
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}
application := utils.FindByApplicationName(applications.GetResults(), applicationName)
if application == nil {
utils.PrintlnError(fmt.Errorf("application %s not found", applicationName))
utils.PrintlnInfo("You can list all applications with: qovery application list")
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}
var storage []qovery.ServiceStorageRequestStorageInner
for _, s := range application.Storage {
storage = append(storage, qovery.ServiceStorageRequestStorageInner{
Id: &s.Id,
Type: s.Type,
Size: s.Size,
MountPoint: s.MountPoint,
})
}
req := qovery.ApplicationEditRequest{
Storage: storage,
Name: &application.Name,
Description: application.Description,
GitRepository: &qovery.ApplicationGitRepositoryRequest{
Branch: application.GitRepository.Branch,
GitTokenId: application.GitRepository.GitTokenId,
RootPath: application.GitRepository.RootPath,
Url: application.GitRepository.Url,
},
BuildMode: application.BuildMode,
DockerfilePath: application.DockerfilePath,
Cpu: application.Cpu,
Memory: application.Memory,
MinRunningInstances: application.MinRunningInstances,
MaxRunningInstances: application.MaxRunningInstances,
Healthchecks: application.Healthchecks,
AutoPreview: application.AutoPreview,
Ports: application.Ports,
Arguments: application.Arguments,
Entrypoint: application.Entrypoint,
AutoDeploy: *qovery.NewNullableBool(application.AutoDeploy),
}
if applicationBranch != "" {
req.GitRepository.Branch = &applicationBranch
}
if cmd.Flags().Changed("auto-deploy") {
req.AutoDeploy = *qovery.NewNullableBool(&applicationAutoDeploy)
}
_, _, err = client.ApplicationMainCallsAPI.EditApplication(context.Background(), application.Id).ApplicationEditRequest(req).Execute()
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}
utils.Println(fmt.Sprintf("Application %s updated!", pterm.FgBlue.Sprintf("%s", applicationName)))
},
}
func init() {
applicationCmd.AddCommand(applicationUpdateCmd)
applicationUpdateCmd.Flags().StringVarP(&organizationName, "organization", "", "", "Organization Name")
applicationUpdateCmd.Flags().StringVarP(&projectName, "project", "", "", "Project Name")
applicationUpdateCmd.Flags().StringVarP(&environmentName, "environment", "", "", "Environment Name")
applicationUpdateCmd.Flags().StringVarP(&applicationName, "application", "n", "", "Application Name")
applicationUpdateCmd.Flags().StringVarP(&applicationBranch, "branch", "", "", "Application Git Branch")
applicationUpdateCmd.Flags().BoolVarP(&applicationAutoDeploy, "auto-deploy", "", false, "Application Auto Deploy")
_ = applicationUpdateCmd.MarkFlagRequired("application")
}