Skip to content

Commit 0aec523

Browse files
author
Seth Goings
committed
Merge pull request #4436 from sgoings/rigger-aws
contrib(aws): add aws support for rigger
2 parents be4939c + b456e3f commit 0aec523

5 files changed

Lines changed: 186 additions & 0 deletions

File tree

contrib/aws/check

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail -o nounset
4+
5+
function check-elb-service {
6+
local elb_name="${1}"
7+
8+
ATTEMPTS=45
9+
SLEEPTIME=10
10+
COUNTER=1
11+
IN_SERVICE=0
12+
until [ $IN_SERVICE -ge 1 ]; do
13+
if [ $COUNTER -gt $ATTEMPTS ]; then exit 1; fi # timeout after 7 1/2 minutes
14+
if [ $COUNTER -ne 1 ]; then sleep $SLEEPTIME; fi
15+
rigger-log "Waiting for ELB (${elb_name}) to see an instance in InService..."
16+
IN_SERVICE=$(aws elb describe-instance-health \
17+
--load-balancer-name "${elb_name}" \
18+
--query 'InstanceStates[].State' \
19+
| grep InService \
20+
| wc -l)
21+
done
22+
}
23+
24+
check-elb-service "${ELB_NAME}"

contrib/aws/config.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export SUGGEST_DEV_REGISTRY="registry.hub.docker.com"
2+
export STACK_TAG="${STACK_TAG:-test}-${DEIS_ID}"
3+
export DEIS_NUM_INSTANCES=${DEIS_NUM_INSTANCES:-3}
4+
export STACK_NAME="${STACK_NAME:-deis-${STACK_TAG}}"
5+
6+
prompt "Enter your AWS key:" AWS_ACCESS_KEY_ID
7+
prompt "Enter your AWS secret key:" AWS_SECRET_ACCESS_KEY
8+
9+
rigger-save-vars AWS_ACCESS_KEY_ID \
10+
AWS_SECRET_ACCESS_KEY \
11+
STACK_NAME \
12+
STACK_TAG

