This document discusses using Packer and Jenkins to create immutable AWS deployments. Packer is used to build machine images from the ground up with all necessary software and code pre-installed. Provisioners further configure and customize the images. Jenkins automates building the images with Packer whenever code is committed. The immutable images prevent drift and ensure consistency. The process allows fully automated deployments through launching instances from the pre-built images.
11. What could go wrong?
Unpatched, outdated dependencies
Inconsistent app behavior
Changes outside of the deployment cycle
Human Error(s)
Does not scale
13. Immutability
Build the entire runtime infrastructure from ground up
Automate it!
Runtime Infrastructure = O/S + Libraries + App Server + Code + Agents
14. AWS
AWS is collection of services for..
Compute
Storage
Databases
Messaging
+ many, many more...
15. AWS
AWS helps build architectures that are -
Highly Available
Fault Tolerant
Scalable
Cost-efficient
16. AMIs
Templates to launch EC2 instances
Specify O/S, Virtualization Type, Storage Type, Volume Attachments, etc.
Can be shared within accounts, or made public
Highest level of deployment abstraction
17.
18. Customize AMIs
Trim the fat
Configure the libraries, tune the parameters
Summary : Make infrastructure, not war*
* Java Reference
19. Packer
A tool from Hashicorp to create Machine Images
Supports multiple providers
Supports multiple provisioners
24. Inspect
~ packer inspect packer.json
Optional variables and their defaults:
aws_access_key =
aws_secret_key =
Builders:
amazon-ebs
Provisioners:
<No provisioners>
Note: If your build names contain user variables or template
functions such as 'timestamp', these are processed at build time,
and therefore only show in their raw form here.
25. Build!
~ packer build packer.json
amazon-ebs output will be in this color.
==> amazon-ebs: Prevalidating AMI Name: ScaleByTheBay AMI
amazon-ebs: Found Image ID: ami-8c1be5f6
==> amazon-ebs: Launching a source AWS instance...
==> amazon-ebs: Waiting for instance (i-09f4b837ed80a659f) to become ready...
==> amazon-ebs: Waiting for SSH to become available...
==> amazon-ebs: Stopping the source instance...
==> amazon-ebs: Creating the AMI: ScaleByTheBay AMI
amazon-ebs: AMI: ami-5b18a121
==> amazon-ebs: Waiting for AMI to become ready...
==> amazon-ebs: Terminating the source AWS instance...
==> Builds finished. The artifacts of successful builds are:
--> amazon-ebs: AMIs were created:
us-east-1: ami-5b18a121
29. Make our AMI ...useful
1. Apply updates and patches
2. Install OpenJDK 8
3. Install Tomcat 8
4. Download the application artifact, the war
5. Configure Tomcat to run at startup
37. Verify the API
~ curl -iv http://ec2-54-88-249-121.compute-1.amazonaws.com:8080/helloworld-api/hello
* Trying 54.88.249.121...
* TCP_NODELAY set
* Connected to ec2-54-88-249-121.compute-1.amazonaws.com (54.88.249.121) port 8080 (#0)
> GET /helloworld-api/hello HTTP/1.1
> Host: ec2-54-88-249-121.compute-1.amazonaws.com:8080
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 200
HTTP/1.1 200
< Content-Type: text/html;charset=utf-8
< Transfer-Encoding: chunked
< Date: Sat, 11 Nov 2017 08:20:09 GMT
<
* Connection #0 to host ec2-54-88-249-121.compute-1.amazonaws.com left intact
Hello World!
~
38. Automate this - Jenkins
1. git clone <repo>
2. mvn clean install test
3. mvn release:prepare release:perform
4. export version=1.0.2
5. packer build packer.json
6. Output this AMI ID to Terraform to launch an
Autoscaling Group
39. Summary
Do not release code - release runtime infrastructure
Automate Everything
Legendary = Disable ssh from your AMIs