Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
bb77787
feat: support multiple firebase sites
glasnt Apr 27, 2023
8ccc7a2
fix: add suffix directly on the job, rather than parsing later
glasnt Apr 27, 2023
b260df6
fix: ensure api dependence
glasnt Apr 27, 2023
20d9ad9
bump avocano
glasnt Apr 28, 2023
c9cacd6
fix: update firebase_url based on resource attribute
glasnt Apr 28, 2023
53e1771
fix: syntax
glasnt Apr 28, 2023
a85b685
docs: update
glasnt Apr 28, 2023
71f7e10
Merge branch 'main' into feat/multi-firebase
glasnt Apr 28, 2023
7a85338
Merge branch 'feat/multi-firebase' of github.com:GoogleCloudPlatform/…
glasnt Apr 28, 2023
cd58077
(noop for re-run tests)
glasnt May 1, 2023
85c617c
Merge branch 'main' into feat/multi-firebase
glasnt May 2, 2023
3c7bf00
reintro firebasehosting api
glasnt May 2, 2023
8ee5e7d
Merge branch 'feat/multi-firebase' of github.com:GoogleCloudPlatform/…
glasnt May 2, 2023
e7cc4c7
Merge branch 'main' into feat/multi-firebase
glasnt May 4, 2023
0c99f61
Merge branch 'main' into feat/multi-firebase
glasnt May 11, 2023
bfc5941
fix: explicitly encode project/region for google-beta provider
glasnt May 11, 2023
0c5fc0b
make firebase site depend on project
glasnt May 15, 2023
ef39b75
Merge branch 'main' into feat/multi-firebase
glasnt May 16, 2023
0327d88
Merge branch 'main' into feat/multi-firebase
glasnt May 16, 2023
6885933
add suffix logic to placeholder
glasnt May 16, 2023
9bcf68e
debugging
glasnt May 16, 2023
0430c1f
fix trailing fi
glasnt May 16, 2023
870797c
Include json package for config alteration
glasnt May 16, 2023
40f9d52
Merge branch 'main' into feat/multi-firebase
glasnt May 16, 2023
ae80693
Add new test: suffix (merge #59)
glasnt May 16, 2023
1b386cf
Merge branch 'feat/multi-firebase' of github.com:GoogleCloudPlatform/…
glasnt May 16, 2023
285ec74
tf fmt
glasnt May 16, 2023
16576f1
whitespace
glasnt May 16, 2023
b9074a6
DEBUG: try optional sites to mitigate Error 409
glasnt May 17, 2023
2ab0855
fix: conditional site calls for conditional outputs
glasnt May 17, 2023
74481ed
count index for firebase url
glasnt May 17, 2023
b7a857e
rename packages, name files correctly
glasnt May 17, 2023
cd16d5b
Merge branch 'main' into feat/multi-firebase
grayside May 24, 2023
fb6ea65
Merge branch 'main' into feat/multi-firebase
grayside May 24, 2023
0ab98cf
re-order js deps
glasnt May 31, 2023
9ec351b
Use envsubst and template file over raw json
glasnt May 31, 2023
168394f
Add additional inline documenation on envvar usage
glasnt May 31, 2023
ae2350f
attempt: parallel builds
glasnt May 31, 2023
3971a70
Merge branch 'main' into feat/multi-firebase
glasnt May 31, 2023
64e275b
fix: lint
glasnt May 31, 2023
85c019b
update tests to not expect to be run in isolation
glasnt May 31, 2023
49536e2
lint, missing outputs
glasnt May 31, 2023
111ab4b
make generate_docs
glasnt May 31, 2023
05dddb0
fix: use exact matching on service listing
glasnt May 31, 2023
7ba0c29
testing: de-duplicate code
grayside Jun 1, 2023
caa192e
Merge branch 'main' into feat/multi-firebase
glasnt Jun 1, 2023
262e318
Merge branch 'main' into feat/multi-firebase
glasnt Jun 2, 2023
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
1 change: 1 addition & 0 deletions app/placeholder/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ ARG PROJECT_ID=YOURPROJECTID
FROM gcr.io/$PROJECT_ID/firebase

COPY . ./

ENTRYPOINT ./placeholder-deploy.sh
13 changes: 13 additions & 0 deletions app/placeholder/firebaserc.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"projects": {},
"targets": {
"$PROJECT_ID": {
"hosting": {
"$SUFFIX": [
"${PROJECT_ID}-${SUFFIX}"
]
}
}
},
"etags": {}
}
18 changes: 18 additions & 0 deletions app/placeholder/placeholder-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@
# any errors? exit immediately.
set -e

