blob: 53833e7b805ea190bf8df7b0fc735ca635f3c31a [file] [log] [blame]
"""This module defines the gold_launcher macro."""
load("//golden/pages:all_gold_pages.bzl", "ALL_GOLD_PAGES")
# Curly braces are escaped ("{" becomes "{{", "}" becomes "}}") because we will format this
# template with
if [[ -z "$$1" ]]; then
echo "Usage: bazel run {bazel_target_name} -- /path/to/client_secret.json"
exit 1
# Compute the path to the directory with web assets by extracting the parent directory of an
# arbitrary page. This works because all web assets are generated on the same directory (with the
# exception of the favicon, which we will handle later).
byblame_page_assets=($(rootpaths //golden/pages:byblame_dev)) # Expands to byblame.(html,js,css).
web_assets_dir=$$(realpath $$(dirname $${{byblame_page_assets[0]}}))
# Copy the favicon into the web assets directory.
cp $(rootpath //golden/static:favicon.ico) $$web_assets_dir
# Based on //golden/k8s-instances/skia-infra/skia-infra-frontend.json5.
cat > config.json5 <<EOF
authorized_users: [""],
client_secret_file: "$$1",
frontend: {{
baseRepoURL: "<inherited from git_repo_url>",
defaultCorpus: "{default_corpus}",
title: "{title}",
materialized_view_corpora: {materialized_view_corpora},
negatives_max_age: "4320h", // 180 days
positives_max_age: "720h", // 30 days
prom_port: ":20000",
ready_port: ":8000",
resources_path: "$$web_assets_dir",
# Print contents of file for debugging purposes.
echo "CONTENTS OF FILE $$(pwd)/config.json5:"
cat config.json5
# Based on //golden/k8s-instances/skia-infra/skia-infra.json5.
cat > common_instance_config.json5 <<EOF
local: true,
code_review_systems: [
id: "gerrit",
flavor: "gerrit",
gerrit_url: "",
url_template: ""
gcs_bucket: "{gcs_bucket}",
git_repo_branch: "main",
git_repo_url: "{git_repo_url}",
pubsub_project_id: "skia-public",
site_url: "{site_url}",
sql_connection: "root@localhost:26235",
sql_database: "{sql_database}",
known_hashes_gcs_path: "{known_hashes_gcs_path}",
window_size: {window_size},
# Print contents of file for debugging purposes.
echo "CONTENTS OF FILE $$(pwd)/common_instance_config.json5:"
cat common_instance_config.json5
# Print out all commands from now on for debugging purposes.
set -ex
# Switch to te skia-public GCP project.
gcloud container clusters get-credentials skia-public --zone us-central1-a --project skia-public
gcloud config set project skia-public
# Port-forward the production CockroachDB instance to port 26235. The default CockroachDB port is
# 26234, so this prevents the forwarded port from clashing with a local running CockroachDB.
# This command will be killed on Ctrl+C.
kubectl port-forward gold-cockroachdb-0 26235:26234 &
sleep 5
# Ignore any local running emulators.
# Launch the gold_frontend binary.
$(rootpath //golden/cmd/gold_frontend:gold_frontend) \
--config=config.json5 \
def gold_launcher(
materialized_view_corpora = None):
"""Launches a local gold_frontend instance that talks to a production database.
This rule is meant for local development and debugging. It reuses the credentials given to the
kubectl command, which means it might have write access to the production database, so please
use with caution.
name: Name of the rule.
default_corpus: Default corpus, e.g. "gm".
title: Title shown in the Gold UI, e.g. "Skia Gold".
gcs_bucket: GCS bucket where digests are found, e.g. "skia-infra-gm".
git_repo_url: Git repository URL, e.g. "".
site_url: URL of the Gold instance, e.g. "".
sql_database: Name of the production CockroachDB database, e.g. "skia".
known_hashes_gcs_path: Path to the known hashes GCS file, e.g.
window_size: Window size, e.g. 256.
materialized_view_corpora: Array with the materialized view corpora, e.g.
["canvaskit", "colorImage", "gm", "image", "pathkit", "skp", "svg"]. Optional.
formatted_runner_script = _RUNNER_SCRIPT.format(
bazel_target_name = "//%s:%s" % (native.package_name(), name),
default_corpus = default_corpus,
title = title,
materialized_view_corpora =
materialized_view_corpora if materialized_view_corpora else "null",
gcs_bucket = gcs_bucket,
git_repo_url = git_repo_url,
site_url = site_url,
sql_database = sql_database,
known_hashes_gcs_path = known_hashes_gcs_path,
window_size = window_size,
deps = [
] + ["//golden/pages:%s_dev" % page for page in ALL_GOLD_PAGES]
name = name + "_runner",
srcs = deps,
outs = [name + ""],
cmd = "echo '%s' > $@" % formatted_runner_script,
name = name,
srcs = [name + "_runner"],
data = deps,