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

ci:stopping instances #159

Open
wants to merge 4 commits into
base: main
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 .github/workflows/run_e2e_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 PRE_RELEASE_NAME=${{ inputs.gh_release_name }}"
secrets: inherit
2 changes: 1 addition & 1 deletion terraform/ec2-instances-creator/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions terraform/ec2-instances-creator/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
22 changes: 22 additions & 0 deletions terraform/ec2-test-executors/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,25 @@ 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}"
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}'
1 change: 1 addition & 0 deletions terraform/ec2-test-executors/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
4 changes: 4 additions & 0 deletions terraform/ec2-test-executors/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions versions/amazonlinux_2023.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
osDistro: amazonlinux
osVersion: 2023
packages:
- arch: x86_64
ami: ami-01103fb68b3569475
# - arch: x86_64
# ami: ami-01103fb68b3569475
- arch: aarch64
ami: ami-0b9df99d3514cdede
3 changes: 2 additions & 1 deletion versions/strategyMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading