From e390372ae202fa36c6671a5bf95f9b26dfc2a82d Mon Sep 17 00:00:00 2001 From: frrist Date: Tue, 6 Feb 2024 18:21:12 -0800 Subject: [PATCH] feat: allow different versions of bacalhau to be installed gracefully handle version upgrades, ensure the attached disks re-attach --- ops/tf/main.tf | 6 ++++++ ops/tf/modules/cloud-init/cloud-init.yml | 8 ------- .../gcp/compute_instances/compute/main.tf | 21 ++++++++++++------- .../compute_instances/compute/variables.tf | 13 +++++++++++- .../gcp/compute_instances/requester/main.tf | 20 +++++++++++------- .../compute_instances/requester/variables.tf | 12 +++++++++++ ops/tf/modules/instance_files/start.sh | 12 +++++++++++ ops/tf/variables.tf | 13 ++++++++++++ ops/tf/vars.tfvars | 7 +++++-- 9 files changed, 86 insertions(+), 26 deletions(-) diff --git a/ops/tf/main.tf b/ops/tf/main.tf index 83846c7491..8a4d3a40f0 100644 --- a/ops/tf/main.tf +++ b/ops/tf/main.tf @@ -32,6 +32,9 @@ module "requester_instance" { bacalhau_repo_disk_size = var.bacalhau_repo_disk_size bacalhau_otel_collector_endpoint = var.bacalhau_otel_collector_endpoint bacalhau_auth_token = random_string.bacalhau_auth_token.result + + bacalhau_install_version = var.bacalhau_install_version + bacalhau_install_branch = var.bacalhau_install_branch } module "compute_instance" { @@ -60,4 +63,7 @@ module "compute_instance" { bacalhau_local_disk_size = var.bacalhau_local_disk_size bacalhau_otel_collector_endpoint = var.bacalhau_otel_collector_endpoint bacalhau_auth_token = random_string.bacalhau_auth_token.result + + bacalhau_install_version = var.bacalhau_install_version + bacalhau_install_branch = var.bacalhau_install_branch } \ No newline at end of file diff --git a/ops/tf/modules/cloud-init/cloud-init.yml b/ops/tf/modules/cloud-init/cloud-init.yml index 0f72e53490..8ca9356dff 100644 --- a/ops/tf/modules/cloud-init/cloud-init.yml +++ b/ops/tf/modules/cloud-init/cloud-init.yml @@ -1,11 +1,3 @@ -#cloud-config -packages: - - jq - -runcmd: - - bash /etc/install-bacalhau.sh release v1.2.1 - - systemctl restart bacalhau - write_files: # bacalhau config - path: /etc/config.yaml diff --git a/ops/tf/modules/gcp/compute_instances/compute/main.tf b/ops/tf/modules/gcp/compute_instances/compute/main.tf index 2271260975..6f52fe35f0 100644 --- a/ops/tf/modules/gcp/compute_instances/compute/main.tf +++ b/ops/tf/modules/gcp/compute_instances/compute/main.tf @@ -6,10 +6,11 @@ resource "google_compute_instance" "compute" { zone = var.zone metadata = { - startup-script = local.bacalhau_start_script user-data = data.cloudinit_config.compute_cloud_init.rendered } + metadata_startup_script = local.bacalhau_start_script + boot_disk { initialize_params { image = var.boot_image @@ -99,8 +100,12 @@ locals { // // templating the bacalhau start script // + + // inject custom bacalhau install based on variables. + bacalhau_install_cmd_content = var.bacalhau_install_version != "" ? "release ${var.bacalhau_install_version}" : var.bacalhau_install_branch != "" ? "branch ${var.bacalhau_install_branch}" : "" bacalhau_start_script = templatefile("${path.module}/../../../instance_files/start.sh", { node_type = "compute" + bacalhau_version_cmd = local.bacalhau_install_cmd_content // Add more arguments as needed }) @@ -144,13 +149,13 @@ data "cloudinit_config" "compute_cloud_init" { content_type = "text/cloud-config" content = templatefile("${path.module}/../../../cloud-init/cloud-init.yml", { - bacalhau_config_file : base64encode(local.compute_config_content), - bacalhau_service_file : base64encode(local.bacalhau_service_content), - bacalhau_authn_policy_file : base64encode(local.bacalhau_authn_policy_content) - bacalhau_authz_policy_file : base64encode(local.bacalhau_authz_policy_content) - otel_config_file : base64encode(local.otel_config_content) - otel_service_file : base64encode(local.otel_service_content), - requester_ip : var.requester_ip, + bacalhau_config_file : base64encode(local.compute_config_content) + bacalhau_service_file : base64encode(local.bacalhau_service_content) + bacalhau_authn_policy_file : base64encode(local.bacalhau_authn_policy_content) + bacalhau_authz_policy_file : base64encode(local.bacalhau_authz_policy_content) + otel_config_file : base64encode(local.otel_config_content) + otel_service_file : base64encode(local.otel_service_content) + requester_ip : var.requester_ip }) } } \ No newline at end of file diff --git a/ops/tf/modules/gcp/compute_instances/compute/variables.tf b/ops/tf/modules/gcp/compute_instances/compute/variables.tf index 69808d4a17..27d1c7384d 100644 --- a/ops/tf/modules/gcp/compute_instances/compute/variables.tf +++ b/ops/tf/modules/gcp/compute_instances/compute/variables.tf @@ -70,7 +70,6 @@ variable "bacalhau_local_disk_size" { type = number } - variable "bacalhau_otel_collector_endpoint" { description = "The opentelemetry collector endpoint to send metrics to" type = string @@ -80,3 +79,15 @@ variable "bacalhau_auth_token" { description = "Auth token for bacalhau api" type = string } + +variable "bacalhau_install_version" { + description = "The version or branch of bacalhau to install. If empty https://get.bacalhau.org/install.sh will be used to install" + type = string + default = "" +} + +variable "bacalhau_install_branch" { + description = "The branch of bacalhau to install. If empty default to https://get.bacalhau.org/install.sh" + type = string + default = "" +} diff --git a/ops/tf/modules/gcp/compute_instances/requester/main.tf b/ops/tf/modules/gcp/compute_instances/requester/main.tf index 2e0235db4f..3bdeae24e8 100644 --- a/ops/tf/modules/gcp/compute_instances/requester/main.tf +++ b/ops/tf/modules/gcp/compute_instances/requester/main.tf @@ -5,9 +5,11 @@ resource "google_compute_instance" "requester" { zone = var.zone metadata = { - startup-script = local.bacalhau_start_script user-data = data.cloudinit_config.requester_cloud_init.rendered } + + metadata_startup_script = local.bacalhau_start_script + boot_disk { initialize_params { image = var.boot_image @@ -78,8 +80,12 @@ locals { // // templating the bacalhau start script // + + // inject custom bacalhau install based on variables. + bacalhau_install_cmd_content = var.bacalhau_install_version != "" ? "release ${var.bacalhau_install_version}" : var.bacalhau_install_branch != "" ? "branch ${var.bacalhau_install_branch}" : "" bacalhau_start_script = templatefile("${path.module}/../../../instance_files/start.sh", { node_type = "requester" + bacalhau_version_cmd = local.bacalhau_install_cmd_content // Add more arguments as needed }) @@ -122,12 +128,12 @@ data "cloudinit_config" "requester_cloud_init" { content_type = "text/cloud-config" content = templatefile("${path.module}/../../../cloud-init/cloud-init.yml", { - bacalhau_config_file : base64encode(local.requester_config_content) - bacalhau_service_file : base64encode(local.bacalhau_service_content) - bacalhau_authn_policy_file : base64encode(local.bacalhau_authn_policy_content) - bacalhau_authz_policy_file : base64encode(local.bacalhau_authz_policy_content) - otel_config_file : base64encode(local.otel_config_content) - otel_service_file : base64encode(local.otel_service_content) + bacalhau_config_file : base64encode(local.requester_config_content) + bacalhau_service_file : base64encode(local.bacalhau_service_content) + bacalhau_authn_policy_file : base64encode(local.bacalhau_authn_policy_content) + bacalhau_authz_policy_file : base64encode(local.bacalhau_authz_policy_content) + otel_config_file : base64encode(local.otel_config_content) + otel_service_file : base64encode(local.otel_service_content) }) } } \ No newline at end of file diff --git a/ops/tf/modules/gcp/compute_instances/requester/variables.tf b/ops/tf/modules/gcp/compute_instances/requester/variables.tf index f4bc4cf8fb..8752fb70a0 100644 --- a/ops/tf/modules/gcp/compute_instances/requester/variables.tf +++ b/ops/tf/modules/gcp/compute_instances/requester/variables.tf @@ -69,3 +69,15 @@ variable "bacalhau_auth_token" { description = "Auth token for bacalhau api" type = string } + +variable "bacalhau_install_version" { + description = "The version or branch of bacalhau to install. If empty https://get.bacalhau.org/install.sh will be used to install" + type = string + default = "" +} + +variable "bacalhau_install_branch" { + description = "The branch of bacalhau to install. If empty default to https://get.bacalhau.org/install.sh" + type = string + default = "" +} diff --git a/ops/tf/modules/instance_files/start.sh b/ops/tf/modules/instance_files/start.sh index cb888115dc..c0cc5559cb 100644 --- a/ops/tf/modules/instance_files/start.sh +++ b/ops/tf/modules/instance_files/start.sh @@ -1,6 +1,9 @@ #!/bin/bash +set -x + NODE_TYPE="${node_type}" +BACALHAU_VERSION_CMD="${bacalhau_version_cmd}" # mount or format repo disk function setup-bacalhau-repo-disk() { @@ -49,6 +52,11 @@ function install-otel-collector() { sudo mv otelcol-contrib /usr/local/bin/otelcol } +function install-bacalhau() { + echo "Installing bacalhau" + bash /etc/install-bacalhau.sh $BACALHAU_VERSION_CMD +} + # reload service files and enable services function setup-services() { echo "Loading systemctl services..." @@ -76,6 +84,10 @@ function start() { setup-bacalhau-local-disk fi + if [ "$BACALHAU_VERSION_CMD" != "" ]; then + install-bacalhau + fi + # TODO move this into the VMI, maybe? install-otel-collector setup-bacalhau-config diff --git a/ops/tf/variables.tf b/ops/tf/variables.tf index d904c2c40e..141408a976 100644 --- a/ops/tf/variables.tf +++ b/ops/tf/variables.tf @@ -65,3 +65,16 @@ variable "bacalhau_otel_collector_endpoint" { description = "The opentelemetry collector endpoint to send metrics to" type = string } + + +variable "bacalhau_install_version" { + description = "The version of bacalhau to install. If empty default to https://get.bacalhau.org/install.sh" + type = string + default = "" +} + +variable "bacalhau_install_branch" { + description = "The branch of bacalhau to install. If empty default to https://get.bacalhau.org/install.sh" + type = string + default = "" +} \ No newline at end of file diff --git a/ops/tf/vars.tfvars b/ops/tf/vars.tfvars index 19802e158c..d0889bf716 100644 --- a/ops/tf/vars.tfvars +++ b/ops/tf/vars.tfvars @@ -7,7 +7,7 @@ requester_machine_type ="e2-standard-8" compute_machine_type = "e2-standard-8" compute_count = 2 -gcp_boot_image = "projects/forrest-dev-407420/global/images/bacalhau-ubuntu-2004-lts-test" +gcp_boot_image = "projects/forrest-dev-407420/global/images/bacalhau-ubuntu-2204-lts-test-latest" gcp_project_id = "forrest-dev-407420" gcp_region = "us-west1" gcp_zone = "us-west1-b" @@ -18,4 +18,7 @@ aws_secret_access_key = "" bacalhau_accept_networked_jobs = true -bacalhau_otel_collector_endpoint = "" \ No newline at end of file +bacalhau_otel_collector_endpoint = "" + +bacalhau_install_branch = "main" +bacalhau_install_version = ""