Skip to content

Commit

Permalink
add ELB support to Dokku stack
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasmcnulty committed Oct 13, 2017
1 parent efaaf5f commit e4a54a0
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 32 deletions.
36 changes: 34 additions & 2 deletions stack/dokku.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import troposphere.cloudformation as cloudformation
import troposphere.ec2 as ec2
import troposphere.iam as iam
from troposphere import Base64, FindInMap, Join, Output, Parameter, Ref, Tags
from troposphere import (
Base64,
Equals,
FindInMap,
Join,
Output,
Parameter,
Ref,
Tags
)
from troposphere.policies import CreationPolicy, ResourceSignal

from .assets import assets_management_policy
Expand Down Expand Up @@ -81,6 +90,27 @@
label="SSH CIDR",
)

load_balancer_enable = template.add_parameter(
Parameter(
"LoadBalancerEnable",
Description="Whether or not to place a Elastic Load Balancer (with an auto-generated SSL "
"certificate) in front of your Dokku instance.",
Type="String",
AllowedValues=["true", "false"],
Default="false",
),
group="Load Balancer",
label="Enable Load Balancer",
)

use_load_balancer = "DokkuUseLoadBalancer"
template.add_condition(use_load_balancer, Equals(Ref(load_balancer_enable), "true"))

# Don't create the load balancer unless it's needed, and don't import it until the
# load_balancer_enable Parameter is defined (so it shows up first in the interface)
from .load_balancer import load_balancer # noqa: E402
load_balancer.Condition = use_load_balancer

# "16.04 hvm ssd" AMIs from https://cloud-images.ubuntu.com/locator/ec2/
template.add_mapping('RegionMap', {
"ap-northeast-1": {"AMI": "ami-0417e362"},
Expand Down Expand Up @@ -153,7 +183,6 @@
# Elastic IP for EC2 instance
eip = template.add_resource(ec2.EIP("Eip"))


# The Dokku EC2 instance
ec2_instance_name = 'Ec2Instance'
ec2_instance = template.add_resource(ec2.Instance(
Expand Down Expand Up @@ -285,6 +314,9 @@
),
))

# assign our load balancer (if any) the Dokku instance
load_balancer.Instances = [Ref(ec2_instance)]

# Associate the Elastic IP separately, so it doesn't change when the instance changes.
eip_assoc = template.add_resource(ec2.EIPAssociation(
"EipAssociation",
Expand Down
59 changes: 29 additions & 30 deletions stack/vpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,39 +117,38 @@
)


if not USE_DOKKU:
# Holds load balancer
loadbalancer_a_subnet_cidr = "10.0.2.0/24"
loadbalancer_a_subnet = Subnet(
"LoadbalancerASubnet",
template=template,
VpcId=Ref(vpc),
CidrBlock=loadbalancer_a_subnet_cidr,
AvailabilityZone=Ref(primary_az),
)
# Holds load balancer
loadbalancer_a_subnet_cidr = "10.0.2.0/24"
loadbalancer_a_subnet = Subnet(
"LoadbalancerASubnet",
template=template,
VpcId=Ref(vpc),
CidrBlock=loadbalancer_a_subnet_cidr,
AvailabilityZone=Ref(primary_az),
)

SubnetRouteTableAssociation(
"LoadbalancerASubnetRouteTableAssociation",
template=template,
RouteTableId=Ref(public_route_table),
SubnetId=Ref(loadbalancer_a_subnet),
)
SubnetRouteTableAssociation(
"LoadbalancerASubnetRouteTableAssociation",
template=template,
RouteTableId=Ref(public_route_table),
SubnetId=Ref(loadbalancer_a_subnet),
)

loadbalancer_b_subnet_cidr = "10.0.3.0/24"
loadbalancer_b_subnet = Subnet(
"LoadbalancerBSubnet",
template=template,
VpcId=Ref(vpc),
CidrBlock=loadbalancer_b_subnet_cidr,
AvailabilityZone=Ref(secondary_az),
)
loadbalancer_b_subnet_cidr = "10.0.3.0/24"
loadbalancer_b_subnet = Subnet(
"LoadbalancerBSubnet",
template=template,
VpcId=Ref(vpc),
CidrBlock=loadbalancer_b_subnet_cidr,
AvailabilityZone=Ref(secondary_az),
)

SubnetRouteTableAssociation(
"LoadbalancerBSubnetRouteTableAssociation",
template=template,
RouteTableId=Ref(public_route_table),
SubnetId=Ref(loadbalancer_b_subnet),
)
SubnetRouteTableAssociation(
"LoadbalancerBSubnetRouteTableAssociation",
template=template,
RouteTableId=Ref(public_route_table),
SubnetId=Ref(loadbalancer_b_subnet),
)


if USE_NAT_GATEWAY:
Expand Down

0 comments on commit e4a54a0

Please sign in to comment.