elasticdev.yml
Stacks are executed through a launch configuration file - elasticdev/elasticdev.yml .
Sections
These are the major sections in the yml file:
global
arguments
<arg 1>
<arg 2>
<arg 3>
...
<automation category>:
<stack alias configuration>:
stack_name: <stack_name>
arguments:
<arg 1>
<arg 2>
<arg 3>
...
Global Arguments
Global variables are passed to all stacks in the project.
global:
arguments:
cloud_provider: aws
region: us-east-1
db_type: mysql
sg_db_label: database
sg_web_label: web
Field | Description |
---|---|
global => arguments | arguments – stack arguments for all the stacks in the project. |
Labels
- labels are applied to created resources.
labels:
general:
environment: dev
purpose: test
infrastructure:
cloud: aws
product: vpc
app_tier: networking
vehicle:
car: bmw
In the example, the first label general contains key,value:
- environment -> dev
- purpose -> test
As shown, labels general , infrastructure , and vehicle will be applied to infrastructure resources such as the VPC, subnets, security groups, and internet gateways.
infrastructure:
vpc:
stack_name: elasticdev:::aws_vpc_and_security_group
arguments:
eks_cluster: eval-ed-eks
vpc_name: eval-ed-vpc
main_network_block: 10.30.0.0/16
tier_level: "2"
enable_nat_gateway: true
single_nat_gateway: true
enable_dns_hostnames: true
reuse_nat_ips: true
one_nat_gateway_per_az: false
tags: "mongo,database,stateful"
labels:
- general
- infrastructure
- vehicle
Selectors
- selectors are queried for variable substitution.
- match_labels are key/value for the query
- match_keys are specific key,value (not labels) used as part of the query.
- match_params are additional params and conditions. For example:
- must_exist => True – the query must return at least a value
- resource_type => The resource type to query for.
An example for selector(s) definitions.
selectors:
vpc_info:
match_labels:
car: bmw
environment: dev
match_keys:
provider: aws
region: us-west-1
match_params:
must_exists: True
resource_type: vpc
sg_info:
match_labels:
car: bmw
environment: dev
match_keys:
provider: aws
region: us-west-1
name: database
match_params:
must_be_one: True
resource_type: security_group
subnet_info:
match_labels:
car: bmw
environment: dev
match_keys:
provider: aws
region: us-west-1
name: private
match_params:
resource_type: subnet
Selectors are included per stack - they are not global.
infrastructure:
rds:
stack_name: elasticdev:::aws_rds
arguments:
vpc_name: selector:::vpc_info::name
sg_id: selector:::sg_info::sg_id
subnet_ids: selector:::subnet_info::subnet_id:csv
rds_name: eval-ed-rds
allocated_storage: 14
db_name: app
selectors:
- vpc_info
- sg_info
- subnet_info
The selector query below:
<variable_name>:selector::: <selector name> ::<key in query>::<<format>
For example:
- vpc_name:selector::: vpc_info :: name
- subnet_ids:selector::: subnet_info :: subnet_id :: csv
The variable vpc_name will be looked up through the selector vpc_info . The key name is return from the selector result. String is the default format.
The subnet_ids will be looked up through the selector subnet_info . The key subnet_id from results is returned. The format will be a string of subnet_ids separated by a comma – csv .
Specify Stacks
Parameterized stacks are driven by both arguments and environmental variables. Since stacks are first class citizens, they are specified and configured as such:
automation category
- the stacks are categorized by automation type in the yml configuration.
- examples: infrastructure , build , and deploy .
stack alias
- in each automation category, the stack is given an alias.
- example: ecr_repo is an alias for stack name elasticdev:::ecr_repo .
stack name
- the stack names are referenced by username, stack_name, and optionally version
- < username >:::< stack_name >:< version >1
- latest version (most common)
- elasticdev:::ec2_docker_host
- release version (most known and stable)
- elasticdev:::ec2_docker_host:0.0.1
- auto-incrementing version (most simple)
- elasticdev:::ec2_docker_host:5
arguments
- variables used by the stack.
- arguments drive the behavior of the stack.
#<automation_category>
# <stack_alias_setup>
# stack_name: <stack_name>
# arguments:
# ...
infrastructure:
ecr_repo:
stack_name: elasticdev:::ecr_repo
arguments:
name: flask_sample
dockerhost:
stack_name: elasticdev:::ec2_docker_host
arguments:
size: t2.micro
disksize: 25
Sample
The sample yml file provides DockerCI on AWS. It is end to end automation with a single entry point.
- creates the ECR repository if it doesn’t exists.
- creates the EC2 server build and test code
- creates the ssh key on Bitbucket repository
- sets up the webhook that triggers builds
global:
arguments:
aws_default_region: us-east-1
docker_repo: flask_sample
infrastructure:
ecr_repo:
stack_name: elasticdev:::ecr_repo
arguments:
name: flask_sample
dockerhost:
stack_name: elasticdev:::ec2_docker_host
arguments:
size: t2.micro
disksize: 25
stack_vars:
- name: elasticdev:::ubuntu::ec2_ubuntu
arguments:
ip_key: public_ip
build:
ci_example:
create_webhook: False
dependencies:
- infrastructure::dockerhost
- infrastructure::ecr_repo
stack_name: elasticdev:::ec2_ci_fastest
arguments:
repo_url: https://bitbucket.org/williaumwu/flask_sample
repo_branch: dev
dockerfile: Dockerfile
dockerfile_test: Dockerfile_test
triggered_branches:
- dev
-
- version is optional.
- version can be auto-incrementing like 1,2,3
- version can also be release version provided by user