Skip to content

Commit

Permalink
feat: better install script, install via commit
Browse files Browse the repository at this point in the history
  • Loading branch information
frrist committed Feb 9, 2024
1 parent e6daab6 commit 1d38ebd
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 6 deletions.
2 changes: 2 additions & 0 deletions ops/tf/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module "requester_instance" {

bacalhau_install_version = var.bacalhau_install_version
bacalhau_install_branch = var.bacalhau_install_branch
bacalhau_install_commit = var.bacalhau_install_commit
}

module "compute_instance" {
Expand Down Expand Up @@ -66,4 +67,5 @@ module "compute_instance" {

bacalhau_install_version = var.bacalhau_install_version
bacalhau_install_branch = var.bacalhau_install_branch
bacalhau_install_commit = var.bacalhau_install_commit
}
8 changes: 8 additions & 0 deletions ops/tf/modules/cloud-init/cloud-init.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
write_files:
# bacalhau install-script
- path: /etc/install-bacalhau.sh
encoding: b64
owner: root:root
permissions: "0600"
content: |
${bacalhau_install_script_file}
# bacalhau config
- path: /etc/config.yaml
encoding: b64
Expand Down
9 changes: 6 additions & 3 deletions ops/tf/modules/gcp/compute_instances/compute/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ resource "google_compute_attached_disk" "attach_bacalhau_local_disks" {

locals {
//
// templating the bacalhau service file
//
// templating the bacalhau install script file

// service env vars
bacalhau_env_vars = {
Expand Down Expand Up @@ -107,13 +106,16 @@ locals {
//

// 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}" : ""
// I am sorry reader, terraform requires this be one line
bacalhau_install_cmd_content = var.bacalhau_install_version != "" ? "release ${var.bacalhau_install_version}" : var.bacalhau_install_branch != "" ? "branch ${var.bacalhau_install_branch}" : var.bacalhau_install_commit != "" ? "commit ${var.bacalhau_install_commit}" : ""
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
})

bacalhau_install_script_content = file("${path.module}/../../../instance_files/install-bacalhau.sh")

//
// templating otel config file
//
Expand Down Expand Up @@ -154,6 +156,7 @@ data "cloudinit_config" "compute_cloud_init" {
content_type = "text/cloud-config"

content = templatefile("${path.module}/../../../cloud-init/cloud-init.yml", {
bacalhau_install_script_file: base64encode(local.bacalhau_install_script_content)
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)
Expand Down
6 changes: 6 additions & 0 deletions ops/tf/modules/gcp/compute_instances/compute/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,9 @@ variable "bacalhau_install_branch" {
type = string
default = ""
}

variable "bacalhau_install_commit" {
description = "The commit sha of bacalhau to install. If empty default to https://get.bacalhau.org/install.sh"
type = string
default = ""
}
6 changes: 5 additions & 1 deletion ops/tf/modules/gcp/compute_instances/requester/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ locals {
args = local.bacalhau_args,
})

bacalhau_install_script_content = file("${path.module}/../../../instance_files/install-bacalhau.sh")

//
// templating the bacalhau config file
//
Expand All @@ -87,7 +89,8 @@ locals {
//

// 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}" : ""
// I am sorry reader, terraform requires this be one line
bacalhau_install_cmd_content = var.bacalhau_install_version != "" ? "release ${var.bacalhau_install_version}" : var.bacalhau_install_branch != "" ? "branch ${var.bacalhau_install_branch}" : var.bacalhau_install_commit != "" ? "commit ${var.bacalhau_install_commit}" : ""
bacalhau_start_script = templatefile("${path.module}/../../../instance_files/start.sh", {
node_type = "requester"
bacalhau_version_cmd = local.bacalhau_install_cmd_content
Expand Down Expand Up @@ -133,6 +136,7 @@ data "cloudinit_config" "requester_cloud_init" {
content_type = "text/cloud-config"

content = templatefile("${path.module}/../../../cloud-init/cloud-init.yml", {
bacalhau_install_script_file: base64encode(local.bacalhau_install_script_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)
Expand Down
6 changes: 6 additions & 0 deletions ops/tf/modules/gcp/compute_instances/requester/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,9 @@ variable "bacalhau_install_branch" {
type = string
default = ""
}

variable "bacalhau_install_commit" {
description = "The commit sha of bacalhau to install. If empty default to https://get.bacalhau.org/install.sh"
type = string
default = ""
}
139 changes: 139 additions & 0 deletions ops/tf/modules/instance_files/install-bacalhau.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#!/bin/bash

set -x

# Usage: install-bacalhau [release <version> | branch <branch-name> | commit <commit-sha>]
function install-bacalhau() {
if [ $# -eq 0 ]; then
install-bacalhau-default
elif [ "$1" = "release" ]; then
install-bacalhau-from-release "$2"
elif [ "$1" = "branch" ]; then
install-bacalhau-from-branch "$2"
elif [ "$1" == "commit" ]; then
install-bacalhau-from-commit "$2"
else
echo "Invalid argument: $1" >&2
echo "Usage: install-bacalhau [release <version> | branch <branch-name> | commit <commit-sha>]" >&2
return 1
fi
}

# installs bacalhau using the get.bacalhau.org/install.sh script.
function install-bacalhau-default() {
echo "Installing Bacalhau from get.bacalhau.org"
curl -sL https://get.bacalhau.org/install.sh | bash || {
echo "Failed to install Bacalhau using default method" >&2
return 1
}
}

# installs bacalhau from a specific release tag, e.g. v1.0.0, v1.2.1, etc.
function install-bacalhau-from-release() {
local version=$1
echo "Installing Bacalhau from release ${version}"
apt-get -y install --no-install-recommends jq || {
echo "Failed to install jq" >&2
return 1
}

wget "https://github.com/bacalhau-project/bacalhau/releases/download/${version}/bacalhau_${version}_linux_amd64.tar.gz" || {
echo "Failed to download Bacalhau release ${version}" >&2
return 1
}

tar xfv "bacalhau_${version}_linux_amd64.tar.gz" || {
echo "Failed to extract Bacalhau release ${version}" >&2
return 1
}

mv ./bacalhau /usr/local/bin/bacalhau || {
echo "Failed to move Bacalhau to /usr/local/bin" >&2
return 1
}
}

# installs the dependencies required to build bacalhau from source
function install-bacalhau-dependencies() {
echo "Installing Bacalhau dependencies..."
sudo apt update -y
sudo apt-get -y install --no-install-recommends jq make gcc g++ zip || {
echo "Failed to install dependencies." >&2
return 1
}

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs

sudo apt remove cmdtest -y
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update
sudo apt-get -y install --no-install-recommends yarn
}

# installs bacalhau based on a branch name, e.g. main, frrist/some-code, simon/some-other-code, etc.
function install-bacalhau-from-branch() {
local branch=$1
echo "Installing Bacalhau from branch ${branch}"
install-bacalhau-dependencies || return 1

git clone --branch "${branch}" https://github.com/bacalhau-project/bacalhau.git || {
echo "Failed to clone repository" >&2
return 1
}

pushd bacalhau || return 1
pushd webui || return 1
yarn install || {
echo "Failed to install yarn packages" >&2
popd
return 1
}
popd

make build-bacalhau || {
echo "Failed to build bacalhau" >&2
popd
return 1
}
mv ./bin/*/*/bacalhau /usr/local/bin/bacalhau
popd
}

# installs the version of bacalhau based on a git commit sha.
function install-bacalhau-from-commit() {
local commit_sha=$1
echo "Installing Bacalhau from commit ${commit_sha}"
install-bacalhau-dependencies || return 1

git clone https://github.com/bacalhau-project/bacalhau.git || {
echo "Failed to clone repository" >&2
return 1
}

pushd bacalhau || return 1
git checkout "${commit_sha}" || {
echo "Failed to checkout commit ${commit_sha}" >&2
popd
return 1
}

pushd webui || return 1
yarn install || {
echo "Failed to install yarn packages" >&2
popd
return 1
}
popd

make build-bacalhau || {
echo "Failed to build bacalhau" >&2
popd
return 1
}
mv ./bin/*/*/bacalhau /usr/local/bin/bacalhau
popd
}

install-bacalhau "$@"
8 changes: 7 additions & 1 deletion ops/tf/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,10 @@ variable "bacalhau_install_branch" {
description = "The branch of bacalhau to install. If empty default to https://get.bacalhau.org/install.sh"
type = string
default = ""
}
}

variable "bacalhau_install_commit" {
description = "The commit sha of bacalhau to install. If empty default to https://get.bacalhau.org/install.sh"
type = string
default = ""
}
3 changes: 2 additions & 1 deletion ops/tf/vars.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ bacalhau_accept_networked_jobs = true

bacalhau_otel_collector_endpoint = "http://analytics.bacalhau.tech:4318"

bacalhau_install_branch = "main"
bacalhau_install_branch = ""
bacalhau_install_version = ""
bacalhau_install_commit = "292663a6a23fe9a88dabb2b3bdf797dfa825bbe5"

0 comments on commit 1d38ebd

Please sign in to comment.