A simple hello world node js application
npm start
- A jenkins server hosted on-prem / on aws exists with the necessary plugins installed (aws credentials plugin, docker plugin etc).
- AWS credentials set up in jenkins server (separate user in case of on-prem server, role in case of aws hosted).
- A jenkins job created with git source https://github.com/balajijudaya/node-hello.git which looks for Jenkinsfile at the root for pipeline script.
- Github webhook set up to trigger jenkins job on code checkins.
- Terraform will provision the infrastructue in aws including VPC, subnets, internet gateway, NAT gateway, route tables, security groups, etc.
- Terraform will provision a ECS(Fargate) cluster to run the node service based on the task definition template.
- ECS service is configures to autoscale based on CPU usage (with cloudwatch monitoring).
- Application Load Balancer will act as a Front for user requests which will route requests to the ECS service.
- Terraform will pick up latest docker image from ECR and deploy to stage and prod ECS clusters.
- Terraform infrastructure state is managed using s3 buckets and dynamo db tables for stage and prod environments so that terraform always knows the current state of the infrastructure.
- Manual deployment using terraform
cd bootstrap
terraform init
terraform plan
terraform apply
terraform init -backend-config=stage-backend.tfvars
terraform plan -var-file=stage.tfvars
terraform apply -var-file=stage.tfvars
terraform init -backend-config=prod-backend.tfvars
terraform plan -var-file=prod.tfvars
terraform apply -var-file=prod.tfvars
When jenkins job is triggerred by github webhook / manual trigger, pipeline will be executed.
- npm dependencies will be installed.
- npm unit test will be run.
- New docker image based on the Dockerfill will be built and tagged as latest.
- Docker image built will be pushed to aws ECR.
- Terraform script is triggerred to deploy the latest docker images to stage environment ECS cluster.
- A cucumber selenium functional test is run against the stage environment(latest deployment).
- Once regression suite succeeds, jenkins will prompt the user for approval to promote the deployment to prod.
- On approval terraform script will be triggerred to deploy to production. On 'cancel' jenkins job will be aborted.
- During any failure in any of the above steps will cause the jenkins build to fail and abort and send out an failure email.
- ALB url will be the url used by the users to access the node app. Route 53 DNS is not implemented.
- No alerting implemented in case of service unavailability. But email will be sent in case of build / test / deployment failures.