# if deploying with a suffix (from infra/jobs.tf), adjust the config to suit the custom site
# https://firebase.google.com/docs/hosting/multisites#set_up_deploy_targets
if [[ -n $SUFFIX ]]; then
json -I -f firebase.json -e "this.hosting.target='$SUFFIX'"
UPDATED=true

# Use template file to generate configuration
envsubst < firebaserc.tmpl > .firebaserc
echo "Customised .firebaserc created to support site."
cat .firebaserc
fi

# If anything was updated, then export the output.
if [[ -n $UPDATED ]]; then
echo "Deploying with the following updated config: "
cat firebase.json
fi

echo "Deploying placeholder to Firebase..."

firebase deploy --project "$PROJECT_ID" --only hosting
33 changes: 33 additions & 0 deletions build/int.cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,55 @@ steps:
- 'TF_VAR_org_id=$_ORG_ID'
- 'TF_VAR_folder_id=$_FOLDER_ID'
- 'TF_VAR_billing_account=$_BILLING_ACCOUNT'

# Initialize all tests, then run two parallel sets of tests.
- id: init-all
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run all --stage init --verbose']
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Since both sections below have an init step, what is this init-all doing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure, this was copied from https://github.com/GoogleCloudPlatform/terraform-google-secure-cicd/blob/main/build/int.cloudbuild.yaml#L31 as a presumed 'best practice' (note: only example I could find)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm chatting with tf blueprint maintainers around best practices here, tbd


# Simple example - one deployment per project
- id: simple-example-init
waitFor: ['init-all']
dir: infra
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestSimpleExample --stage init --verbose']
- id: simple-example-apply
waitFor: ['simple-example-init']
dir: infra
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestSimpleExample --stage apply --verbose']
- id: simple-example-verify
waitFor: ['simple-example-apply']
dir: infra
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestSimpleExample --stage verify --verbose']
- id: simple-example-teardown
waitFor: ['simple-example-verify']
dir: infra
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestSimpleExample --stage teardown --verbose']

# Suffix example - supports multiple deployments per project
- id: suffix-example-init
waitFor: ['init-all']
dir: infra
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestSuffixExample --stage init --verbose']
- id: suffix-example-apply
waitFor: ['suffix-example-init']
dir: infra
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestSuffixExample --stage apply --verbose']
- id: suffix-example-verify
waitFor: ['suffix-example-apply']
dir: infra
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestSuffixExample --stage verify --verbose']
- id: suffix-example-teardown
waitFor: ['suffix-example-verify']
dir: infra
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
args: ['/bin/bash', '-c', 'cft test run TestSuffixExample --stage teardown --verbose']
tags:
- 'ci'
- 'integration'
Expand Down
2 changes: 2 additions & 0 deletions infra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ Functional examples are included in the

| Name | Description |
|------|-------------|
| client\_job\_name | Name of the Cloud Run Job, deploying the front end |
| django\_admin\_password | Djando Admin password |
| django\_admin\_url | Djando Admin URL |
| firebase\_url | Firebase URL |
| neos\_toc\_url | Neos Tutorial URL |
| server\_service\_name | Name of the Cloud Run service, hosting the server API |
| usage | Next steps for usage |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Expand Down
1 change: 1 addition & 0 deletions infra/apis.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ locals {
"secretmanager.googleapis.com",
"cloudresourcemanager.googleapis.com",
"firebase.googleapis.com",
"firebasehosting.googleapis.com",
]
}

Expand Down
2 changes: 2 additions & 0 deletions infra/examples/simple_example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ This example illustrates how to use the `dynamic-python-webapp` module.

| Name | Description |
|------|-------------|
| client\_job\_name | Client Cloud Run job name |
| firebase\_url | Firebase URL |
| server\_service\_name | Server Cloud Run service name |
| usage | Connection details for the project |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Expand Down
6 changes: 3 additions & 3 deletions infra/examples/simple_example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

module "dynamic-python-webapp" {
source = "../.."

project_id = var.project_id
source = "../.."
project_id = var.project_id
random_suffix = false
}
10 changes: 10 additions & 0 deletions infra/examples/simple_example/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,13 @@ output "firebase_url" {
description = "Firebase URL"
value = module.dynamic-python-webapp.firebase_url
}

output "server_service_name" {
description = "Server Cloud Run service name"
value = module.dynamic-python-webapp.server_service_name
}

output "client_job_name" {
description = "Client Cloud Run job name"
value = module.dynamic-python-webapp.client_job_name
}
29 changes: 29 additions & 0 deletions infra/examples/suffix_example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Simple Example

This example illustrates how to use the `dynamic-python-webapp` module.

This example uses a randomly generated suffix when naming resources to support multiple deployments per project.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| project\_id | The ID of the project in which to provision resources. | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| client\_job\_name | Client Cloud Run job name |
| firebase\_url | Firebase URL |
| server\_service\_name | Server Cloud Run service name |
| usage | Connection details for the project |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

