-
Notifications
You must be signed in to change notification settings - Fork 71
feat: implement fast-follow placeholder website for firebase #75
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
Changes from all commits
0205714
50b3a9d
c2d1ba0
96006b1
3a6cdc2
285cbf3
c0773c0
8f22aec
1475f9f
3981c9a
6f54893
ebcd441
af14f14
368cf29
7fc29fc
6e2a96f
347580c
398bd04
006afb8
879d1d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,5 @@ | ||
| See https://github.com/GoogleCloudPlatform/avocano | ||
| This application uses three containers images: | ||
|
|
||
| * `client`: https://github.com/GoogleCloudPlatform/avocano/tree/main/client | ||
| * `server`: https://github.com/GoogleCloudPlatform/avocano/tree/main/server | ||
| * `placeholder`: [placeholder/](placeholder/) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Copyright 2023 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
|
|
||
| # Execute with "docker run --build-arg PROJECT_ID=$PROJECT_ID ..." | ||
| ARG PROJECT_ID=YOURPROJECTID | ||
| FROM gcr.io/$PROJECT_ID/firebase | ||
|
|
||
| COPY . ./ | ||
| ENTRYPOINT ./placeholder-deploy.sh |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Placeholder | ||
|
|
||
| This folder is designed to hold a static page that can be deployed to Firebase as a placeholder until the real website is deployed. | ||
|
|
||
| Features: | ||
|
|
||
| * replaces the Firebase Hosting "Site Not Found" 404 page with a placeholder | ||
| * page set to automatically refresh every 5 seconds | ||
| * uses embedded image (like the "Site Not Found" does) to prevent image loading flickering. | ||
|
|
||
| This placeholder is built in `placeholder-image.cloudbuild.json`, automatically built and deployed using Cloud Build triggers for use in the Jump Start Solution terraform. |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "hosting": { | ||
| "public": "dist" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #!/bin/bash | ||
| # Copyright 2023 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # Script to assist in Dockerfile-based deployments. | ||
| # any errors? exit immediately. | ||
| set -e | ||
|
|
||
| echo "Deploying placeholder to Firebase..." | ||
|
|
||
| firebase deploy --project "$PROJECT_ID" --only hosting |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Copyright 2023 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # Build placeholder site code into container | ||
|
|
||
| steps: | ||
| - id: build | ||
| name: "gcr.io/cloud-builders/docker" | ||
| dir: app/placeholder | ||
| args: | ||
| [ | ||
| "build", | ||
| "--build-arg", | ||
| "PROJECT_ID=$PROJECT_ID", | ||
| "-t", | ||
| "gcr.io/$PROJECT_ID/$_IMAGE_NAME", | ||
| ".", | ||
| ] | ||
|
|
||
| images: | ||
| - gcr.io/$PROJECT_ID/$_IMAGE_NAME | ||
|
|
||
| substitutions: | ||
| _IMAGE_NAME: placeholder | ||
|
|
||
| options: | ||
| dynamic_substitutions: true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,7 +51,7 @@ resource "google_compute_instance" "gce_init" { | |
| name = var.random_suffix ? "head-start-initialize-${random_id.suffix.hex}" : "head-start-initialize" | ||
| machine_type = "n1-standard-1" | ||
| zone = var.zone | ||
| desired_status = "RUNNING" | ||
| desired_status = "RUNNING" # https://github.com/GoogleCloudPlatform/terraform-dynamic-python-webapp/pull/75#issuecomment-1547198414 | ||
|
|
||
| allow_stopping_for_update = true | ||
|
|
||
|
|
@@ -91,3 +91,49 @@ curl ${local.server_url}/api/products/?warmup | |
| shutdown -h now | ||
| EOT | ||
| } | ||
|
|
||
|
|
||
| resource "google_compute_instance" "placeholder_init" { | ||
| count = var.init ? 1 : 0 | ||
|
|
||
| depends_on = [ | ||
| google_project_service.enabled, | ||
| google_cloud_run_v2_job.placeholder, | ||
| ] | ||
|
|
||
| name = var.random_suffix ? "placeholder-initialize-${random_id.suffix.hex}" : "placeholder-initialize" | ||
| machine_type = "n1-standard-1" | ||
| zone = var.zone | ||
|
|
||
| allow_stopping_for_update = true | ||
|
|
||
| boot_disk { | ||
| initialize_params { | ||
| image = "debian-cloud/debian-11" | ||
| } | ||
| } | ||
|
|
||
| network_interface { | ||
| network = google_compute_network.gce_init[0].self_link | ||
| subnetwork = google_compute_subnetwork.gce_init[0].self_link | ||
|
|
||
| access_config { | ||
| // Ephemeral public IP | ||
| } | ||
| } | ||
|
|
||
| service_account { | ||
| email = google_service_account.compute[0].email | ||
| scopes = ["cloud-platform"] # TODO: Restrict?? | ||
| } | ||
|
|
||
| metadata_startup_script = <<EOT | ||
| #!/bin/bash | ||
|
|
||
| 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}/" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?)
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
| shutdown -h now | ||
| EOT | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.