From 214527de4d8145c026208f63078d2746214e35d6 Mon Sep 17 00:00:00 2001 From: voorepreethi Date: Mon, 16 Sep 2024 23:36:15 +0530 Subject: [PATCH 1/4] ci:stopping instances --- .github/workflows/run_e2e_tests.yml | 2 +- terraform/ec2-test-executors/Makefile | 13 +++++++++++++ versions/amazonlinux_2023.yml | 4 ++-- versions/strategyMatrix.py | 3 ++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.github/workflows/run_e2e_tests.yml b/.github/workflows/run_e2e_tests.yml index ff0bca00..feb8e6e0 100644 --- a/.github/workflows/run_e2e_tests.yml +++ b/.github/workflows/run_e2e_tests.yml @@ -102,5 +102,5 @@ jobs: needs: report_test_results uses: ./.github/workflows/run_task.yml with: - container_make_target: "terraform/ec2-test-executors/clean PRE_RELEASE_NAME=${{ inputs.gh_release_name }}" + container_make_target: "terraform/ec2-test-executors/stop" secrets: inherit diff --git a/terraform/ec2-test-executors/Makefile b/terraform/ec2-test-executors/Makefile index 0457facb..d54237fb 100644 --- a/terraform/ec2-test-executors/Makefile +++ b/terraform/ec2-test-executors/Makefile @@ -29,3 +29,16 @@ clean: backend vars generateMatrices terraform destroy -auto-approve -var-file="variables.tfvars" @echo "Removing Terraform backend file ${TERRAFORM_PROJECT}/terraform.backend.tf" @rm "./terraform.backend.tf" + +# Terraform-stop +.PHONY: stop +stop: backend vars generateMatrices + @echo "Stopping instances for ${TERRAFORM_PROJECT}" + @instance_ids=$(shell aws ec2 describe-instances --filters "Name=tag:product,Values=logging" --query "Reservations[*].Instances[?State.Name=='running'].InstanceId" --output text) && \ + echo "Found instance IDs: $$instance_ids" && \ + if [ -n "$$instance_ids" ]; then \ + echo "Stopping instances: $$instance_ids"; \ + aws ec2 stop-instances --instance-ids $$instance_ids; \ + else \ + echo "No running instances found to stop."; \ + fi \ No newline at end of file diff --git a/versions/amazonlinux_2023.yml b/versions/amazonlinux_2023.yml index a3ccad56..a3b7ebab 100644 --- a/versions/amazonlinux_2023.yml +++ b/versions/amazonlinux_2023.yml @@ -3,5 +3,5 @@ osVersion: 2023 packages: - arch: x86_64 ami: ami-01103fb68b3569475 - - arch: aarch64 - ami: ami-0b9df99d3514cdede + # - arch: aarch64 + # ami: ami-0b9df99d3514cdede diff --git a/versions/strategyMatrix.py b/versions/strategyMatrix.py index 4e4f47e8..42d27853 100644 --- a/versions/strategyMatrix.py +++ b/versions/strategyMatrix.py @@ -186,7 +186,8 @@ def list_distro_files(): return [ filename for filename in os.listdir(".") - if (filename.endswith(".yml") or filename.endswith(".yaml")) + # if (filename.endswith(".yml") or filename.endswith(".yaml")) + if (filename.endswith("amazonlinux_2023.yml")) and filename != "common.yml" ] except Exception as e: From 7e4b5ba4386bd6cbd9466574e2983c1bde389dd6 Mon Sep 17 00:00:00 2001 From: voorepreethi Date: Tue, 17 Sep 2024 16:25:32 +0530 Subject: [PATCH 2/4] added release name --- .github/workflows/run_e2e_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run_e2e_tests.yml b/.github/workflows/run_e2e_tests.yml index feb8e6e0..c3b9d881 100644 --- a/.github/workflows/run_e2e_tests.yml +++ b/.github/workflows/run_e2e_tests.yml @@ -102,5 +102,5 @@ jobs: needs: report_test_results uses: ./.github/workflows/run_task.yml with: - container_make_target: "terraform/ec2-test-executors/stop" + container_make_target: "terraform/ec2-test-executors/stop PRE_RELEASE_NAME=${{ inputs.gh_release_name }}" secrets: inherit From 1d7abf1f6c3196a567b31cde7532f545056ab696 Mon Sep 17 00:00:00 2001 From: voorepreethi Date: Tue, 17 Sep 2024 16:42:15 +0530 Subject: [PATCH 3/4] changed tag to prerelease name to pull the running instances --- terraform/ec2-test-executors/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/ec2-test-executors/Makefile b/terraform/ec2-test-executors/Makefile index d54237fb..c7bd5815 100644 --- a/terraform/ec2-test-executors/Makefile +++ b/terraform/ec2-test-executors/Makefile @@ -34,7 +34,7 @@ clean: backend vars generateMatrices .PHONY: stop stop: backend vars generateMatrices @echo "Stopping instances for ${TERRAFORM_PROJECT}" - @instance_ids=$(shell aws ec2 describe-instances --filters "Name=tag:product,Values=logging" --query "Reservations[*].Instances[?State.Name=='running'].InstanceId" --output text) && \ + @instance_ids=$(shell aws ec2 describe-instances --filters "Name=tag:pre_release_name,Values=$${PRE_RELEASE_NAME}" --query "Reservations[*].Instances[?State.Name=='running'].InstanceId" --output text) && \ echo "Found instance IDs: $$instance_ids" && \ if [ -n "$$instance_ids" ]; then \ echo "Stopping instances: $$instance_ids"; \ From 5434b15bff160ec8558e06ccb9eaa99ac1c34ce2 Mon Sep 17 00:00:00 2001 From: voorepreethi Date: Tue, 17 Sep 2024 17:29:20 +0530 Subject: [PATCH 4/4] changed to terraform --- terraform/ec2-instances-creator/main.tf | 2 +- terraform/ec2-instances-creator/variables.tf | 5 ++++ terraform/ec2-test-executors/Makefile | 25 +++++++++++++------- terraform/ec2-test-executors/main.tf | 1 + terraform/ec2-test-executors/variables.tf | 4 ++++ versions/amazonlinux_2023.yml | 8 +++---- 6 files changed, 32 insertions(+), 13 deletions(-) diff --git a/terraform/ec2-instances-creator/main.tf b/terraform/ec2-instances-creator/main.tf index 8311ea53..8fcfd12c 100644 --- a/terraform/ec2-instances-creator/main.tf +++ b/terraform/ec2-instances-creator/main.tf @@ -36,7 +36,7 @@ locals { module "ec2_instance" { source = "terraform-aws-modules/ec2-instance/aws" - for_each = { for pkg in local.instance_matrix : "${var.pre_release_name}-${pkg.osDistro}-${pkg.osVersion}-${pkg.arch}-fb-${pkg.fbVersion}-${var.instance_type}" => pkg } + for_each = { for pkg in local.instance_matrix : "${var.pre_release_name}-${pkg.osDistro}-${pkg.osVersion}-${pkg.arch}-fb-${pkg.fbVersion}-${var.instance_type}" => pkg if var.instance_count > 0 } name = each.key diff --git a/terraform/ec2-instances-creator/variables.tf b/terraform/ec2-instances-creator/variables.tf index 255f6dc8..5518d8a5 100644 --- a/terraform/ec2-instances-creator/variables.tf +++ b/terraform/ec2-instances-creator/variables.tf @@ -11,4 +11,9 @@ variable "pre_release_name" { variable "instance_type" { type = string description = "Indicates what the created EC2 instances are for. Examples: 'fluentbit-tester', 'fluentbit-builder'. This is later used by the Ansible dynamic inventory (see ansible/build-fb-suse/aws_ec2.yml.dist) to filter out the instances based on their type." +} + + +variable "instance_count" { + default = 1 } \ No newline at end of file diff --git a/terraform/ec2-test-executors/Makefile b/terraform/ec2-test-executors/Makefile index c7bd5815..ec7304f2 100644 --- a/terraform/ec2-test-executors/Makefile +++ b/terraform/ec2-test-executors/Makefile @@ -34,11 +34,20 @@ clean: backend vars generateMatrices .PHONY: stop stop: backend vars generateMatrices @echo "Stopping instances for ${TERRAFORM_PROJECT}" - @instance_ids=$(shell aws ec2 describe-instances --filters "Name=tag:pre_release_name,Values=$${PRE_RELEASE_NAME}" --query "Reservations[*].Instances[?State.Name=='running'].InstanceId" --output text) && \ - echo "Found instance IDs: $$instance_ids" && \ - if [ -n "$$instance_ids" ]; then \ - echo "Stopping instances: $$instance_ids"; \ - aws ec2 stop-instances --instance-ids $$instance_ids; \ - else \ - echo "No running instances found to stop."; \ - fi \ No newline at end of file + terraform init -reconfigure && \ + terraform apply -auto-approve -var 'instance_count=0' -var 'pre_release_name=${PRE_RELEASE_NAME}' +# @instance_ids=$(shell aws ec2 describe-instances --filters "Name=tag:pre_release_name,Values=$${PRE_RELEASE_NAME}" --query "Reservations[*].Instances[?State.Name=='running'].InstanceId" --output text) && \ +# echo "Found instance IDs: $$instance_ids" && \ +# if [ -n "$$instance_ids" ]; then \ +# echo "Stopping instances: $$instance_ids"; \ +# aws ec2 stop-instances --instance-ids $$instance_ids; \ +# else \ +# echo "No running instances found to stop."; \ +# fi + + + +# .PHONY: stop +# stop: backend vars generateMatrices +# @echo "Stopping instances for ${TERRAFORM_PROJECT}" +# terraform apply -auto-approve -var 'instance_count=0' -var 'pre_release_name=${PRE_RELEASE_NAME}' \ No newline at end of file diff --git a/terraform/ec2-test-executors/main.tf b/terraform/ec2-test-executors/main.tf index cbc96542..806d8d7f 100644 --- a/terraform/ec2-test-executors/main.tf +++ b/terraform/ec2-test-executors/main.tf @@ -18,5 +18,6 @@ module "test-executor-instances" { instance_matrix_file = local.to_use_matrix pre_release_name = var.pre_release_name + instance_count = var.instance_count instance_type = "test-executor" } \ No newline at end of file diff --git a/terraform/ec2-test-executors/variables.tf b/terraform/ec2-test-executors/variables.tf index 39df10a8..e1438245 100644 --- a/terraform/ec2-test-executors/variables.tf +++ b/terraform/ec2-test-executors/variables.tf @@ -8,3 +8,7 @@ variable "matrix" { description = "Two values; prerelease or all. Prerelease will spin up instances for which we are processing packages. All will spin up all supported instances." default = "prerelease" } + +variable "instance_count" { + default = 1 +} \ No newline at end of file diff --git a/versions/amazonlinux_2023.yml b/versions/amazonlinux_2023.yml index a3b7ebab..f8cf0b40 100644 --- a/versions/amazonlinux_2023.yml +++ b/versions/amazonlinux_2023.yml @@ -1,7 +1,7 @@ osDistro: amazonlinux osVersion: 2023 packages: - - arch: x86_64 - ami: ami-01103fb68b3569475 - # - arch: aarch64 - # ami: ami-0b9df99d3514cdede + # - arch: x86_64 + # ami: ami-01103fb68b3569475 + - arch: aarch64 + ami: ami-0b9df99d3514cdede