-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
941 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
locals { | ||
autoid_node_ip_v4 = flatten([ | ||
[aws_instance.autoid_node.*.public_ip] | ||
] | ||
) | ||
} | ||
|
||
resource "null_resource" "setup-autoid-nodes" { | ||
count = length(local.autoid_node_ip_v4) | ||
|
||
depends_on = [aws_instance.autoid_node] | ||
|
||
# trigger on node ip changes | ||
triggers = { | ||
cluster_instance_ipv4s = join(",", local.autoid_node_ip_v4) | ||
} | ||
|
||
connection { | ||
host = local.autoid_node_ip_v4[count.index] | ||
user = var.ssh_user | ||
type = "ssh" | ||
agent = true | ||
private_key = file("${var.private_key_path}") | ||
timeout = "300s" | ||
} | ||
|
||
# create subspace dir | ||
provisioner "remote-exec" { | ||
inline = [ | ||
"sudo mkdir -p /home/${var.ssh_user}/subspace/", | ||
"sudo chown -R ${var.ssh_user}:${var.ssh_user} /home/${var.ssh_user}/subspace/ && sudo chmod -R 750 /home/${var.ssh_user}/subspace/" | ||
] | ||
} | ||
|
||
# copy install file | ||
provisioner "file" { | ||
source = "${var.path_to_scripts}/installer.sh" | ||
destination = "/home/${var.ssh_user}/subspace/installer.sh" | ||
} | ||
|
||
# copy acme.sh file | ||
provisioner "file" { | ||
source = "${var.path_to_scripts}/acme.sh" | ||
destination = "/home/${var.ssh_user}/subspace/acme.sh" | ||
} | ||
|
||
# install docker and docker compose | ||
provisioner "remote-exec" { | ||
inline = [ | ||
"sudo bash /home/${var.ssh_user}/subspace/installer.sh", | ||
] | ||
} | ||
|
||
# clone testing branch | ||
provisioner "remote-exec" { | ||
inline = [ | ||
"cd /home/${var.ssh_user}/subspace/", | ||
"git clone https://github.com/subspace/subspace.git", | ||
"cd subspace", | ||
"git checkout ${var.branch_name}" | ||
] | ||
} | ||
|
||
} | ||
|
||
resource "null_resource" "prune-autoid-nodes" { | ||
count = var.autoid-node-config.prune ? length(local.autoid_node_ip_v4) : 0 | ||
depends_on = [null_resource.setup-autoid-nodes] | ||
|
||
triggers = { | ||
prune = var.autoid-node-config.prune | ||
} | ||
|
||
connection { | ||
host = local.autoid_node_ip_v4[count.index] | ||
user = var.ssh_user | ||
type = "ssh" | ||
agent = true | ||
private_key = file("${var.private_key_path}") | ||
timeout = "300s" | ||
} | ||
|
||
provisioner "file" { | ||
source = "${var.path_to_scripts}/prune_docker_system.sh" | ||
destination = "/home/${var.ssh_user}/subspace/prune_docker_system.sh" | ||
} | ||
|
||
# prune network | ||
provisioner "remote-exec" { | ||
inline = [ | ||
"sudo bash /home/${var.ssh_user}/subspace/prune_docker_system.sh" | ||
] | ||
} | ||
} | ||
|
||
resource "null_resource" "start-autoid-nodes" { | ||
count = length(local.autoid_node_ip_v4) | ||
|
||
depends_on = [null_resource.setup-autoid-nodes] | ||
|
||
# trigger on node deployment version change | ||
triggers = { | ||
deployment_version = var.autoid-node-config.deployment-version | ||
reserved_only = var.autoid-node-config.reserved-only | ||
} | ||
|
||
connection { | ||
host = local.autoid_node_ip_v4[count.index] | ||
user = var.ssh_user | ||
type = "ssh" | ||
agent = true | ||
private_key = file("${var.private_key_path}") | ||
timeout = "300s" | ||
} | ||
|
||
# copy node keys file | ||
provisioner "file" { | ||
source = "./autoid_node_keys.txt" | ||
destination = "/home/${var.ssh_user}/subspace/node_keys.txt" | ||
} | ||
|
||
# copy boostrap node keys file | ||
provisioner "file" { | ||
source = "./bootstrap_node_keys.txt" | ||
destination = "/home/${var.ssh_user}/subspace/bootstrap_node_keys.txt" | ||
} | ||
|
||
# copy dsn_boostrap node keys file | ||
provisioner "file" { | ||
source = "./dsn_bootstrap_node_keys.txt" | ||
destination = "/home/${var.ssh_user}/subspace/dsn_bootstrap_node_keys.txt" | ||
} | ||
|
||
# copy keystore | ||
provisioner "file" { | ||
source = "./keystore" | ||
destination = "/home/${var.ssh_user}/subspace/subspace/keystore/" | ||
} | ||
|
||
# copy relayer ids | ||
provisioner "file" { | ||
source = "./relayer_ids.txt" | ||
destination = "/home/${var.ssh_user}/subspace/relayer_ids.txt" | ||
} | ||
|
||
# copy compose file creation script | ||
provisioner "file" { | ||
source = "${var.path_to_scripts}/create_autoid_node_compose_file.sh" | ||
destination = "/home/${var.ssh_user}/subspace/create_compose_file.sh" | ||
} | ||
|
||
# start docker containers | ||
provisioner "remote-exec" { | ||
inline = [ | ||
# set hostname | ||
"sudo hostnamectl set-hostname ${var.network_name}-autoid-node-${count.index}", | ||
|
||
# create .env file | ||
"echo REPO_ORG=${var.autoid-node-config.repo-org} > /home/${var.ssh_user}/subspace/.env", | ||
"echo DOCKER_TAG=${var.autoid-node-config.docker-tag} >> /home/${var.ssh_user}/subspace/.env", | ||
"echo NETWORK_NAME=${var.network_name} >> /home/${var.ssh_user}/subspace/.env", | ||
"echo DOMAIN_PREFIX_AUTO=${var.autoid-node-config.domain-prefix[1]} >> /home/${var.ssh_user}/subspace/.env", | ||
"echo DOMAIN_LABEL_AUTO=${var.autoid-node-config.domain-labels[1]} >> /home/${var.ssh_user}/subspace/.env", | ||
"echo DOMAIN_ID_AUTO=${var.autoid-node-config.domain-id[1]} >> /home/${var.ssh_user}/subspace/.env", | ||
"echo NODE_ID=${count.index} >> /home/${var.ssh_user}/subspace/.env", | ||
"echo NODE_KEY=$(sed -nr 's/NODE_${count.index}_KEY=//p' /home/${var.ssh_user}/subspace/node_keys.txt) >> /home/${var.ssh_user}/subspace/.env", | ||
"echo PIECE_CACHE_SIZE=${var.piece_cache_size} >> /home/${var.ssh_user}/subspace/.env", | ||
"echo NODE_DSN_PORT=${var.autoid-node-config.node-dsn-port} >> /home/${var.ssh_user}/subspace/.env", | ||
|
||
# create docker compose file | ||
"bash /home/${var.ssh_user}/subspace/create_compose_file.sh ${var.bootstrap-node-config.reserved-only} ${length(local.autoid_node_ip_v4)} ${count.index} ${length(local.bootstrap_nodes_ip_v4)} ${var.autoid-node-config.enable-domains} ${var.autoid-node-config.domain-id[0]}", | ||
|
||
# create acme.json file | ||
"bash /home/${var.ssh_user}/subspace/acme.sh", | ||
|
||
# start subspace domain node | ||
"cp -f /home/${var.ssh_user}/subspace/.env /home/${var.ssh_user}/subspace/subspace/.env", | ||
"sudo docker compose -f /home/${var.ssh_user}/subspace/subspace/docker-compose.yml up -d", | ||
] | ||
} | ||
} |
171 changes: 171 additions & 0 deletions
171
testing-framework/ec2/base/bootstrap_node_autoid_provisioner.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
locals { | ||
bootstrap_nodes_autoid_ip_v4 = flatten([ | ||
[aws_instance.bootstrap_node_autoid.*.public_ip] | ||
] | ||
) | ||
} | ||
|
||
resource "null_resource" "setup-bootstrap-nodes-autoid" { | ||
count = length(local.bootstrap_nodes_autoid_ip_v4) | ||
|
||
depends_on = [aws_instance.bootstrap_node_autoid] | ||
|
||
# trigger on node ip changes | ||
triggers = { | ||
cluster_instance_ipv4s = join(",", local.bootstrap_nodes_autoid_ip_v4) | ||
} | ||
|
||
connection { | ||
host = local.bootstrap_nodes_autoid_ip_v4[count.index] | ||
user = var.ssh_user | ||
type = "ssh" | ||
agent = true | ||
private_key = file("${var.private_key_path}") | ||
timeout = "300s" | ||
} | ||
|
||
# create subspace dir | ||
provisioner "remote-exec" { | ||
inline = [ | ||
"sudo mkdir -p /home/${var.ssh_user}/subspace/", | ||
"sudo chown -R ${var.ssh_user}:${var.ssh_user} /home/${var.ssh_user}/subspace/ && sudo chmod -R 750 /home/${var.ssh_user}/subspace/" | ||
] | ||
} | ||
|
||
# copy install file | ||
provisioner "file" { | ||
source = "${var.path_to_scripts}/installer.sh" | ||
destination = "/home/${var.ssh_user}/subspace/installer.sh" | ||
} | ||
|
||
# install docker and docker compose | ||
provisioner "remote-exec" { | ||
inline = [ | ||
"chmod +x /home/${var.ssh_user}/subspace/installer.sh", | ||
"sudo bash /home/${var.ssh_user}/subspace/installer.sh", | ||
] | ||
} | ||
|
||
# clone testing branch | ||
provisioner "remote-exec" { | ||
inline = [ | ||
"cd /home/${var.ssh_user}/subspace/", | ||
"git clone https://github.com/subspace/subspace.git", | ||
"cd subspace", | ||
"git checkout ${var.branch_name}" | ||
] | ||
} | ||
|
||
} | ||
|
||
resource "null_resource" "prune-bootstrap-nodes-autoid" { | ||
count = var.bootstrap-node-autoid-config.prune ? length(local.bootstrap_nodes_autoid_ip_v4) : 0 | ||
depends_on = [null_resource.setup-bootstrap-nodes-autoid] | ||
|
||
triggers = { | ||
prune = var.bootstrap-node-autoid-config.prune | ||
} | ||
|
||
connection { | ||
host = local.bootstrap_nodes_autoid_ip_v4[count.index] | ||
user = var.ssh_user | ||
type = "ssh" | ||
agent = true | ||
private_key = file("${var.private_key_path}") | ||
timeout = "300s" | ||
} | ||
|
||
provisioner "file" { | ||
source = "${var.path_to_scripts}/prune_docker_system.sh" | ||
destination = "/home/${var.ssh_user}/subspace/prune_docker_system.sh" | ||
} | ||
|
||
# prune network | ||
provisioner "remote-exec" { | ||
inline = [ | ||
"sudo bash /home/${var.ssh_user}/subspace/prune_docker_system.sh" | ||
] | ||
} | ||
} | ||
|
||
resource "null_resource" "start-bootstrap-nodes-autoid" { | ||
count = length(local.bootstrap_nodes_autoid_ip_v4) | ||
|
||
depends_on = [null_resource.setup-bootstrap-nodes-autoid] | ||
|
||
# trigger on node deployment version change | ||
triggers = { | ||
deployment_version = var.bootstrap-node-autoid-config.deployment-version | ||
reserved_only = var.bootstrap-node-autoid-config.reserved-only | ||
} | ||
|
||
connection { | ||
host = local.bootstrap_nodes_autoid_ip_v4[count.index] | ||
user = var.ssh_user | ||
type = "ssh" | ||
agent = true | ||
private_key = file("${var.private_key_path}") | ||
timeout = "300s" | ||
} | ||
|
||
# copy bootstrap node keys file | ||
provisioner "file" { | ||
source = "./bootstrap_node_autoid_keys.txt" | ||
destination = "/home/${var.ssh_user}/subspace/node_keys.txt" | ||
} | ||
|
||
# copy boostrap node keys file | ||
provisioner "file" { | ||
source = "./bootstrap_node_keys.txt" | ||
destination = "/home/${var.ssh_user}/subspace/bootstrap_node_keys.txt" | ||
} | ||
|
||
# copy DSN bootstrap node keys file | ||
provisioner "file" { | ||
source = "./dsn_bootstrap_node_keys.txt" | ||
destination = "/home/${var.ssh_user}/subspace/dsn_bootstrap_node_keys.txt" | ||
} | ||
|
||
# copy relayer ids | ||
provisioner "file" { | ||
source = "./relayer_ids.txt" | ||
destination = "/home/${var.ssh_user}/subspace/relayer_ids.txt" | ||
} | ||
|
||
# copy compose file creation script | ||
provisioner "file" { | ||
source = "${var.path_to_scripts}/create_bootstrap_node_autoid_compose_file.sh" | ||
destination = "/home/${var.ssh_user}/subspace/create_compose_file.sh" | ||
} | ||
|
||
# start docker containers | ||
provisioner "remote-exec" { | ||
inline = [ | ||
# set hostname | ||
"sudo hostnamectl set-hostname ${var.network_name}-bootstrap-node-autoid-${count.index}", | ||
|
||
# create .env file | ||
"echo REPO_ORG=${var.bootstrap-node-autoid-config.repo-org} > /home/${var.ssh_user}/subspace/.env", | ||
"echo DOCKER_TAG=${var.bootstrap-node-autoid-config.docker-tag} >> /home/${var.ssh_user}/subspace/.env", | ||
"echo NETWORK_NAME=${var.network_name} >> /home/${var.ssh_user}/subspace/.env", | ||
"echo NODE_ID=${count.index} >> /home/${var.ssh_user}/subspace/.env", | ||
"echo NODE_KEY=$(sed -nr 's/NODE_${count.index}_KEY=//p' /home/${var.ssh_user}/subspace/node_keys.txt) >> /home/${var.ssh_user}/subspace/.env", | ||
"echo DOMAIN_LABEL_AUTO=${var.domain-node-config.domain-labels[1]} >> /home/${var.ssh_user}/subspace/.env", | ||
"echo DOMAIN_ID_AUTO=${var.domain-node-config.domain-id[1]} >> /home/${var.ssh_user}/subspace/.env", | ||
"echo PIECE_CACHE_SIZE=${var.piece_cache_size} >> /home/${var.ssh_user}/subspace/.env", | ||
"echo DSN_NODE_ID=${count.index} >> /home/${var.ssh_user}/subspace/.env", | ||
"echo DSN_NODE_KEY=$(sed -nr 's/NODE_${count.index}_DSN_KEY=//p' /home/${var.ssh_user}/subspace/node_keys.txt) >> /home/${var.ssh_user}/subspace/.env", | ||
"echo DSN_LISTEN_PORT=${var.bootstrap-node-autoid-config.dsn-listen-port} >> /home/${var.ssh_user}/subspace/.env", | ||
"echo NODE_DSN_PORT=${var.bootstrap-node-autoid-config.node-dsn-port} >> /home/${var.ssh_user}/subspace/.env", | ||
"echo OPERATOR_PORT=${var.bootstrap-node-autoid-config.operator-port} >> /home/${var.ssh_user}/subspace/.env", | ||
"echo GENESIS_HASH=${var.bootstrap-node-autoid-config.genesis-hash} >> /home/${var.ssh_user}/subspace/.env", | ||
|
||
# create docker compose file | ||
"bash /home/${var.ssh_user}/subspace/create_compose_file.sh ${var.bootstrap-node-autoid-config.reserved-only} ${length(local.bootstrap_nodes_autoid_ip_v4)} ${count.index} ${length(local.bootstrap_nodes_ip_v4)} ${var.domain-node-config.enable-domains} ", | ||
|
||
# start subspace bootstrap autoid node | ||
"cp -f /home/${var.ssh_user}/subspace/.env /home/${var.ssh_user}/subspace/subspace/.env", | ||
"sudo docker compose -f /home/${var.ssh_user}/subspace/subspace/docker-compose.yml up -d", | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.