Skip to content

Conversation

@glasnt
Copy link
Collaborator

@glasnt glasnt commented May 12, 2023

Implements #64

Using the image described in GoogleCloudPlatform/avocano#231, create a Cloud Run job that deploys a placeholder website. This will execute midway through the terraform processing, giving a "Your application is still deploying..." page.

Once the client deployment job runs, this placeholder is overwritten. The placeholder autofreshes through JavaScript every 5 seconds, so automatically updates when the avocano site is deployed.

This is faster than splitting the existing client/setup jobs into separate instances, as the client job depends on the cloud run API service, which depends on the database, which makes it low in the order of deployments. Deploying a placeholder without this dependency makes it higher in the order of operations, observed to be midway through the sql instance deployment, but definitely mid terraform deployment, which means it's ready before the window where Terraform is done but async metadata startup scripts haven't completed.

@glasnt glasnt requested review from a team and donmccasland as code owners May 12, 2023 04:15
echo "Running placeholder deployment"
gcloud beta run jobs execute ${google_cloud_run_v2_job.placeholder.name} --wait --project ${var.project_id} --region ${var.region}
curl -X PURGE "${local.firebase_url}/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussion: This cache purge shouldn't be necessary because we don't expect the firebase site URL to be exposed and checked before it's deploy is complete, unlike the final deploy which ends after tf apply completes. Would be great to learn if that's wrong (and if so, could we have an inline comment?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I was testing this out, I had the URL open in a window, with the "Site not configured", and I found this helped clean that out with the placeholder. It shouldn't have to happen, I just found more success keeping it in.

@glasnt
Copy link
Collaborator Author

glasnt commented May 15, 2023

It's non-obvious, but tests are failing because the "plan after apply should have non-empty diff".


Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # module.dynamic-python-webapp.google_compute_instance.placeholder_init[0] will be updated in-place
  ~ resource "google_compute_instance" "placeholder_init" {
      ~ desired_status            = "TERMINATED" -> "RUNNING"
        id                        = "projects/ci-dynamic-python-webapp-44c8/zones/us-central1-c/instances/placeholder-initialize-4ac0"
        name                      = "placeholder-initialize-4ac0"
        tags                      = []
        # (19 unchanged attributes hidden)

        # (5 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

─────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't
guarantee to take exactly these actions if you run "terraform apply" now.
    terraform.go:359: 
...
        	Error:      	Should not be: 2
        	Test:       	TestSimpleExample
        	Messages:   	plan after apply should have non-empty diff

This is because the placeholder GCE instance copied the desired_status from the "run migrations again if you run terraform" config from #46. The placeholder instance was long stopped, and should only be run once, so the desired_status can be removed.

It's presumed this instance stays running for a short time after terraform apply finishes, as it's running the jobs, so the state will still be running by the time this check is made. If this compute instance ends up synchronous, resulting in a plan diff by the time this check is run, this may need to be readdressed.

@glasnt
Copy link
Collaborator Author

glasnt commented May 15, 2023

@grayside merged the two PRs together, can I get your re-approval?

@glasnt glasnt requested a review from a team as a code owner May 16, 2023 00:35
@glasnt
Copy link
Collaborator Author

glasnt commented May 16, 2023

Merging blocked pending GoogleCloudPlatform/cloud-foundation-toolkit#1575

@glasnt glasnt merged commit 3c6704c into main May 16, 2023
@glasnt glasnt deleted the feat/placeholder branch May 16, 2023 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants