Skip to content

Commit

Permalink
Rework deployment logic (#1048)
Browse files Browse the repository at this point in the history
* Rework deployment logic

This commit modifies the logic used by the `digitalocean_app` resource to check each step for a success
status rather than using the counts of steps. The step counting method fails to work with jobs of kind
`FAILED_DEPLOY` as these will always be pending, meaning that any app deployed with a job of this type
will always time out even when it is successful.

Closes #1047

Signed-off-by: David Bond <[email protected]>

* Add FAILED_DEPLOY job to acceptance tests.

* Run terrafmt on new test case.

---------

Signed-off-by: David Bond <[email protected]>
Co-authored-by: Andrew Starr-Bochicchio <[email protected]>
  • Loading branch information
davidsbond and andrewsomething authored Oct 12, 2023
1 parent b8ba602 commit 74bddda
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
9 changes: 8 additions & 1 deletion digitalocean/app/resource_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,14 @@ func waitForAppDeployment(client *godo.Client, id string, timeout time.Duration)
return fmt.Errorf("Error trying to read app deployment state: %s", err)
}

allSuccessful := deployment.Progress.SuccessSteps == deployment.Progress.TotalSteps
allSuccessful := true
for _, step := range deployment.Progress.Steps {
if step.Status != godo.DeploymentProgressStepStatus_Success {
allSuccessful = false
break
}
}

if allSuccessful {
ticker.Stop()
return nil
Expand Down
23 changes: 19 additions & 4 deletions digitalocean/app/resource_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ func TestAccDigitalOceanApp_Job(t *testing.T) {
"digitalocean_app.foobar", "spec.0.job.1.log_destination.0.datadog.0.endpoint", "https://example.com"),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.job.1.log_destination.0.datadog.0.api_key", "test-api-key"),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.job.2.name", "example-failed-job"),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.job.2.kind", "FAILED_DEPLOY"),
),
},
},
Expand Down Expand Up @@ -1189,10 +1193,6 @@ resource "digitalocean_app" "foobar" {
repo_clone_url = "https://github.com/digitalocean/sample-golang.git"
branch = "main"
}
routes {
path = "/"
}
}
job {
Expand All @@ -1217,6 +1217,21 @@ resource "digitalocean_app" "foobar" {
}
}
}
job {
name = "example-failed-job"
instance_count = 1
instance_size_slug = "basic-xxs"
kind = "FAILED_DEPLOY"
run_command = "echo 'This is a failed deploy job.'"
image {
registry_type = "DOCKER_HUB"
registry = "frolvlad"
repository = "alpine-bash"
tag = "latest"
}
}
}
}`

Expand Down

0 comments on commit 74bddda

Please sign in to comment.