From 495352e6d91a6fccc2dc13344084a18e3b0a6609 Mon Sep 17 00:00:00 2001 From: Emily Lim Date: Mon, 9 Oct 2023 23:10:42 -0700 Subject: [PATCH 01/11] Add Terraform configuration file File contains configuration needed for Terraform to an EC2 t2.micro instance --- terraform/main.tf | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 terraform/main.tf diff --git a/terraform/main.tf b/terraform/main.tf new file mode 100644 index 00000000000..0b9e71c1d8b --- /dev/null +++ b/terraform/main.tf @@ -0,0 +1,23 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 4.16" + } + } + + required_version = ">= 1.2.0" +} + +provider "aws" { + region = "us-west-2" +} + +resource "aws_instance" "app_server" { + ami = "ami-830c94e3" + instance_type = "t2.micro" + + tags = { + Name = "ExampleAppServerInstance" + } +} From 0cafb549282b3eeff01cf466f61e0a292eede9fe Mon Sep 17 00:00:00 2001 From: Emily Lim Date: Tue, 10 Oct 2023 18:25:32 -0700 Subject: [PATCH 02/11] Add sensitive Terraform files to .gitignore Include Terraform state files, directories, and logs in .gitignore. Format Terraform configuration. --- .gitignore | 15 +++++++++++++++ terraform/main.tf | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d32231d1abc..2af15e6a08c 100644 --- a/.gitignore +++ b/.gitignore @@ -168,3 +168,18 @@ pyembed_includes .cache/ build_cinderx_venv/ CinderX/build/ + +# Ignore Terraform state files, directories, and logs +*.tfstate +*.tfstate.* +*.terraform +*.terraform.* +.terraform/ +terraform.log + +# Ignore sensitive or auto-generated files +*.pem +*.key +*.tfvars +*.tfvars.* + diff --git a/terraform/main.tf b/terraform/main.tf index 0b9e71c1d8b..e2621f05e1f 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -10,7 +10,7 @@ terraform { } provider "aws" { - region = "us-west-2" + region = "us-west-2" } resource "aws_instance" "app_server" { From 42e2cabdf8ca3edde0ef6f59dc5c7726f59273e4 Mon Sep 17 00:00:00 2001 From: Emily Lim Date: Tue, 10 Oct 2023 18:36:24 -0700 Subject: [PATCH 03/11] Update .gitignore to exclude sensitive Terraform files --- .gitignore | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.gitignore b/.gitignore index d32231d1abc..2af15e6a08c 100644 --- a/.gitignore +++ b/.gitignore @@ -168,3 +168,18 @@ pyembed_includes .cache/ build_cinderx_venv/ CinderX/build/ + +# Ignore Terraform state files, directories, and logs +*.tfstate +*.tfstate.* +*.terraform +*.terraform.* +.terraform/ +terraform.log + +# Ignore sensitive or auto-generated files +*.pem +*.key +*.tfvars +*.tfvars.* + From 09f2cc94307af6625fabbd0e752ced90cd4e07d5 Mon Sep 17 00:00:00 2001 From: Emily Lim Date: Wed, 11 Oct 2023 12:02:26 -0700 Subject: [PATCH 04/11] Add workflow and configuration files for Actions Add requirements.txt to create the new files. Update .gitignore to ignore venv files. --- .github/workflows/_generate.yml | 45 +++++++++++++++++++++++++++++ .github/workflows/_publish.yml | 50 +++++++++++++++++++++++++++++++++ .gitignore | 3 ++ requirements.txt | 1 + 4 files changed, 99 insertions(+) create mode 100644 .github/workflows/_generate.yml create mode 100644 .github/workflows/_publish.yml create mode 100644 requirements.txt diff --git a/.github/workflows/_generate.yml b/.github/workflows/_generate.yml new file mode 100644 index 00000000000..e9aeec6b3a7 --- /dev/null +++ b/.github/workflows/_generate.yml @@ -0,0 +1,45 @@ +--- +name: _generate + +"on": + workflow_call: + inputs: + force: + type: boolean + default: false + dry_run: + type: boolean + default: false + + workflow_dispatch: + inputs: + force: + description: "Regenerate all of the derived data, even if it already exists" + type: boolean + default: false + dry_run: + description: "Dry run: Do not commit to the repo" + type: boolean + default: false + +jobs: + generate-results: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: '3.11' + cache: pip + - name: install dependencies + run: + python -m pip install -r requirements.txt + - name: regenerate + run: + python -m bench_runner.scripts.generate_results ${{ inputs.force == true && '--force' || '' }} + - name: Add to repo + uses: EndBug/add-and-commit@v9 + if: ${{ !inputs.dry_run }} + with: + add: "['results', 'README.md', 'RESULTS.md', 'longitudinal.png', 'profiling/profiling.png', 'profiling/profiling.md']" + message: Benchmarking results for @${{ github.actor }} diff --git a/.github/workflows/_publish.yml b/.github/workflows/_publish.yml new file mode 100644 index 00000000000..d46d1f5b8ca --- /dev/null +++ b/.github/workflows/_publish.yml @@ -0,0 +1,50 @@ +--- +name: _publish + +"on": + workflow_call: + inputs: + force: + type: boolean + default: false + dry_run: + type: boolean + default: false + + workflow_dispatch: + inputs: + force: + description: "Regenerate all of the derived data, even if it already exists" + type: boolean + default: false + dry_run: + description: "Dry run: Do not commit to the repo" + type: boolean + default: false + +jobs: + mirror: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + path: private + ref: main + fetch-depth: 0 + - uses: actions/checkout@v3 + with: + path: public + ref: main + repository: faster-cpython/benchmarking-public + token: ${{ secrets.BENCHMARK_MIRROR }} + - name: Mirror + run: | + cd public + git remote add upstream $PWD/../private + git fetch upstream + git reset --hard upstream/main + - name: Push + if: ${{ !inputs.dry_run }} + run: | + cd public + git push origin main diff --git a/.gitignore b/.gitignore index 2af15e6a08c..0aa50c34f8d 100644 --- a/.gitignore +++ b/.gitignore @@ -183,3 +183,6 @@ terraform.log *.tfvars *.tfvars.* +# Ignore venv directory +venv/ + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000000..fadb5fcc0f9 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +git+https://github.com/faster-cpython/bench_runner@v0.2.2#egg=bench_runner From 7d9d788972504648b3705090c45b9c87cc121d24 Mon Sep 17 00:00:00 2001 From: Emily Lim Date: Tue, 17 Oct 2023 13:21:24 -0700 Subject: [PATCH 05/11] Add workflow file with AWS configuration Workflow file to be updated with steps to deploy benchrunner --- .github/workflows/benchrunner-aws.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/benchrunner-aws.yml diff --git a/.github/workflows/benchrunner-aws.yml b/.github/workflows/benchrunner-aws.yml new file mode 100644 index 00000000000..19cade70cde --- /dev/null +++ b/.github/workflows/benchrunner-aws.yml @@ -0,0 +1,19 @@ +name: Deploy benchrunner to AWS + +on: + workflow_dispatch: {} + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Check out the repository to the runner + uses: actions/checkout@v4 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-west-2 From 96301c2941c3972465235124eccd9a7b74037b2a Mon Sep 17 00:00:00 2001 From: Emily Lim Date: Mon, 23 Oct 2023 13:02:27 -0700 Subject: [PATCH 06/11] Add Terraform to workflow to start EC2 instance --- .github/workflows/benchrunner-aws.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/benchrunner-aws.yml b/.github/workflows/benchrunner-aws.yml index 19cade70cde..b1a39475a69 100644 --- a/.github/workflows/benchrunner-aws.yml +++ b/.github/workflows/benchrunner-aws.yml @@ -17,3 +17,13 @@ jobs: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: us-west-2 + + - name: Set Up Terraform + uses: hashicorp/setup-terraform@v2 + + - name: Start EC2 instance Using Terraform Configuration + run: | + cd terraform + terraform init + terraform apply -auto-approve + From 0fa566c934b761c0fa457b899a2f076d3ea18b52 Mon Sep 17 00:00:00 2001 From: Emily Lim Date: Mon, 23 Oct 2023 13:19:40 -0700 Subject: [PATCH 07/11] Update workflow to run on push Workflow will run on push instead of manually. --- .github/workflows/benchrunner-aws.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchrunner-aws.yml b/.github/workflows/benchrunner-aws.yml index b1a39475a69..555fe3c171e 100644 --- a/.github/workflows/benchrunner-aws.yml +++ b/.github/workflows/benchrunner-aws.yml @@ -1,7 +1,7 @@ name: Deploy benchrunner to AWS on: - workflow_dispatch: {} + [push] jobs: deploy: From b439df38c79c779d4d0aa2c904fe3f3ca3788c9f Mon Sep 17 00:00:00 2001 From: Emily Lim Date: Tue, 24 Oct 2023 19:24:39 -0700 Subject: [PATCH 08/11] Update Terraform configuration for SSH Add key pair for SSH access to instance. Add resources for traffic rules. --- terraform/main.tf | 78 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 74 insertions(+), 4 deletions(-) diff --git a/terraform/main.tf b/terraform/main.tf index e2621f05e1f..b366fd781a3 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -13,11 +13,81 @@ provider "aws" { region = "us-west-2" } -resource "aws_instance" "app_server" { - ami = "ami-830c94e3" - instance_type = "t2.micro" +resource "aws_vpc" "bench_run" { + cidr_block = "10.0.0.0/16" + enable_dns_hostnames = true + enable_dns_support = true tags = { - Name = "ExampleAppServerInstance" + Name = "bench_run" } } + +resource "aws_eip" "bench_run_ip" { + instance = aws_instance.bench_runner.id + vpc = true +} + +resource "aws_internet_gateway" "bench_run_gw" { + vpc_id = aws_vpc.bench_run.id + + tags = { + Name = "bench_run_gw" + } +} + +resource "aws_subnet" "subnet1" { + cidr_block = cidrsubnet(aws_vpc.bench_run.cidr_block, 3, 1) + vpc_id = aws_vpc.bench_run.id + availability_zone = "us-west-2a" +} + +resource "aws_route_table" "bench_run_route_table" { + vpc_id = aws_vpc.bench_run.id + + route { + cidr_block = "0.0.0.0/0" + gateway_id = aws_internet_gateway.bench_run_gw.id + } + + tags = { + Name = "bench_run_route_table" + } +} + +resource "aws_route_table_association" "subnet_association" { + subnet_id = aws_subnet.subnet1.id + route_table_id = aws_route_table.bench_run_route_table.id +} + +resource "aws_security_group" "ingress_all" { + name = "allow_all_sg" + vpc_id = aws_vpc.bench_run.id + + ingress { + cidr_blocks = ["0.0.0.0/0"] + from_port = 22 + to_port = 22 + protocol = "tcp" + } + + egress { + cidr_blocks = ["0.0.0.0/0"] + from_port = 0 + to_port = 0 + protocol = "-1" + } +} + +resource "aws_instance" "bench_runner" { + ami = "ami-830c94e3" + instance_type = "t2.micro" + key_name = "bench-runner" + vpc_security_group_ids = ["${aws_security_group.ingress_all.id}"] + subnet_id = aws_subnet.subnet1.id + + tags = { + Name = "BenchmarkingEC2Runner" + } +} + From 99b78b56a3b054366861b77285cd1ec104e886a4 Mon Sep 17 00:00:00 2001 From: Emily Lim Date: Wed, 25 Oct 2023 18:56:12 -0700 Subject: [PATCH 09/11] Add key pair resource in Terraform configuration Existing key pair referenced in a separate resource instead of directly in instance resource. --- terraform/main.tf | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/terraform/main.tf b/terraform/main.tf index b366fd781a3..73a6f75f10c 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -79,10 +79,15 @@ resource "aws_security_group" "ingress_all" { } } +resource "aws_key_pair" "benchrun_keypair" { + key_name = "bench-runner" + public_key = file("~/.ssh/id_rsa.pub") +} + resource "aws_instance" "bench_runner" { ami = "ami-830c94e3" instance_type = "t2.micro" - key_name = "bench-runner" + key_name = aws_key_pair.benchrun_keypair.key_name vpc_security_group_ids = ["${aws_security_group.ingress_all.id}"] subnet_id = aws_subnet.subnet1.id From 2c57cf32b97b55ac11cbb2bf3e3394a92ec64e74 Mon Sep 17 00:00:00 2001 From: Emily Lim Date: Wed, 25 Oct 2023 19:19:29 -0700 Subject: [PATCH 10/11] Remove key pair resource Key pair resource does not match with how SSH key is created. --- terraform/main.tf | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/terraform/main.tf b/terraform/main.tf index 73a6f75f10c..b366fd781a3 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -79,15 +79,10 @@ resource "aws_security_group" "ingress_all" { } } -resource "aws_key_pair" "benchrun_keypair" { - key_name = "bench-runner" - public_key = file("~/.ssh/id_rsa.pub") -} - resource "aws_instance" "bench_runner" { ami = "ami-830c94e3" instance_type = "t2.micro" - key_name = aws_key_pair.benchrun_keypair.key_name + key_name = "bench-runner" vpc_security_group_ids = ["${aws_security_group.ingress_all.id}"] subnet_id = aws_subnet.subnet1.id From 90c0c0a969c158e885b817085159a30ef9f75fbd Mon Sep 17 00:00:00 2001 From: Emily Lim Date: Thu, 2 Nov 2023 19:33:29 -0700 Subject: [PATCH 11/11] Update Terraform configuration to add user data During initialization, a test script is run. Update workflow. --- .github/workflows/benchrunner-aws.yml | 5 ++++- terraform/init.sh | 3 +++ terraform/main.tf | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 terraform/init.sh diff --git a/.github/workflows/benchrunner-aws.yml b/.github/workflows/benchrunner-aws.yml index 555fe3c171e..f24bde37814 100644 --- a/.github/workflows/benchrunner-aws.yml +++ b/.github/workflows/benchrunner-aws.yml @@ -1,7 +1,10 @@ name: Deploy benchrunner to AWS on: - [push] + push: + branches: + - main + workflow_dispatch: {} jobs: deploy: diff --git a/terraform/init.sh b/terraform/init.sh new file mode 100644 index 00000000000..0bb36a27881 --- /dev/null +++ b/terraform/init.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "This is a test file was created during the instance initialization." > test.txt diff --git a/terraform/main.tf b/terraform/main.tf index b366fd781a3..b170d9ce618 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -85,6 +85,7 @@ resource "aws_instance" "bench_runner" { key_name = "bench-runner" vpc_security_group_ids = ["${aws_security_group.ingress_all.id}"] subnet_id = aws_subnet.subnet1.id + user_data = file("init.sh") tags = { Name = "BenchmarkingEC2Runner"