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

Pre Launch #12

Merged
merged 49 commits into from
Jan 20, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
e8ef987
Add a VPC Cloudformation template
vladgh Jan 14, 2016
516be5c
Add security groups cloudformation template
vladgh Jan 14, 2016
c3f0bd1
Update README
vladgh Jan 15, 2016
148eced
Fix alignment
vladgh Jan 15, 2016
a009409
Update modules
vladgh Jan 15, 2016
a9b4f10
Improve bootstrap
vladgh Jan 16, 2016
105115c
Add puppet color support in the bootstrap script
vladgh Jan 17, 2016
afa071a
Add AWS IAM cloudformation template
vladgh Jan 17, 2016
c665520
Validate Cloudformation templates when committing
vladgh Jan 17, 2016
fcf83c9
Minor change
vladgh Jan 17, 2016
40169b3
Add common functions and variables
vladgh Jan 17, 2016
8aaf7f3
Add AWS functions
vladgh Jan 17, 2016
d0fbc30
Add a private .env file
vladgh Jan 17, 2016
5c03531
Improve shebang
vladgh Jan 17, 2016
5ea6fa7
Move functions to a separate include folder
vladgh Jan 17, 2016
6d6eee5
Update README
vladgh Jan 17, 2016
1561add
Add main CloudFormation template
vladgh Jan 18, 2016
ee7d59b
Deploy to S3 with Travis
vladgh Jan 18, 2016
9b0d943
Install awscli
vladgh Jan 18, 2016
950cfec
Add sudo
vladgh Jan 18, 2016
1110437
Fix sudo RTFM
vladgh Jan 18, 2016
b92e5df
Fix environment
vladgh Jan 18, 2016
cd6a200
Add encrypted environment
vladgh Jan 18, 2016
b0aac45
Use a custom script for building
vladgh Jan 18, 2016
3a04811
Add cfn_create_stack command
vladgh Jan 18, 2016
717d860
Do not fail if can not find ip
vladgh Jan 18, 2016
dc4d1dd
Use after_success instead of deploy
vladgh Jan 18, 2016
e045afc
Use after_script instead of after_success
vladgh Jan 18, 2016
7735554
Simplify sync command
vladgh Jan 18, 2016
63c8713
Debug build
vladgh Jan 18, 2016
2e02f67
Debug build
vladgh Jan 18, 2016
6996831
Debug build
vladgh Jan 18, 2016
e6671ba
Revert to TRAVIS_BRANCH to find the current branch
vladgh Jan 18, 2016
18572e9
Fix branch
vladgh Jan 18, 2016
d23694f
Cache pip dependencies
vladgh Jan 18, 2016
d64146c
Test cache
vladgh Jan 18, 2016
cbb175e
Improve aws scripts
vladgh Jan 18, 2016
4007e76
Improve AWS functions
vladgh Jan 18, 2016
626208d
Fix aws command
vladgh Jan 19, 2016
48cc36c
Improve wait function for CloudFormation
vladgh Jan 19, 2016
9ccf36e
Fix CloudFormation parameters and tags declaration
vladgh Jan 19, 2016
2f5ff7a
Fix create stack command
vladgh Jan 19, 2016
367d863
Fix Security Group CFN template
vladgh Jan 19, 2016
4eeb6c2
Remove CI user in the IAM CFN template
vladgh Jan 19, 2016
9e485ff
Add a delete stack command
vladgh Jan 19, 2016
93f2459
Remove stack notifications
vladgh Jan 20, 2016
a16d5e5
Upgrade aws cli if needed
vladgh Jan 20, 2016
5c33019
Add a load balancer
vladgh Jan 20, 2016
aeea06c
Ignore external ip error
vladgh Jan 20, 2016
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
Prev Previous commit
Next Next commit
Improve AWS functions
  • Loading branch information
vladgh committed Jan 18, 2016
commit 4007e764a6feda7a6d348e7b4029f00889d07689
Binary file modified .env.enc
Binary file not shown.
2 changes: 1 addition & 1 deletion bin/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ case "$1" in
bundle exec rake test
;;
deploy)
aws_cmd s3 sync "${REPODIR}/cfn/" "${vgh_cfn_stack_s3:?}/" \
aws s3 sync "${REPODIR}/cfn/" "${vgh_cfn_stack_s3:?}/" \
--delete --acl public-read \
--exclude "*" --include "*.json"
;;
Expand Down
3 changes: 3 additions & 0 deletions environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ esac
## External ip
external_ip=$(dig +short myip.opendns.com @resolver1.opendns.com || true)

