Skip to content

Commit

Permalink
Merge pull request #314 from buildkite/reduce-ci-costs
Browse files Browse the repository at this point in the history
Reduce ci costs
  • Loading branch information
lox authored Jul 14, 2017
2 parents a69bff7 + b5da0c1 commit 9d7da6a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
38 changes: 35 additions & 3 deletions .buildkite/steps/cleanup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
#!/bin/bash
set -eu
# shellcheck disable=SC2016
set -uo pipefail

echo "--- Deleting stack $AWS_STACK_NAME"
aws cloudformation delete-stack --stack-name "$AWS_STACK_NAME"
if [[ $OSTYPE =~ ^darwin ]] ; then
cutoff_date=$(gdate --date='-2 days' +%Y-%m-%d)
else
cutoff_date=$(date --date='-2 days' +%Y-%m-%d)
fi

if [[ -n "${AWS_STACK_NAME:-}" ]] ; then
echo "--- Deleting stack $AWS_STACK_NAME"
aws cloudformation delete-stack --stack-name "$AWS_STACK_NAME"
fi

echo "--- Deleting test managed secrets buckets created"
aws s3api list-buckets \
--output text \
--query "$(printf 'Buckets[?CreationDate<`%s`].Name' "$cutoff_date" )" \
| xargs -n1 \
| grep -E 'buildkite-aws-stack-test-managedsecrets' \
| xargs -n1 -t -I% aws s3 rb s3://% --force

echo "--- Deleting old cloudformation stacks"
aws cloudformation describe-stacks \
--output text \
--query "$(printf 'Stacks[?CreationTime<`%s`].StackName' "$cutoff_date" )" \
| xargs -n1 \
| grep -E 'buildkite-aws-stack-test-\d+' \
| xargs -n1 -t -I% aws cloudformation delete-stack --stack-name "%"

echo "--- Deleting old packer builders"
aws ec2 describe-instances \
--filters "Name=tag:Name,Values=Packer Builder" \
--query "$(printf 'Reservations[].Instances[?LaunchTime<`%s`].InstanceId' "$cutoff_date")" \
--output text \
| xargs -n1 -t -I% aws ec2 terminate-instances --instance-ids "%"
5 changes: 5 additions & 0 deletions .buildkite/steps/test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# shellcheck disable=SC1117
set -eu

vpc_id=$(aws ec2 describe-vpcs --filters "Name=isDefault,Values=true" --query "Vpcs[0].VpcId" --output text)
Expand Down Expand Up @@ -58,6 +59,10 @@ cat << EOF > config.json
{
"ParameterKey": "ECRAccessPolicy",
"ParameterValue": "readonly"
},
{
"ParameterKey": "RootVolumeSize",
"ParameterValue": "10"
}
]
EOF
Expand Down
4 changes: 3 additions & 1 deletion packer/buildkite-ami.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"type": "amazon-ebs",
"region": "us-east-1",
"source_ami": "ami-643b1972",
"instance_type": "c4.large",
"instance_type": "i3.large",
"spot_price": "auto",
"spot_price_auto_product": "Linux/UNIX (Amazon VPC)",
"ssh_username": "ec2-user",
"ami_name": "buildkite-stack-{{isotime | clean_ami_name}}",
"ami_description": "Buildkite CloudFormation Stack base image (Amazon Linux, buildkite-agent, docker, docker-compose, docker-gc, jq)",
Expand Down
2 changes: 1 addition & 1 deletion plugins/ecr
Submodule ecr updated from b5ea37 to 02c9f8

0 comments on commit 9d7da6a

Please sign in to comment.