-
Notifications
You must be signed in to change notification settings - Fork 6
Add Cloud Run for GCP CI env #56
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
dd820ea
Add Cloud Run for GCP CI env
roger2hk b0c1482
Add .terraform.lock.hcl
roger2hk 63a1e04
Build conformance Docker image on top of base image
roger2hk 2f94e5a
Fix circular dependency on stage in Dockerfile
roger2hk 1c14efc
Add `roles/monitoring.metricWriter` to Cloud Run service account
roger2hk 03e72e4
Add missing configure-docker command
roger2hk 6f418a0
Remove leading slash in path
roger2hk ca6b06d
Replace us-central1 with ${GOOGLE_REGION}
roger2hk bf81aa5
Add `unset TESSERA_BASE_NAME`
roger2hk d01ed41
Update to `GCP SCTFE Test Environment` in README
roger2hk 0382d70
Add `env` to GCS bucket labels
roger2hk 5a26d23
Update the Cloud Run resources limit to align with the measurement unit
roger2hk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM sctfe-gcp:latest AS base | ||
|
||
# Build release image | ||
FROM alpine:3.20.2@sha256:0a4eaa0eecf5f8c050e5bba433f58c052be7587ee8af3e8b3910ef9ab5fbe9f5 | ||
|
||
# Copy the fake CA certificate into the container | ||
COPY ./testdata/fake-ca.cert /bin/ | ||
|
||
# Copy the sctfe-gcp binary | ||
COPY --from=base /bin/sctfe-gcp /bin/ | ||
|
||
ENTRYPOINT ["/bin/sctfe-gcp"] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# GCP SCTFE CI Environment | ||
|
||
## Overview | ||
|
||
This config uses the [gcp/conformance](/deployment/modules/gcp/conformance) module to | ||
define a CI environment to run the SCTFE, backed by Trillian Tessera. | ||
|
||
At a high level, this environment consists of: | ||
- One Spanner instance with two databases: | ||
- one for Tessera | ||
- one for deduplication | ||
- A GCS Bucket | ||
- Secret Manager | ||
- Cloud Run | ||
|
||
### Manual Deployment | ||
|
||
First authenticate via `gcloud` as a principle with sufficient ACLs for | ||
the project: | ||
|
||
```sh | ||
gcloud auth application-default login | ||
``` | ||
|
||
Set the required environment variables: | ||
|
||
```sh | ||
export GOOGLE_PROJECT={VALUE} | ||
export GOOGLE_REGION={VALUE} # e.g: us-central1 | ||
``` | ||
|
||
TODO: Add the Artifact Registry which is in the Cloud Build pull request. The expected repository is `us-central1-docker.pkg.dev/${GOOGLE_PROJECT}/docker-ci`. | ||
|
||
Build and push the Docker image to Artifact Registry repository: | ||
|
||
```sh | ||
docker build -f ./cmd/gcp/Dockerfile -t sctfe-gcp:latest . | ||
docker build -f ./cmd/gcp/ci/Dockerfile -t conformance-gcp:latest . | ||
docker tag conformance-gcp:latest us-central1-docker.pkg.dev/${GOOGLE_PROJECT}/docker-ci/conformance-gcp:latest | ||
roger2hk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
docker push us-central1-docker.pkg.dev/${GOOGLE_PROJECT}/docker-ci/conformance-gcp | ||
roger2hk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
Terraforming the project can be done by: | ||
1. `cd` to the relevant directory (/deployment/live/gcp/ci/) for the environment to deploy/change. | ||
roger2hk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
2. Run `terragrunt apply`. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
terraform { | ||
source = "${get_repo_root()}/deployment/modules/gcp//conformance" | ||
} | ||
|
||
locals { | ||
env = "ci" | ||
base_name = "${local.env}-conformance" | ||
server_docker_image = "us-central1-docker.pkg.dev/${include.root.locals.project_id}/docker-${local.env}/conformance-gcp:latest" | ||
} | ||
|
||
include "root" { | ||
path = find_in_parent_folders() | ||
expose = true | ||
} | ||
|
||
inputs = merge( | ||
local, | ||
include.root.locals, | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
locals { | ||
env = path_relative_to_include() | ||
project_id = get_env("GOOGLE_PROJECT", "phboneff-dev") | ||
location = get_env("GOOGLE_REGION", "us-central1") | ||
base_name = get_env("TESSERA_BASE_NAME", "${local.env}-static-ct") | ||
} | ||
|
||
remote_state { | ||
backend = "gcs" | ||
|
||
config = { | ||
project = local.project_id | ||
location = local.location | ||
bucket = "${local.project_id}-${local.base_name}-terraform-state" | ||
prefix = "terraform.tfstate" | ||
|
||
gcs_bucket_labels = { | ||
name = "terraform_state_conformance" | ||
roger2hk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,18 @@ | ||
terraform { | ||
source = "${get_repo_root()}/deployment/modules/gcp//conformance" | ||
source = "${get_repo_root()}/deployment/modules/gcp//test" | ||
} | ||
|
||
locals { | ||
project_id = get_env("GOOGLE_PROJECT", "phboneff-dev") | ||
location = get_env("GOOGLE_REGION", "us-central1") | ||
base_name = get_env("TESSERA_BASE_NAME", "tessera-staticct") | ||
env = "test" | ||
base_name = get_env("TESSERA_BASE_NAME", "${local.env}-static-ct") | ||
} | ||
|
||
inputs = local | ||
|
||
remote_state { | ||
backend = "gcs" | ||
|
||
config = { | ||
project = local.project_id | ||
location = local.location | ||
bucket = "${local.project_id}-${local.base_name}-terraform-state" | ||
prefix = "terraform.tfstate" | ||
|
||
gcs_bucket_labels = { | ||
name = "terraform_state_conformance" | ||
} | ||
} | ||
include "root" { | ||
path = find_in_parent_folders() | ||
expose = true | ||
} | ||
|
||
inputs = merge( | ||
local, | ||
include.root.locals, | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
terraform { | ||
required_providers { | ||
google = { | ||
source = "registry.terraform.io/hashicorp/google" | ||
version = "6.1.0" | ||
} | ||
} | ||
} | ||
|
||
# Cloud Run | ||
|
||
resource "google_project_service" "cloudrun_api" { | ||
service = "run.googleapis.com" | ||
disable_on_destroy = false | ||
} | ||
|
||
resource "google_service_account" "cloudrun_service_account" { | ||
account_id = "cloudrun-${var.env}-sa" | ||
display_name = "Service Account for Cloud Run (${var.env})" | ||
} | ||
|
||
resource "google_project_iam_member" "monitoring_metric_writer" { | ||
project = var.project_id | ||
role = "roles/monitoring.metricWriter" | ||
member = "serviceAccount:${google_service_account.cloudrun_service_account.email}" | ||
} | ||
|
||
resource "google_storage_bucket_iam_member" "member" { | ||
bucket = var.bucket | ||
role = "roles/storage.objectUser" | ||
member = "serviceAccount:${google_service_account.cloudrun_service_account.email}" | ||
} | ||
|
||
resource "google_project_iam_member" "iam_secret_accessor" { | ||
project = var.project_id | ||
role = "roles/secretmanager.secretAccessor" | ||
member = "serviceAccount:${google_service_account.cloudrun_service_account.email}" | ||
} | ||
|
||
resource "google_spanner_database_iam_member" "iam_log_spanner_database_user" { | ||
instance = var.log_spanner_instance | ||
database = var.log_spanner_db | ||
role = "roles/spanner.databaseUser" | ||
member = "serviceAccount:${google_service_account.cloudrun_service_account.email}" | ||
} | ||
|
||
resource "google_spanner_database_iam_member" "iam_dedup_spanner_database_user" { | ||
instance = var.log_spanner_instance | ||
database = var.dedup_spanner_db | ||
role = "roles/spanner.databaseUser" | ||
member = "serviceAccount:${google_service_account.cloudrun_service_account.email}" | ||
} | ||
|
||
locals { | ||
spanner_log_db_path = "projects/${var.project_id}/instances/${var.log_spanner_instance}/databases/${var.log_spanner_db}" | ||
spanner_dedup_db_path = "projects/${var.project_id}/instances/${var.log_spanner_instance}/databases/${var.dedup_spanner_db}" | ||
} | ||
|
||
resource "google_cloud_run_v2_service" "default" { | ||
roger2hk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
name = var.base_name | ||
location = var.location | ||
launch_stage = "GA" | ||
|
||
template { | ||
service_account = google_service_account.cloudrun_service_account.account_id | ||
max_instance_request_concurrency = 700 | ||
timeout = "5s" | ||
|
||
scaling { | ||
max_instance_count = 3 | ||
} | ||
|
||
containers { | ||
image = var.server_docker_image | ||
name = "conformance" | ||
args = [ | ||
"--logtostderr", | ||
"--v=1", | ||
"--http_endpoint=:6962", | ||
"--project_id=${var.project_id}", | ||
"--bucket=${var.bucket}", | ||
"--spanner_db_path=${local.spanner_log_db_path}", | ||
"--spanner_dedup_db_path=${local.spanner_dedup_db_path}", | ||
"--roots_pem_file=/bin/fake-ca.cert", | ||
"--origin=${var.base_name}", | ||
"--signer_public_key_secret_name=${var.signer_public_key_secret_name}", | ||
"--signer_private_key_secret_name=${var.signer_private_key_secret_name}", | ||
] | ||
ports { | ||
container_port = 6962 | ||
} | ||
|
||
resources { | ||
limits = { | ||
cpu = "2" | ||
memory = "1024Mi" | ||
} | ||
} | ||
|
||
startup_probe { | ||
initial_delay_seconds = 1 | ||
timeout_seconds = 1 | ||
period_seconds = 10 | ||
failure_threshold = 6 | ||
tcp_socket { | ||
port = 6962 | ||
} | ||
} | ||
} | ||
} | ||
|
||
deletion_protection = false | ||
|
||
client = "terraform" | ||
|
||
depends_on = [ | ||
google_project_service.cloudrun_api, | ||
] | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.