# AWS
export AWS_DEFAULT_REGION='us-east-1'

## CloudFormation
export vgh_stack_name=${vgh_stack_name:-vgh}
export vgh_stack_file=${vgh_stack_file:-file://./cfn/vgh.json}
Expand Down
51 changes: 22 additions & 29 deletions include/aws.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# shellcheck disable=1090
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)/common.sh"

# AWS Region
export AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION:-us-east-1}"

# NAME: aws_get_metadata
# DESCRIPTION: AWS MetaData Service
aws_get_metadata(){
Expand Down Expand Up @@ -32,26 +35,16 @@ aws_get_instance_az() {
}

# NAME: aws_get_instance_region
# DESCRIPTION: Returns the the AWS region (defaults to us-east-1)
# DESCRIPTION: Returns the the AWS region
aws_get_instance_region() {
if [ -z "${AWS_DEFAULT_REGION}" ]; then
zone=$(aws_get_instance_az)
export AWS_DEFAULT_REGION="${zone%?}"
echo "${AWS_DEFAULT_REGION:-us-east-1}"
else
echo "$AWS_DEFAULT_REGION"
fi
}

# AWS CLI Command
aws_cmd(){
/usr/local/bin/aws --region "$(aws_get_instance_region)" "${@}"
local zone; zone=$(aws_get_instance_az)
echo "${zone%?}"
}

# NAME: list_all_tags
# DESCRIPTION: Returns all EC2 tags associated with the current instance
list_all_tags(){
aws_cmd --output text ec2 describe-tags \
aws --output text ec2 describe-tags \
--filters "Name=resource-id,Values=$(aws_get_instance_id)" \
--query "Tags[*].[join(\`=\`,[Key,Value])]" 2>/dev/null | \
awk '{print tolower($0)}' | \
Expand All @@ -69,7 +62,7 @@ aws_get_tag(){
local instance_id; instance_id=$(aws_get_instance_id)
local resource=${2:-$instance_id}

aws_cmd --output text ec2 describe-tags \
aws --output text ec2 describe-tags \
--filters "Name=resource-id,Values=${resource}" "Name=key,Values=$name" \
--query "Tags[*].[Value]" 2>/dev/null
}
Expand All @@ -82,7 +75,7 @@ aws_get_tag(){
# 1) The instance id
aws_get_instance_state_asg() {
local instance_id=$1
local state; state=$(aws_cmd autoscaling describe-auto-scaling-instances \
local state; state=$(aws autoscaling describe-auto-scaling-instances \
--instance-ids "$instance_id" \
--query "AutoScalingInstances[?InstanceId == \`$instance_id\`].LifecycleState | [0]" \
--output text)
Expand All @@ -102,7 +95,7 @@ aws_get_instance_state_asg() {
# 1) The instance id
aws_get_autoscaling_group_name() {
local instance_id=$1
local autoscaling_name; autoscaling_name=$(aws_cmd autoscaling \
local autoscaling_name; autoscaling_name=$(aws autoscaling \
describe-auto-scaling-instances \
--instance-ids "$instance_id" \
--output text \
Expand Down Expand Up @@ -143,7 +136,7 @@ aws_autoscaling_enter_standby(){
fi

echo "Putting instance $instance_id into Standby"
aws_cmd autoscaling enter-standby \
aws autoscaling enter-standby \
--instance-ids "$instance_id" \
--auto-scaling-group-name "$asg_name" \
--should-decrement-desired-capacity
Expand Down Expand Up @@ -187,7 +180,7 @@ aws_autoscaling_exit_standby(){
fi

echo "Moving instance $instance_id out of Standby"
aws_cmd autoscaling exit-standby \
aws autoscaling exit-standby \
--instance-ids "$instance_id" \
--auto-scaling-group-name "$asg_name"
if [ $? != 0 ]; then
Expand Down Expand Up @@ -215,7 +208,7 @@ aws_deploy_list_running_deployments() {
local app=$1
local group=$2

aws_cmd deploy list-deployments \
aws deploy list-deployments \
--output text \
--query 'deployments' \
--application-name "$1" \
Expand All @@ -233,7 +226,7 @@ aws_deploy_group_exists() {
local app=$1
local group=$2

aws_cmd deploy get-deployment-group \
aws deploy get-deployment-group \
--query 'deploymentGroupInfo.deploymentGroupId' --output text \
--application-name "$1" \
--deployment-group-name "$2" >/dev/null
Expand Down Expand Up @@ -279,7 +272,7 @@ aws_deploy_create_deployment(){
aws_deploy_wait "$@"

echo "Creating deployment for application '${app}', group '${group}'"
aws_cmd deploy create-deployment \
aws deploy create-deployment \
--application-name "$app" \
--s3-location bucket="${bucket}",key="${key}",bundleType="${bundle}" \
--deployment-group-name "$group" \
Expand All @@ -306,7 +299,7 @@ aws_get_private_env(){
echo "File '${file}' already exists. Replacing"
sudo rm "$file"
fi
aws_cmd s3 cp "$src" "$file" || echo "Failed to get ${src}"
aws s3 cp "$src" "$file" || echo "Failed to get ${src}"
if [ -s "$file" ]; then
echo "Setting permissions for ${file}"
sudo chmod 400 "$file"
Expand Down Expand Up @@ -359,7 +352,7 @@ aws_cfn_wait_for_stack(){
echo "Waiting for $stack to complete ..." >&2
until [[ $status =~ _(COMPLETE|FAILED)$ ]]; do
sleep 5
status="$(aws_cmd cloudformation describe-stacks --stack-name "$1" --output text --query 'Stacks[0].StackStatus')"
status="$(aws cloudformation describe-stacks --stack-name "$1" --output text --query 'Stacks[0].StackStatus')"
echo " ... $stack - $status" >&2
done

Expand Down Expand Up @@ -416,7 +409,7 @@ aws_cf_events() {
stack="$(basename "$1" .json)"
shift
local output
if output=$(aws_cmd --color on cloudformation describe-stack-events --stack-name "$stack" --query 'sort_by(StackEvents, &Timestamp)[].{Resource: LogicalResourceId, Type: ResourceType, Status: ResourceStatus}' --output table "$@"); then
if output=$(aws --color on cloudformation describe-stack-events --stack-name "$stack" --query 'sort_by(StackEvents, &Timestamp)[].{Resource: LogicalResourceId, Type: ResourceType, Status: ResourceStatus}' --output table "$@"); then
echo "$output" | uniq -u
else
return $?
Expand All @@ -427,7 +420,7 @@ aws_cf_events() {
# DESCRIPTION: Returns the ELB to which the instance is registered.
aws_get_elb_name() {
local instance_id; instance_id=$(aws_get_instance_id)
if output=$(aws_cmd elb describe-load-balancers --query "LoadBalancerDescriptions[?contains(Instances[].InstanceId, \`${instance_id}\`)].LoadBalancerName" --output text); then
if output=$(aws elb describe-load-balancers --query "LoadBalancerDescriptions[?contains(Instances[].InstanceId, \`${instance_id}\`)].LoadBalancerName" --output text); then
echo "$output"
else
return $?
Expand All @@ -438,7 +431,7 @@ aws_get_elb_name() {
# DESCRIPTION: Returns the Elastic Load Balancer health check configuration
aws_elb_get_health_check() {
local elb; elb=$(aws_get_elb_name)
if output=$(aws_cmd elb describe-load-balancers --load-balancer-names "$elb" --query 'LoadBalancerDescriptions[].HealthCheck | [0]'); then
if output=$(aws elb describe-load-balancers --load-balancer-names "$elb" --query 'LoadBalancerDescriptions[].HealthCheck | [0]'); then
echo "$output"
else
return $?
Expand All @@ -453,7 +446,7 @@ aws_elb_get_health_check() {
# Ex: Target=HTTP:80/,Interval=10,UnhealthyThreshold=5,HealthyThreshold=2,Timeout=5
aws_elb_configure_health_check() {
local elb; elb=$(aws_get_elb_name)
if output=$(aws_cmd elb configure-health-check --load-balancer-name "$elb" --health-check "$1"); then
if output=$(aws elb configure-health-check --load-balancer-name "$elb" --health-check "$1"); then
echo "$output"
else
return $?
Expand All @@ -463,7 +456,7 @@ aws_elb_configure_health_check() {
# NAME: aws_ecs_list_clusters
# DESCRIPTION: Returns a list of EC2 Container Service Clusters
aws_ecs_list_clusters(){
if output=$(aws_cmd ecs list-clusters --query 'clusterArns[]' --output text); then
if output=$(aws ecs list-clusters --query 'clusterArns[]' --output text); then
echo "$output"
else
return $?
Expand Down