To provision this example, run the following from within this directory:
- `terraform init` to get the plugins
- `terraform plan` to see the infrastructure plan
- `terraform apply` to apply the infrastructure build
- `terraform destroy` to destroy the built infrastructure
21 changes: 21 additions & 0 deletions infra/examples/suffix_example/main.tf
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.
*/

module "dynamic-python-webapp" {
source = "../.."

project_id = var.project_id
}
37 changes: 37 additions & 0 deletions infra/examples/suffix_example/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* 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.
*/

output "usage" {
sensitive = true
description = "Connection details for the project"
value = module.dynamic-python-webapp.usage
}

output "firebase_url" {
description = "Firebase URL"
value = module.dynamic-python-webapp.firebase_url
}

output "server_service_name" {
description = "Server Cloud Run service name"
value = module.dynamic-python-webapp.server_service_name
}

output "client_job_name" {
description = "Client Cloud Run job name"
value = module.dynamic-python-webapp.client_job_name
}

20 changes: 20 additions & 0 deletions infra/examples/suffix_example/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* 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.
*/

variable "project_id" {
description = "The ID of the project in which to provision resources."
type = string
}
25 changes: 25 additions & 0 deletions infra/examples/suffix_example/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* 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.
*/

terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "~> 4.0"
}
}
required_version = ">= 0.13"
}
12 changes: 12 additions & 0 deletions infra/firebase.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,15 @@ resource "google_firebase_project" "default" {

depends_on = [google_project_service.enabled]
}

resource "google_firebase_hosting_site" "client" {

# By default, a firebase site will be named "project_id". Only create a custom site if using suffixes
count = var.random_suffix ? 1 : 0

provider = google-beta
project = google_firebase_project.default.project
site_id = "${var.project_id}-${random_id.suffix.hex}"

depends_on = [google_project_service.enabled]
}
11 changes: 11 additions & 0 deletions infra/jobs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ resource "google_cloud_run_v2_job" "client" {
service_account = google_service_account.client.email
containers {
image = local.client_image

# Variables used to customise Firebase configuration on deployment
# https://github.com/GoogleCloudPlatform/avocano/blob/main/client/docker-deploy.sh
env {
Copy link
Contributor

Choose a reason for hiding this comment

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

discussion: At first I found this variable's presence on the Cloud Run Jobs mysterious, and wondered if we should have inline comments linking to usage. But I'm not sure we want to try maintaining a list like that to be comprehensive. This is one of those pieces that hand-off to future maintainers might lose track how to handle changes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've added links to the script usage, which might help, but happy to do more

name = "SUFFIX"
value = var.random_suffix ? random_id.suffix.hex : ""
}
env {
name = "SERVICE_NAME"
value = google_cloud_run_v2_service.server.name
Expand Down Expand Up @@ -154,6 +161,10 @@ resource "google_cloud_run_v2_job" "placeholder" {
value = var.project_id
}

env {
name = "SUFFIX"
value = var.random_suffix ? random_id.suffix.hex : ""
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ provider "google" {
project = var.project_id
region = var.region
}

provider "google-beta" {
project = var.project_id
region = var.region
}
6 changes: 6 additions & 0 deletions infra/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ spec:
examples:
- name: simple_example
location: examples/simple_example
- name: suffix_example
location: examples/suffix_example
interfaces:
variables:
- name: client_image_host
Expand Down Expand Up @@ -100,6 +102,8 @@ spec:
varType: string
defaultValue: us-central1-c
outputs:
- name: client_job_name
description: Name of the Cloud Run Job, deploying the front end
- name: django_admin_password
description: Djando Admin password
- name: django_admin_url
Expand All @@ -108,6 +112,8 @@ spec:
description: Firebase URL
- name: neos_toc_url
description: Neos Tutorial URL
- name: server_service_name
description: Name of the Cloud Run service, hosting the server API
- name: usage
description: Next steps for usage
requirements:
Expand Down
12 changes: 11 additions & 1 deletion infra/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

locals {
server_url = google_cloud_run_v2_service.server.uri
firebase_url = "https://${var.project_id}.web.app"
firebase_url = var.random_suffix ? google_firebase_hosting_site.client[0].default_url : "https://${var.project_id}.web.app"
}

output "firebase_url" {
Expand Down Expand Up @@ -63,3 +63,13 @@ output "usage" {
Password: ${google_secret_manager_secret_version.django_admin_password.secret_data}
EOF
}

output "server_service_name" {
description = "Name of the Cloud Run service, hosting the server API"
value = google_cloud_run_v2_service.server.name
}

output "client_job_name" {
description = "Name of the Cloud Run Job, deploying the front end"
value = google_cloud_run_v2_job.client.name
}
Loading