Skip to content

Commit b324b54

Browse files
authored
Run the preloader in a container in a VM. (#392)
* [preloader] initial implementation * [preloader] run in a container * [preloader] more preloader load * [preloader] use ilb address output * [preloader] add flags to configure src and start index # Conflicts: # deployment/live/gcp/static-ct-staging/logs/arche2025h1/terragrunt.hcl * [preloader] rename module * [preloader] edit network tags # Conflicts: # deployment/modules/gcp/vm/main.tf * [preloader] use bigger VM * [preloader] more load # Conflicts: # deployment/live/gcp/static-ct-staging/logs/arche2025h1/terragrunt.hcl # Conflicts: # deployment/live/gcp/static-ct-staging/logs/arche2025h1/terragrunt.hcl * [preloader] break down preloader in its own module # Conflicts: # deployment/modules/gcp/gce/tesseract/main.tf # Conflicts: # deployment/modules/gcp/gce/tesseract/main.tf # Conflicts: # deployment/modules/gcp/gce/tesseract/main.tf # Conflicts: # deployment/live/gcp/static-ct-staging/logs/arche2025h1/terragrunt.hcl # Conflicts: # deployment/live/gcp/static-ct-staging/logs/arche2025h2/terragrunt.hcl # Conflicts: # deployment/modules/gcp/gce/tesseract/main.tf # Conflicts: # deployment/modules/gcp/gce/tesseract/variables.tf # Conflicts: # deployment/live/gcp/static-ct-staging/logs/arche2025h1/terragrunt.hcl # Conflicts: # deployment/live/gcp/static-ct-staging/logs/arche2025h2/terragrunt.hcl # Conflicts: # deployment/live/gcp/static-ct-staging/logs/arche2025h1/terragrunt.hcl # deployment/live/gcp/static-ct-staging/logs/arche2025h2/terragrunt.hcl # deployment/modules/gcp/vm/main.tf * [preloader] fix a few things * make machine type configurable * [preloader] more nits
1 parent dbc8b1e commit b324b54

2 files changed

Lines changed: 129 additions & 0 deletions

File tree

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
terraform {
2+
required_providers {
3+
google = {
4+
source = "registry.terraform.io/hashicorp/google"
5+
version = "6.12.0"
6+
}
7+
}
8+
}
9+
10+
locals {
11+
cloudrun_service_account_id = var.env == "" ? "cloudrun-sa" : "cloudrun-${var.env}-sa"
12+
}
13+
14+
module "gce_container_preloader" {
15+
# https://github.com/terraform-google-modules/terraform-google-container-vm
16+
source = "terraform-google-modules/container-vm/google"
17+
version = "~> 2.0"
18+
19+
container = {
20+
image = "us-central1-docker.pkg.dev/static-ct-staging/docker-staging/preloader@sha256:latest",
21+
args = [
22+
"--target_log_uri=${var.target_log_uri}",
23+
"--source_log_uri=${var.source_log_uri}",
24+
"--start_index=${var.start_index}",
25+
"--num_workers=500",
26+
"--parallel_fetch=20",
27+
"--parallel_submit=500",
28+
]
29+
tty : true # maybe remove this
30+
}
31+
32+
restart_policy = "Always"
33+
}
34+
35+
resource "google_compute_instance" "preloader" {
36+
name = "${var.base_name}-preloader"
37+
machine_type = var.machine_type
38+
zone = "${var.location}-f"
39+
40+
tags = ["preloader-allow-group"]
41+
42+
boot_disk {
43+
initialize_params {
44+
image = module.gce_container_preloader.source_image
45+
labels = {
46+
my_label = "value"
47+
}
48+
}
49+
}
50+
51+
network_interface {
52+
network = "default"
53+
}
54+
55+
labels = {
56+
environment = var.env
57+
container-vm = module.gce_container_preloader.vm_container_label
58+
}
59+
60+
# Come back to this: the start_index needs to be manually edited
61+
# when the prelaoder restarts.
62+
scheduling {
63+
automatic_restart = true
64+
on_host_maintenance = "MIGRATE"
65+
}
66+
allow_stopping_for_update = true
67+
68+
metadata = {
69+
gce-container-declaration = module.gce_container_preloader.metadata_value
70+
google-logging-enabled = "true"
71+
google-monitoring-enabled = "true"
72+
}
73+
74+
service_account {
75+
# Google recommends custom service accounts that have cloud-platform scope and permissions granted via IAM Roles.
76+
email = "${local.cloudrun_service_account_id}@${var.project_id}.iam.gserviceaccount.com" # TODO(phbnf): change this
77+
scopes = ["cloud-platform"] # Allows using service accounts and OAuth.
78+
}
79+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
variable "project_id" {
2+
description = "GCP project ID where the log is hosted"
3+
type = string
4+
}
5+
6+
variable "base_name" {
7+
description = "Base name to use when naming resources"
8+
type = string
9+
}
10+
11+
variable "origin_suffix" {
12+
description = "Origin suffix, appended to base_name"
13+
type = string
14+
}
15+
16+
variable "location" {
17+
description = "Location in which to create resources"
18+
type = string
19+
}
20+
21+
variable "env" {
22+
description = "Unique identifier for the env, e.g. dev or ci or prod"
23+
type = string
24+
}
25+
26+
variable "machine_type" {
27+
description = "GCP Compute Engine machine type to run the TesseraCT container on"
28+
type = string
29+
default = "n2-standard-4"
30+
}
31+
32+
variable "server_docker_image" {
33+
description = "The full image URL (path & tag) for the Docker image to deploy in Cloud Run"
34+
type = string
35+
}
36+
37+
variable "target_log_uri" {
38+
description = "URL of the destination log to preload to."
39+
type = string
40+
}
41+
42+
variable "source_log_uri" {
43+
description = "URL of the source RFC6962 log."
44+
type = string
45+
}
46+
47+
variable "start_index" {
48+
description = "Index to start preloading from on the source log."
49+
type = number
50+
}

0 commit comments

Comments
 (0)