Skip to content

Commit

Permalink
feat: allow different versions of bacalhau to be installed
Browse files Browse the repository at this point in the history
gracefully handle version upgrades, ensure the attached disks re-attach
  • Loading branch information
frrist committed Feb 7, 2024
1 parent 2865c5f commit e390372
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 26 deletions.
6 changes: 6 additions & 0 deletions ops/tf/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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
}
8 changes: 0 additions & 8 deletions ops/tf/modules/cloud-init/cloud-init.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
21 changes: 13 additions & 8 deletions ops/tf/modules/gcp/compute_instances/compute/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
})

Expand Down Expand Up @@ -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
})
}
}
13 changes: 12 additions & 1 deletion ops/tf/modules/gcp/compute_instances/compute/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = ""
}
20 changes: 13 additions & 7 deletions ops/tf/modules/gcp/compute_instances/requester/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
})

Expand Down Expand Up @@ -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)
})
}
}
12 changes: 12 additions & 0 deletions ops/tf/modules/gcp/compute_instances/requester/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
}
12 changes: 12 additions & 0 deletions ops/tf/modules/instance_files/start.sh
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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..."
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions ops/tf/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
}
7 changes: 5 additions & 2 deletions ops/tf/vars.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -18,4 +18,7 @@ aws_secret_access_key = ""

bacalhau_accept_networked_jobs = true

bacalhau_otel_collector_endpoint = ""
bacalhau_otel_collector_endpoint = ""

bacalhau_install_branch = "main"
bacalhau_install_version = ""

0 comments on commit e390372

Please sign in to comment.