contrib/aws/create

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail -o nounset
4+
5+
export DEIS_NUM_INSTANCES=3
6+
7+
function aws-setup-keypair {
8+
local deis_auth_key="${1}"
9+
10+
rigger-log "Importing ${deis_auth_key} keypair to EC2"
11+
12+
# TODO: don't hardcode --key-names
13+
if ! aws ec2 describe-key-pairs --key-names "deis" >/dev/null ; then
14+
rigger-log "Importing ${deis_auth_key} keypair to EC2"
15+
aws ec2 import-key-pair --key-name deis \
16+
--public-key-material file://${deis_auth_key}.pub \
17+
--output text
18+
fi
19+
}
20+
21+
function aws-provision-cluster {
22+
local stack_name="${1}"
23+
24+
# customize cloudformation.json to use m3.medium instances
25+
cat > $DEIS_ROOT/contrib/aws/cloudformation.json <<EOF
26+
[
27+
{
28+
"ParameterKey": "KeyPair",
29+
"ParameterValue": "deis"
30+
}
31+
]
32+
EOF
33+
34+
rigger-log "Provisioning ${DEIS_NUM_INSTANCES}-node CoreOS"
35+
36+
"${DEIS_ROOT}/contrib/aws/provision-aws-cluster.sh" "${stack_name}"
37+
38+
# discard changes to cloudformation.json
39+
git checkout -- "${DEIS_ROOT}/contrib/aws/cloudformation.json"
40+
}
41+
42+
function aws-get-elb-dns-name {
43+
local stack_name="${1}"
44+
45+
aws cloudformation describe-stacks \
46+
--stack-name "${stack_name}" \
47+
--max-items 1 \
48+
--query 'Stacks[].[ Outputs[0].[ OutputValue ] ]' \
49+
--output=text
50+
}
51+
52+
function aws-get-elb-name {
53+
local elb_dns_name="${1}"
54+
55+
aws elb describe-load-balancers \
56+
--query 'LoadBalancerDescriptions[].[ DNSName,LoadBalancerName ]' \
57+
--output=text | grep -F ${elb_dns_name} | head -n1 | cut -f2
58+
}
59+
60+
function aws-setup-route53 {
61+
local stack_name="${1}"
62+
local domain="${2}"
63+
64+
rigger-log "Setting up Route53 zone..."
65+
66+
python "${DEIS_ROOT}/contrib/aws/route53-wildcard.py" create "${domain}" "$(aws-get-elb-dns-name ${stack_name})"
67+
}
68+
69+
function aws-get-instance-id {
70+
local stack_name="${1}"
71+
72+
local instance_ids=$(aws ec2 describe-instances \
73+
--filters Name=tag:aws:cloudformation:stack-name,Values=${stack_name} Name=instance-state-name,Values=running \
74+
--query 'Reservations[].Instances[].[ InstanceId ]' \
75+
--output text)
76+
77+
cut -d " " -f1 <<< ${instance_ids}
78+
}
79+
80+
function aws-deisctl-tunnel {
81+
local stack_name="${1}"
82+
83+
aws ec2 describe-instances \
84+
--instance-ids=$(aws-get-instance-id ${stack_name}) \
85+
--filters Name=tag:aws:cloudformation:stack-name,Values=${stack_name} Name=instance-state-name,Values=running \
86+
--query 'Reservations[].Instances[].[ PublicDnsName ]' \
87+
--output text
88+
}
89+
90+
(
91+
cd ${DEIS_ROOT}
92+
rigger-log "Creating CloudFormation stack ${STACK_NAME}"
93+
aws-setup-keypair "${DEIS_TEST_AUTH_KEY}"
94+
aws-provision-cluster "${STACK_NAME}"
95+
)
96+
97+
export ELB_DNS_NAME=$(aws-get-elb-dns-name "${STACK_NAME}")
98+
export ELB_NAME=$(aws-get-elb-name "${ELB_DNS_NAME}")
99+
export DEIS_TEST_DOMAIN="${STACK_TAG}.${DEIS_TEST_DOMAIN}"
100+
101+
(
102+
cd ${DEIS_ROOT}
103+
aws-setup-route53 "${STACK_NAME}" "${DEIS_TEST_DOMAIN}"
104+
aws-get-instance-id "${STACK_NAME}"
105+
)
106+
107+
export DEISCTL_TUNNEL="$(aws-deisctl-tunnel ${STACK_NAME})"
108+
rigger-log "DEISCTL_TUNNEL=${DEISCTL_TUNNEL}"
109+
rigger-save-vars DEISCTL_TUNNEL \
110+
ELB_DNS_NAME \
111+
ELB_NAME \
112+
STACK_TAG \
113+
STACK_NAME \
114+
DEIS_TEST_DOMAIN

contrib/aws/destroy

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail -o nounset
4+
5+
function aws-get-elb-dns-name {
6+
local stack_name="${1}"
7+
8+
aws cloudformation describe-stacks \
9+
--stack-name "${stack_name}" \
10+
--max-items 1 \
11+
--query 'Stacks[].[ Outputs[0].[ OutputValue ] ]' \
12+
--output=text
13+
}
14+
15+
function aws-destroy-route53 {
16+
local stack_name="${1}"
17+
local domain="${2}"
18+
19+
local elb_dns_name="$(aws-get-elb-dns-name ${stack_name})"
20+
21+
if [ -n "${elb_dns_name}" ]; then
22+
rigger-log "Removing Route53 zone..."
23+
python "${DEIS_ROOT}/contrib/aws/route53-wildcard.py" delete "${domain}" "${elb_dns_name}"
24+
fi
25+
}
26+
27+
rigger-log "Attempting to destroy ${STACK_NAME}..."
28+
29+
aws cloudformation delete-stack --stack-name "${STACK_NAME}"
30+
31+
aws-destroy-route53 "${STACK_NAME}" "${DEIS_TEST_DOMAIN}"

contrib/aws/install

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
set -eo pipefail -o nounset
4+
5+
pip install -r requirements.txt

0 commit comments

Comments
 (0)