mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-10-06 10:57:51 +00:00
CICD: fix Cleanup_Build_Job inconsistent failures (#2098)
* add aws profile to cleanup job * Split cleanup into bash script * change spot instances to one-tme
This commit is contained in:
parent
9e17579a76
commit
b7516eacc5
3 changed files with 52 additions and 5 deletions
|
|
@ -975,12 +975,20 @@ s3 dump plg tag:
|
|||
|
||||
cleanup_build_job:
|
||||
stage: cleanup_build
|
||||
image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest
|
||||
variables:
|
||||
FBCI_PROFILE: "service-terraform"
|
||||
AWS_ACCESS_KEY_ID: $AWS_FBCI_ACCESS_KEY_ID
|
||||
AWS_SECRET_ACCESS_KEY: $AWS_FBCI_SECRET_ACCESS_KEY
|
||||
tags:
|
||||
- shell
|
||||
- aws
|
||||
- docker
|
||||
- fbsmoke
|
||||
script:
|
||||
- CLEANUP_EC2_IDS=$(aws ec2 describe-instances --region us-east-2 --filters Name=instance-state-name,Values=pending,running "Name=tag:Name,Values=pipeline-${CI_PIPELINE_ID}-*" --query 'Reservations[*].Instances[*].[InstanceId]' --output text | tr '\n' ' ')
|
||||
- '[[ ! -z "$CLEANUP_EC2_IDS" ]] && aws ec2 terminate-instances --region us-east-2 --instance-ids $CLEANUP_IDS || echo "No instances to cleanup"'
|
||||
- CLEANUP_CF_ID=$(aws cloudformation list-stacks --region us-east-2 --stack-status-filter CREATE_IN_PROGRESS CREATE_COMPLETE --query "StackSummaries[?contains(StackName, \`pipeline-${CI_PIPELINE_ID}\`) == \`true\`].[StackName]" --output text )
|
||||
- '[[ ! -z "$CLEANUP_CF_ID" ]] && aws cloudformation delete-stack --region us-east-2 --stack-name $CLEANUP_CF_ID --retain-resources DeploymentEC2Role || echo "No CF stack to cleanup"'
|
||||
- aws configure set aws_access_key_id $AWS_FBCI_ACCESS_KEY_ID --profile $FBCI_PROFILE
|
||||
- aws configure set aws_secret_access_key $AWS_FBCI_SECRET_ACCESS_KEY --profile $FBCI_PROFILE
|
||||
- aws configure set region "us-east-2" --profile $FBCI_PROFILE
|
||||
- aws configure set aws_profile $FBCI_PROFILE
|
||||
- ./qa/scripts/gitlabCleanupBuild.sh
|
||||
when: always
|
||||
|
||||
|
|
|
|||
37
qa/scripts/gitlabCleanupBuild.sh
Executable file
37
qa/scripts/gitlabCleanupBuild.sh
Executable file
|
|
@ -0,0 +1,37 @@
|
|||
#!/bin/bash
|
||||
|
||||
CLEANUP_EC2_IDS=$(aws ec2 describe-instances --profile service-terraform --region us-east-2 --filters Name=instance-state-name,Values=pending,running "Name=tag:Name,Values=pipeline-${CI_PIPELINE_ID}-*" --query 'Reservations[*].Instances[*].[InstanceId]' --output text | tr '\n' ' ')
|
||||
if [ -n "${CLEANUP_EC2_IDS}" ]
|
||||
then
|
||||
echo "ec2 Instances found, terminating."
|
||||
echo $CLEANUP_EC2_IDS
|
||||
IFS=', ' read -r -a array <<< "$CLEANUP_EC2_IDS"
|
||||
aws ec2 terminate-instances --profile service-terraform --region us-east-2 --instance-ids "${array[@]}"
|
||||
|
||||
res=$?
|
||||
if (( $res != 0 )); then
|
||||
echo "Error: instances not terminated - ${CLEANUP_EC2_IDS}"
|
||||
exit $res
|
||||
fi
|
||||
else
|
||||
echo 'No hanging ec2 instances'
|
||||
fi
|
||||
|
||||
CLEANUP_CF_ID=$(aws cloudformation list-stacks --region us-east-2 --stack-status-filter CREATE_IN_PROGRESS CREATE_COMPLETE --query "StackSummaries[?contains(StackName, \`pipeline-${CI_PIPELINE_ID}\`) == \`true\`].[StackName]" --output text | tr '\n' ' ')
|
||||
if [ -n "${CLEANUP_CF_ID}" ]
|
||||
then
|
||||
echo "CF stacks found, deleting."
|
||||
echo $CLEANUP_CF_ID
|
||||
IFS=', ' read -r -a array <<< "$CLEANUP_CF_ID"
|
||||
for element in "${array[@]}"
|
||||
do
|
||||
aws cloudformation delete-stack --region us-east-2 --stack-name $element --retain-resources DeploymentEC2Role
|
||||
res=$?
|
||||
if (( $res != 0 )); then
|
||||
echo "Error: stacks not deleted - ${CLEANUP_CF_ID}"
|
||||
exit $res
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "No CF stacks to cleanup"
|
||||
fi
|
||||
|
|
@ -86,6 +86,7 @@ resource "aws_instance" "fb_ingest" {
|
|||
}
|
||||
resource "aws_spot_instance_request" "fb_cluster_nodes" {
|
||||
wait_for_fulfillment = true
|
||||
spot_type = "one-time"
|
||||
count = var.use_spot_instances ? var.fb_data_node_count : 0
|
||||
ami = data.aws_ami.amazon_linux_2.id
|
||||
instance_type = var.fb_data_node_type
|
||||
|
|
@ -127,6 +128,7 @@ resource "aws_spot_instance_request" "fb_cluster_nodes" {
|
|||
|
||||
resource "aws_spot_instance_request" "fb_ingest" {
|
||||
wait_for_fulfillment = true
|
||||
spot_type = "one-time"
|
||||
count = var.use_spot_instances ? var.fb_ingest_node_count : 0
|
||||
ami = data.aws_ami.amazon_linux_2.id
|
||||
key_name = aws_key_pair.gitlab-featurebase-ci.key_name
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue