Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load Test AMI #4

Open
wants to merge 5 commits into
base: asg-deployment
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packer/blade/blade.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ packer {

variable "go_tag" {
type = string
default = "1.20.11.linux-amd64"
default = "1.22.6.linux-amd64"
}

variable "polycli_tag" {
Expand Down
2 changes: 1 addition & 1 deletion packer/common.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ packer {

variable "go_tag" {
type = string
default = "1.20.11.linux-amd64"
default = "1.22.6.linux-amd64"
}

variable "polycli_tag" {
Expand Down
2 changes: 1 addition & 1 deletion packer/geth/geth.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ packer {

variable "go_tag" {
type = string
default = "1.20.11.linux-amd64"
default = "1.22.6.linux-amd64"
}

variable "polycli_tag" {
Expand Down
143 changes: 143 additions & 0 deletions packer/load-test/load-test.pkr.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
packer {
required_plugins {
amazon = {
version = ">= 0.0.2"
source = "github.com/hashicorp/amazon"
}
}
}

variable "debug_mode" {
type = bool
default = false
}

variable "remove_ami" {
description = "Remove the previous AMI with same name"
type = bool
default = true
}

variable "go_tag" {
type = string
default = "1.22.6.linux-amd64"
}

variable "polycli_tag" {
type = string
default = "0.1.30"
}

variable "node_major" {
type = string
default = "20"
}

source "amazon-ebs" "ubuntu" {
skip_create_ami = var.debug_mode
force_deregister = var.remove_ami
force_delete_snapshot = var.remove_ami
ami_name = "load-test-${formatdate("YYYY-MM-DD", timestamp())}"
ami_description = "Load testing on blockchain verifies the system's ability to handle a large number of transactions, ensuring performance and scalability."
instance_type = "t2.micro"
region = "us-west-2"
availability_zone = "us-west-2a"
source_ami = "ami-0efcece6bed30fd98"
ssh_username = "ubuntu"
launch_block_device_mappings {
device_name = "/dev/sda1"
volume_size = 15
volume_type = "gp2"
delete_on_termination = true
}
run_tags = {
OS = "ubuntu"
Name = "load-test-${formatdate("YYYY-MM-DD", timestamp())}"
Libs = "jq, make, foundry, forge, cast, go, polycli, k6, xk6, xk6-ethereum, nodejs, npm, yarn, pandoras-box"
Rule = "loadtestrunner"
}
}

build {
name = "load-test"
sources = [
"source.amazon-ebs.ubuntu"
]

provisioner "shell" {
environment_vars = ["DEBIAN_FRONTEND=noninteractive"]
execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'"
max_retries = 2 # sometimes fails to update/upgrade Ubuntu
expect_disconnect = true
script = "${path.root}/scripts/common.sh"
}

provisioner "shell" {
environment_vars = ["DEBIAN_FRONTEND=noninteractive"]
execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'"
script = "${path.root}/scripts/foundry.sh"
}

provisioner "shell" {
environment_vars = [
"DEBIAN_FRONTEND=noninteractive",
"GO_TAG=${var.go_tag}"
]
execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'"
script = "${path.root}/scripts/golang.sh"
}

provisioner "shell" {
environment_vars = [
"DEBIAN_FRONTEND=noninteractive",
"POLYCLI_TAG=${var.polycli_tag}"
]
execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'"
script = "${path.root}/scripts/polycli.sh"
}

provisioner "shell" {
environment_vars = ["DEBIAN_FRONTEND=noninteractive"]
execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'"
script = "${path.root}/scripts/k6.sh"
}

provisioner "shell" {
environment_vars = ["DEBIAN_FRONTEND=noninteractive"]
execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'"
script = "${path.root}/scripts/xk6.sh"
}

provisioner "shell" {
environment_vars = ["DEBIAN_FRONTEND=noninteractive"]
execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'"
script = "${path.root}/scripts/xk6-ethereum.sh"
}

provisioner "shell" {
environment_vars = [
"DEBIAN_FRONTEND=noninteractive",
"NODE_MAJOR=${var.node_major}"
]
execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'"
script = "${path.root}/scripts/nodejs.sh"
}

provisioner "shell" {
environment_vars = ["DEBIAN_FRONTEND=noninteractive"]
execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'"
script = "${path.root}/scripts/yarn.sh"
}

provisioner "shell" {
environment_vars = ["DEBIAN_FRONTEND=noninteractive"]
execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'"
script = "${path.root}/scripts/pandoras-box.sh"
}

provisioner "shell" {
environment_vars = ["DEBIAN_FRONTEND=noninteractive"]
execute_command = "sudo sh -c '{{ .Vars }} {{ .Path }}'"
script = "${path.root}/scripts/verify.sh"
}
}
4 changes: 4 additions & 0 deletions packer/load-test/scripts/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash -e
sudo apt-get -y update
sudo apt-get -y upgrade
sudo apt-get -y install make jq
5 changes: 5 additions & 0 deletions packer/load-test/scripts/foundry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash -e
echo "Installing foundry"
curl -L https://foundry.paradigm.xyz | bash
/root/.foundry/bin/foundryup
sudo cp /root/.foundry/bin/* /usr/local/bin
8 changes: 8 additions & 0 deletions packer/load-test/scripts/golang.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash -e
echo "Installing golang"
rm -rf /usr/local/go
sudo wget https://go.dev/dl/go${GO_TAG}.tar.gz -O /opt/go${GO_TAG}.tar.gz
sudo chmod 0755 /opt/go${GO_TAG}.tar.gz
sudo tar -C /usr/local/ -xzf /opt/go${GO_TAG}.tar.gz
sudo ln -s /usr/local/go/bin/go /usr/local/bin/go
sudo rm -rf /opt/go${GO_TAG}.tar.gz
7 changes: 7 additions & 0 deletions packer/load-test/scripts/k6.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash -e
echo "Installing k6"
gpg -k
gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list > /dev/null
sudo apt-get -y update
sudo apt-get -y install k6
8 changes: 8 additions & 0 deletions packer/load-test/scripts/nodejs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash -e
echo "Installing nodejs"
sudo apt-get -y update
sudo apt-get -y install ca-certificates curl gnupg
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list > /dev/null
sudo apt-get -y update
sudo apt-get -y install nodejs
6 changes: 6 additions & 0 deletions packer/load-test/scripts/pandoras-box.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash -e
echo "Installing pandoras-box"
sudo git clone --branch optimizations https://github.com/Ethernal-Tech/pandoras-box /opt/pandoras-box
cd /opt/pandoras-box && sudo yarn && sudo yarn build && sudo yarn link
sudo chmod 0777 /usr/local/bin/pandoras-box
sudo chown ubuntu:ubuntu /usr/local/bin/pandoras-box
7 changes: 7 additions & 0 deletions packer/load-test/scripts/polycli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash -e
echo "Installing polycli"
sudo wget https://github.com/maticnetwork/polygon-cli/releases/download/v${POLYCLI_TAG}/polycli_${POLYCLI_TAG}_linux_amd64.tar.gz -O /opt/polycli_${POLYCLI_TAG}_linux_amd64.tar.gz
sudo chmod 0600 /opt/polycli_${POLYCLI_TAG}_linux_amd64.tar.gz
sudo tar -C /opt/ -xzf /opt/polycli_${POLYCLI_TAG}_linux_amd64.tar.gz
sudo ln -s /opt/polycli_${POLYCLI_TAG}_linux_amd64/polycli /usr/local/bin/polycli
sudo rm -rf /opt/polycli_${POLYCLI_TAG}_linux_amd64.tar.gz
26 changes: 26 additions & 0 deletions packer/load-test/scripts/verify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash -e
echo "make version: `make --version`"
echo "jq version: `jq -V`"
echo "forge version: `forge -V`"
echo "cast version: `cast -V`"
echo "golang version: `go version`"
echo "polycli version: `polycli version`"
echo "k6 version: `k6 version`"
set +e
xk6_version=$(xk6 version 2>&1)
set -e
if ( echo "$xk6_version" | grep -q "go.mod file not found" ); then
echo "xk6 succeeded"
else
echo "xk6 failed"
fi
xk6_ethereum_output=$(ls /home/ubuntu | grep -w "k6" | wc -l)
if [ $xk6_ethereum_output -eq 1 ]; then
echo "xk6-ethereum build succeeded";
else
echo "xk6-ethereum build failed"
fi
echo "npm version: `npm -v`"
echo "yarn version: `yarn --version`"
echo "pandoras-box branch: `cd /opt/pandoras-box && sudo git branch --show-current`"
echo "pandoras-box version: `pandoras-box -V`"
3 changes: 3 additions & 0 deletions packer/load-test/scripts/xk6-ethereum.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash -e
echo "Building xk6-ethereum"
xk6 build --with github.com/distribworks/[email protected] --output /home/ubuntu/k6
5 changes: 5 additions & 0 deletions packer/load-test/scripts/xk6.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash -e
echo "Installing xk6"
go install go.k6.io/xk6/cmd/xk6@latest
sudo cp /root/go/bin/xk6 /usr/local/
sudo ln -s /usr/local/xk6 /usr/local/bin/xk6
2 changes: 2 additions & 0 deletions packer/load-test/scripts/yarn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
echo "Installing yarn"
sudo npm install --global yarn