In this example we’ll use stack consisting of:
Framework: Meteor, great new platform;
Database: mongoDB hosted on compose.io SaaS to show you how to work with external services;
Git repo hosting: BitBucket, because nowadays it’s more common than AWS CodeCommit;
Docker repo hosting: DockerHub, because it’s more common than AWS EC2 Container Registry.
We’ll use pretty classic environments:
Dev environment will be used for functional testing;
Stg environment will be used for load testing and because of this it must be exactly the same as prod;
Prod environment will be used by clients, so no testing on the holy ground.
So we’ll use:
Git repo with dev branch for dev and master branch for prod and stg;
DockerHub repo with dev, stg and prod tags;
ElasticBeanstalk app with dev, stg and prod environments;
And we need some place to build a code and run deploys. To make things simple we’ll use dedicated instance called “build machine” to run all stuff.
Flow & requirements are also simple and common:
All environments must be able to be created from scratch in 30 minutes;
All environments must be able to be restored to previous code version in 15 minutes;
New code from git dev branch must be built and deployed to dev environment automatically in 10 minutes;
New code from git master branch must be built and deployed to stg environment automatically in 30 minutes;
New code from git master branch must be built and deployed to prod environment manually in 30 minutes.
It looks like this:
Since I’ve called demo app “meteorapp” I’ll call script “meteorapp” too.
Create, deploy and restore processes have a lot in common, so we’ll use the same script with positional parameter “Get action” action=$1
And even more – the processes are almost the same for all environments, so we’ll the use the same script with positional parameter “Get environment” env=$2
So here’re an example of using it:
You can add any number of environments and actions, but I don’t recommend you to run two or more actions at the same time.
If you need it for any reason you can use this script on a few build machines.
And of course you can split meteorapp.sh into createDev.sh, deployStg.sh, restoreProd.sh, etc.
To give you an example I decided to create separate createEbApp.sh script.
Sounds good, so let’s get down to practice!
CD with AWS Elastic Beanstalk table of contents