Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: container redeploy #254

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/application_redeploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var applicationRedeployCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

msg, err := utils.RedeployService(client, envId, application.Id, utils.ApplicationType, watchFlag)
msg, err := utils.RedeployService(client, envId, application.Id, application.Name, utils.ApplicationType, watchFlag)

if err != nil {
utils.PrintlnError(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/application_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var applicationUpdateCmd = &cobra.Command{
Name: &application.Name,
Description: application.Description.Get(),
GitRepository: &qovery.ApplicationGitRepositoryRequest{
Url: *application.GitRepository.Url,
Url: application.GitRepository.Url,
Branch: application.GitRepository.Branch,
RootPath: application.GitRepository.RootPath,
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/container_redeploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var containerRedeployCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

msg, err := utils.RedeployService(client, envId, container.Id, utils.ContainerType, watchFlag)
msg, err := utils.RedeployService(client, envId, container.Id, container.Name, utils.ContainerType, watchFlag)

if err != nil {
utils.PrintlnError(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/cronjob_redeploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var cronjobRedeployCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

msg, err := utils.RedeployService(client, envId, cronjob.CronJobResponse.Id, utils.JobType, watchFlag)
msg, err := utils.RedeployService(client, envId, cronjob.CronJobResponse.Id, cronjob.CronJobResponse.Name, utils.JobType, watchFlag)

if err != nil {
utils.PrintlnError(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/database_redeploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var databaseRedeployCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

msg, err := utils.RedeployService(client, envId, database.Id, utils.DatabaseType, watchFlag)
msg, err := utils.RedeployService(client, envId, database.Id, database.Name, utils.DatabaseType, watchFlag)

if err != nil {
utils.PrintlnError(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/helm_redeploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var helmRedeployCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

msg, err := utils.RedeployService(client, envId, helm.Id, utils.HelmType, watchFlag)
msg, err := utils.RedeployService(client, envId, helm.Id, helm.Name, utils.HelmType, watchFlag)

if err != nil {
utils.PrintlnError(err)
Expand Down
12 changes: 2 additions & 10 deletions cmd/helm_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,10 @@ func GetHelmSource(helm *qovery.HelmResponse, chartName string, chartVersion str
updatedBranch = &charGitCommitBranch
}

if gitRepository.Url == nil {
return nil, fmt.Errorf("Invalid Helm git repository source")
}

return &qovery.HelmRequestAllOfSource{
HelmRequestAllOfSourceOneOf: &qovery.HelmRequestAllOfSourceOneOf{
GitRepository: &qovery.HelmGitRepositoryRequest{
Url: *gitRepository.Url,
Url: gitRepository.Url,
Branch: updatedBranch,
RootPath: gitRepository.RootPath,
GitTokenId: gitRepository.GitTokenId,
Expand Down Expand Up @@ -175,15 +171,11 @@ func GetHelmValuesOverride(helm *qovery.HelmResponse, valuesOverrideCommitBranch
updatedBranch = &valuesOverrideCommitBranch
}

if git.GitRepository.Url == nil {
return nil, fmt.Errorf("Invalid Helm git repository source")
}

updatedFile := qovery.HelmRequestAllOfValuesOverrideFile{}
updatedFile.SetGit(qovery.HelmRequestAllOfValuesOverrideFileGit{
Paths: git.Paths,
GitRepository: qovery.ApplicationGitRepositoryRequest{
Url: *git.GitRepository.Url,
Url: git.GitRepository.Url,
Branch: updatedBranch,
GitTokenId: git.GitRepository.GitTokenId,
RootPath: git.GitRepository.RootPath,
Expand Down
2 changes: 1 addition & 1 deletion cmd/lifecycle_redeploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var lifecycleRedeployCmd = &cobra.Command{
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

msg, err := utils.RedeployService(client, envId, lifecycle.LifecycleJobResponse.Id, utils.JobType, watchFlag)
msg, err := utils.RedeployService(client, envId, lifecycle.LifecycleJobResponse.Id, lifecycle.LifecycleJobResponse.Name, utils.JobType, watchFlag)

if err != nil {
utils.PrintlnError(err)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/posthog/posthog-go v0.0.0-20221221115252-24dfed35d71a
github.com/pterm/pterm v0.12.55
github.com/qovery/qovery-client-go v0.0.0-20240117104703-29bf4ea6d3b0
github.com/qovery/qovery-client-go v0.0.0-20240201142745-3115f6b80050
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ github.com/qovery/qovery-client-go v0.0.0-20240108095100-718858da5460 h1:NTLkMvI
github.com/qovery/qovery-client-go v0.0.0-20240108095100-718858da5460/go.mod h1:5QD7sC1Z6XCCYd31c4XKVwGdEOjvtgG0NDcaVDoWb+o=
github.com/qovery/qovery-client-go v0.0.0-20240117104703-29bf4ea6d3b0 h1:RwDgJbYuAxjq7GJ2kxvf4ORq9g0l/ZWv5xHjMlOzNmU=
github.com/qovery/qovery-client-go v0.0.0-20240117104703-29bf4ea6d3b0/go.mod h1:5QD7sC1Z6XCCYd31c4XKVwGdEOjvtgG0NDcaVDoWb+o=
github.com/qovery/qovery-client-go v0.0.0-20240201142745-3115f6b80050 h1:BnUMqurlKYBHZgHexSmIxR+OiAtZ3RzAqpg0Ylueflw=
github.com/qovery/qovery-client-go v0.0.0-20240201142745-3115f6b80050/go.mod h1:5QD7sC1Z6XCCYd31c4XKVwGdEOjvtgG0NDcaVDoWb+o=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
Expand Down
2 changes: 1 addition & 1 deletion pkg/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func GetCurrentVersion() string {
return "0.82.1" // ci-version-check
return "0.82.2" // ci-version-check
}

func GetLatestOnlineVersionUrl() (string, error) {
Expand Down
37 changes: 30 additions & 7 deletions utils/qovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -2116,7 +2116,7 @@ func DeployService(client *qovery.APIClient, envId string, serviceId string, ser
return DeployService(client, envId, serviceId, serviceType, request, watchFlag)
}

func RedeployService(client *qovery.APIClient, envId string, serviceId string, serviceType ServiceType, watchFlag bool) (string, error) {
func RedeployService(client *qovery.APIClient, envId string, serviceId string, serviceName string, serviceType ServiceType, watchFlag bool) (string, error) {
statuses, _, err := client.EnvironmentMainCallsAPI.GetEnvironmentStatuses(context.Background(), envId).Execute()

if err != nil {
Expand All @@ -2128,7 +2128,24 @@ func RedeployService(client *qovery.APIClient, envId string, serviceId string, s
case ApplicationType:
for _, application := range statuses.GetApplications() {
if application.Id == serviceId && IsTerminalState(application.State) {
_, _, err := client.ApplicationActionsAPI.DeployApplication(context.Background(), serviceId).Execute()
apps, _, error := client.ApplicationsAPI.ListApplication(context.Background(), envId).Execute()
if error != nil {
PrintlnError(err)
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

app := FindByApplicationName(apps.GetResults(), serviceName);
if app == nil {
PrintlnError(fmt.Errorf("application %s not found", serviceName))
PrintlnInfo("You can list all applications with: qovery application list")
os.Exit(1)
panic("unreachable") // staticcheck false positive: https://staticcheck.io/docs/checks#SA5011
}

deployRequest := qovery.DeployRequest{ GitCommitId: *app.GitRepository.DeployedCommitId}

_, _, err := client.ApplicationActionsAPI.DeployApplication(context.Background(), serviceId).DeployRequest(deployRequest).Execute()
if err != nil {
return "", err
}
Expand Down Expand Up @@ -2158,7 +2175,9 @@ func RedeployService(client *qovery.APIClient, envId string, serviceId string, s
case ContainerType:
for _, container := range statuses.GetContainers() {
if container.Id == serviceId && IsTerminalState(container.State) {
_, _, err := client.ContainerActionsAPI.DeployContainer(context.Background(), serviceId).Execute()
containerDeployRequest := qovery.ContainerDeployRequest{}

_, _, err := client.ContainerActionsAPI.DeployContainer(context.Background(), serviceId).ContainerDeployRequest(containerDeployRequest) .Execute()
if err != nil {
return "", err
}
Expand All @@ -2173,7 +2192,9 @@ func RedeployService(client *qovery.APIClient, envId string, serviceId string, s
case JobType:
for _, job := range statuses.GetJobs() {
if job.Id == serviceId && IsTerminalState(job.State) {
_, _, err := client.JobActionsAPI.DeployJob(context.Background(), serviceId).Execute()
deployRequest := qovery.JobDeployRequest{}

_, _, err := client.JobActionsAPI.DeployJob(context.Background(), serviceId).JobDeployRequest(deployRequest).Execute()
if err != nil {
return "", err
}
Expand All @@ -2188,7 +2209,9 @@ func RedeployService(client *qovery.APIClient, envId string, serviceId string, s
case HelmType:
for _, helm := range statuses.GetHelms() {
if helm.Id == serviceId && IsTerminalState(helm.State) {
_, _, err := client.HelmActionsAPI.DeployHelm(context.Background(), serviceId).Execute()
deployRequest := qovery.HelmDeployRequest{}

_, _, err := client.HelmActionsAPI.DeployHelm(context.Background(), serviceId).HelmDeployRequest(deployRequest).Execute()
if err != nil {
return "", err
}
Expand All @@ -2208,7 +2231,7 @@ func RedeployService(client *qovery.APIClient, envId string, serviceId string, s
// sleep here to avoid too many requests
time.Sleep(5 * time.Second)

return RedeployService(client, envId, serviceId, serviceType, watchFlag)
return RedeployService(client, envId, serviceId, serviceName, serviceType, watchFlag)
}

func StopService(client *qovery.APIClient, envId string, serviceIds string, serviceType ServiceType, watchFlag bool) (string, error) {
Expand Down Expand Up @@ -2445,7 +2468,7 @@ func ToJobRequest(job qovery.JobResponse) qovery.JobRequest {

if docker != nil {
sourceDockerGitRepository := qovery.ApplicationGitRepositoryRequest{
Url: *docker.GitRepository.Url,
Url: docker.GitRepository.Url,
Branch: docker.GitRepository.Branch,
RootPath: docker.GitRepository.RootPath,
}
Expand Down
Loading