SlideShare une entreprise Scribd logo
1  sur  41
Télécharger pour lire hors ligne
Immutable AWS Deployments
with Packer and Jenkins
Scale by the Bay, 2017
Manish Pandit
About
Manish Pandit
Director of Platform Engineering @Marqeta
Twitter : @lobster1234
Blog: lobster1234.github.io
Show of hands
Deployments
DevOps, CI/CD, Tooling,..
AWS (or something similar!)
Deployments
The process of pushing code beyond the development environment
Multi-step
Usually (heavily) scripted
Complete, or Partial
Complete
Provisioning the stack from ground up
Installation of O/S, Runtime, Application Server, Code, Agents, ...
# mkfs –t ext4 /dev/sda0
# mkdir /apps
# mount –t ext4 /dev/sda0 /apps
Partial
Very common across the board
In-place deployment
“Saves time”
Gives a false sense of automation
Typical Steps
~ scp builds/myService-1.0.2.war mpandit@prd.example.com:/usr/local/tomcat8/webapps
~ ssh mpandit@prd.example.com
~ sudo /usr/local/tomcat8/bin/catalina.sh restart
Typical Steps
~ ssh mpandit@prd.example.com
~ wget https://nx.example.com/com/foo/myService.war -O /usr/local/tomcat8/webapps
~ sudo /usr/local/tomcat8/catalina.sh restart
Automation?
Script this all
Run via a Jenkins job
Fabric (Python), Capistrano, etc.
What could go wrong?
What could go wrong?
Unpatched, outdated dependencies
Inconsistent app behavior
Changes outside of the deployment cycle
Human Error(s)
Does not scale
Immutability
Build the entire runtime infrastructure from ground up
Automate it!
Immutability
Build the entire runtime infrastructure from ground up
Automate it!
Runtime Infrastructure = O/S + Libraries + App Server + Code + Agents
AWS
AWS is collection of services for..
Compute
Storage
Databases
Messaging
+ many, many more...
AWS
AWS helps build architectures that are -
Highly Available
Fault Tolerant
Scalable
Cost-efficient
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
Customize AMIs
Trim the fat
Configure the libraries, tune the parameters
Summary : Make infrastructure, not war*
* Java Reference
Packer
A tool from Hashicorp to create Machine Images
Supports multiple providers
Supports multiple provisioners
Install
~ packer -v
1.1.1
~
Install via brew, or,
Download the binary from the packer.io website
Credentials
EC2 = Use IAM Role for Packer *
Non-EC2 = Use AWS Credentials
* Packer website has the IAM role details
Builders
Define Machine Images for many platforms
JSON-based
Popular : AWS AMI, VMWare, Docker, Azure, GCP…
Custom
AWS AMI Builder
{
"_comment":"Simple Packer Template using Amazon Linux 2017.09.0",
"variables":{
"aws_access_key":"",
"aws_secret_key":""
},
"builders":[
{
"type":"amazon-ebs",
"access_key":"{{user `aws_access_key`}}",
"secret_key":"{{user `aws_secret_key`}}",
"region":"us-east-1",
"source_ami":"ami-8c1be5f6",
"instance_type":"t2.micro",
"ssh_username":"ec2-user",
"ami_name":"ScaleByTheBay AMI"
}
]
}
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.
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
Provisioners
JSON based
Install and configure packages and components
+many, many more tasks
Popular : Ansible, Chef, Puppet, Shell, ..
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
Let’s Provision our AMI
"provisioners": [{
"type": "shell",
"inline": [
"sudo yum update -y",
"sudo yum install java-1.8.0 java-1.8.0-openjdk-devel tomcat8-webapps -y",
"sudo yum remove java-1.7.0-openjdk -y",
"sudo wget https://github.com/lobster1234/helloworld-api/files/953511/helloworld-api.war.gz -O
/usr/share/tomcat8/webapps/helloworld-api.war.gz",
"sudo gunzip /usr/share/tomcat8/webapps/helloworld-api.war.gz",
"sudo chkconfig tomcat8 on"
]
}]
{
"_comment":"Simple Packer Template using Amazon Linux 2017.09.0",
"variables":{
"aws_access_key":"",
"aws_secret_key":""
},
"builders":[
{
"type":"amazon-ebs",
"access_key":"{{user `aws_access_key`}}",
"secret_key":"{{user `aws_secret_key`}}",
"region":"us-east-1",
"source_ami":"ami-8c1be5f6",
"instance_type":"t2.micro",
"ssh_username":"ec2-user",
"ami_name":"ScaleByTheBay AMI with Tomcat8"
}
],
"provisioners": [{
"type": "shell",
"inline": [
"sleep 30",
"sudo yum update -y",
"sudo yum install java-1.8.0 java-1.8.0-openjdk-devel tomcat8-webapps -y",
"sudo yum remove java-1.7.0-openjdk -y",
"sudo wget https://github.com/lobster1234/helloworld-api/files/953511/helloworld-api.war.gz -O /usr/share/tomcat8/webapps/helloworld-
api.war.gz",
"sudo gunzip /usr/share/tomcat8/webapps/helloworld-api.war.gz",
"sudo chkconfig tomcat8 on"
]
}]
}
Build!
~ packer build packer.json
....
==> amazon-ebs: Connected to SSH!
==> amazon-ebs: Provisioning with shell script: /var/folders/vf/d0q4kjg964581kjjz4969dbny407x7/T/packer-shell539435218
amazon-ebs: Loaded plugins: priorities, update-motd, upgrade-helper
amazon-ebs: Resolving Dependencies
amazon-ebs: --> Running transaction check
amazon-ebs: ---> Package amazon-ssm-agent.x86_64 0:2.1.4.0-1.amzn1 will be updated
amazon-ebs:
amazon-ebs: 2017-11-11 07:51:33 (64.0 MB/s) - ‘/usr/share/tomcat8/webapps/helloworld-api.war.gz’ saved
[1918559/1918559]
amazon-ebs:
==> amazon-ebs: Creating the AMI: ScaleByTheBay AMI with Tomcat8
amazon-ebs: AMI: ami-73ed5509
==> amazon-ebs: Waiting for AMI to become ready...
Build 'amazon-ebs' finished.
==> Builds finished. The artifacts of successful builds are:
--> amazon-ebs: AMIs were created:
us-east-1: ami-73ed5509
Launch the instance
Check it out
Verify Tomcat
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!
~
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
Summary
Do not release code - release runtime infrastructure
Automate Everything
Legendary = Disable ssh from your AMIs
Resources
Packer - https://packer.io
AWS EC2 - https://aws.amazon.com/documentation/ec2/
My Blog Post - https://tinyurl.com/packer-jenkins
Questions
Manish Pandit
@lobster1234
lobster1234.github.io
Like what you saw? Come work with me @Marqeta!

Contenu connexe

Tendances

Tendances (20)

[AWS Dev Day] 앱 현대화 | AWS Fargate를 사용한 서버리스 컨테이너 활용 하기 - 삼성전자 개발자 포털 사례 - 정영준...
[AWS Dev Day] 앱 현대화 | AWS Fargate를 사용한 서버리스 컨테이너 활용 하기 - 삼성전자 개발자 포털 사례 - 정영준...[AWS Dev Day] 앱 현대화 | AWS Fargate를 사용한 서버리스 컨테이너 활용 하기 - 삼성전자 개발자 포털 사례 - 정영준...
[AWS Dev Day] 앱 현대화 | AWS Fargate를 사용한 서버리스 컨테이너 활용 하기 - 삼성전자 개발자 포털 사례 - 정영준...
 
Automation with Packer and TerraForm
Automation with Packer and TerraFormAutomation with Packer and TerraForm
Automation with Packer and TerraForm
 
Getting Started with Amazon ECS
Getting Started with Amazon ECSGetting Started with Amazon ECS
Getting Started with Amazon ECS
 
Amazon EC2 Container Service Live Demo - Microservices Web Day
Amazon EC2 Container Service Live Demo - Microservices Web DayAmazon EC2 Container Service Live Demo - Microservices Web Day
Amazon EC2 Container Service Live Demo - Microservices Web Day
 
Packer
Packer Packer
Packer
 
Spinnaker 파트 1
Spinnaker 파트 1Spinnaker 파트 1
Spinnaker 파트 1
 
The AWS DevOps combo (January 2017)
The AWS DevOps combo (January 2017)The AWS DevOps combo (January 2017)
The AWS DevOps combo (January 2017)
 
AWS CloudFormation and Puppet at PuppetConf - Jinesh Varia
AWS CloudFormation and Puppet at PuppetConf - Jinesh VariaAWS CloudFormation and Puppet at PuppetConf - Jinesh Varia
AWS CloudFormation and Puppet at PuppetConf - Jinesh Varia
 
Fargate 를 이용한 ECS with VPC 1부
Fargate 를 이용한 ECS with VPC 1부Fargate 를 이용한 ECS with VPC 1부
Fargate 를 이용한 ECS with VPC 1부
 
Amazon EC2 Container Service
Amazon EC2 Container ServiceAmazon EC2 Container Service
Amazon EC2 Container Service
 
Infrastructure as code with Amazon Web Services
Infrastructure as code with Amazon Web ServicesInfrastructure as code with Amazon Web Services
Infrastructure as code with Amazon Web Services
 
Packer by HashiCorp
Packer by HashiCorpPacker by HashiCorp
Packer by HashiCorp
 
Service Delivery Assembly Line with Vagrant, Packer, and Ansible
Service Delivery Assembly Line with Vagrant, Packer, and AnsibleService Delivery Assembly Line with Vagrant, Packer, and Ansible
Service Delivery Assembly Line with Vagrant, Packer, and Ansible
 
A Introduction of Packer
A Introduction of PackerA Introduction of Packer
A Introduction of Packer
 
Ansible on aws - Pop-up Loft Tel Aviv
Ansible on aws - Pop-up Loft Tel AvivAnsible on aws - Pop-up Loft Tel Aviv
Ansible on aws - Pop-up Loft Tel Aviv
 
AWS Webcast - Getting Started with AWS OpsWorks
AWS Webcast - Getting Started with AWS OpsWorksAWS Webcast - Getting Started with AWS OpsWorks
AWS Webcast - Getting Started with AWS OpsWorks
 
Learn you some Ansible for great good!
Learn you some Ansible for great good!Learn you some Ansible for great good!
Learn you some Ansible for great good!
 
(DEV301) Automating AWS with the AWS CLI
(DEV301) Automating AWS with the AWS CLI(DEV301) Automating AWS with the AWS CLI
(DEV301) Automating AWS with the AWS CLI
 
Deployment and Management on AWS:
 A Deep Dive on Options and Tools
Deployment and Management on AWS:
 A Deep Dive on Options and ToolsDeployment and Management on AWS:
 A Deep Dive on Options and Tools
Deployment and Management on AWS:
 A Deep Dive on Options and Tools
 
A Hands-on Introduction on Terraform Best Concepts and Best Practices
A Hands-on Introduction on Terraform Best Concepts and Best Practices A Hands-on Introduction on Terraform Best Concepts and Best Practices
A Hands-on Introduction on Terraform Best Concepts and Best Practices
 

Similaire à Immutable AWS Deployments with Packer and Jenkins

대용량 데이타 쉽고 빠르게 분석하기 :: 김일호 솔루션즈 아키텍트 :: Gaming on AWS 2016
대용량 데이타 쉽고 빠르게 분석하기 :: 김일호 솔루션즈 아키텍트 :: Gaming on AWS 2016대용량 데이타 쉽고 빠르게 분석하기 :: 김일호 솔루션즈 아키텍트 :: Gaming on AWS 2016
대용량 데이타 쉽고 빠르게 분석하기 :: 김일호 솔루션즈 아키텍트 :: Gaming on AWS 2016
Amazon Web Services Korea
 

Similaire à Immutable AWS Deployments with Packer and Jenkins (20)

Packer, where DevOps begins
Packer, where DevOps beginsPacker, where DevOps begins
Packer, where DevOps begins
 
대용량 데이타 쉽고 빠르게 분석하기 :: 김일호 솔루션즈 아키텍트 :: Gaming on AWS 2016
대용량 데이타 쉽고 빠르게 분석하기 :: 김일호 솔루션즈 아키텍트 :: Gaming on AWS 2016대용량 데이타 쉽고 빠르게 분석하기 :: 김일호 솔루션즈 아키텍트 :: Gaming on AWS 2016
대용량 데이타 쉽고 빠르게 분석하기 :: 김일호 솔루션즈 아키텍트 :: Gaming on AWS 2016
 
Self Service Agile Infrastructure for Product Teams - Pop-up Loft Tel Aviv
Self Service Agile Infrastructure for Product Teams - Pop-up Loft Tel AvivSelf Service Agile Infrastructure for Product Teams - Pop-up Loft Tel Aviv
Self Service Agile Infrastructure for Product Teams - Pop-up Loft Tel Aviv
 
Amazon ECS Deep Dive
Amazon ECS Deep DiveAmazon ECS Deep Dive
Amazon ECS Deep Dive
 
Deep Dive into AWS SAM: re:Invent 2018 Recap at the AWS Loft - San Francisco
Deep Dive into AWS SAM: re:Invent 2018 Recap at the AWS Loft - San FranciscoDeep Dive into AWS SAM: re:Invent 2018 Recap at the AWS Loft - San Francisco
Deep Dive into AWS SAM: re:Invent 2018 Recap at the AWS Loft - San Francisco
 
Deep Dive into AWS SAM
Deep Dive into AWS SAMDeep Dive into AWS SAM
Deep Dive into AWS SAM
 
A 60-minute tour of AWS Compute (November 2016)
A 60-minute tour of AWS Compute (November 2016)A 60-minute tour of AWS Compute (November 2016)
A 60-minute tour of AWS Compute (November 2016)
 
Containers and the Evolution of Computing
Containers and the Evolution of ComputingContainers and the Evolution of Computing
Containers and the Evolution of Computing
 
Deep Dive:EC2 Container Service
Deep Dive:EC2 Container ServiceDeep Dive:EC2 Container Service
Deep Dive:EC2 Container Service
 
AWS re:Invent 2016: Deploying and Managing .NET Pipelines and Microsoft Workl...
AWS re:Invent 2016: Deploying and Managing .NET Pipelines and Microsoft Workl...AWS re:Invent 2016: Deploying and Managing .NET Pipelines and Microsoft Workl...
AWS re:Invent 2016: Deploying and Managing .NET Pipelines and Microsoft Workl...
 
AWS September Webinar Series - Running Microservices with Amazon EC2 Contain...
AWS September Webinar Series -  Running Microservices with Amazon EC2 Contain...AWS September Webinar Series -  Running Microservices with Amazon EC2 Contain...
AWS September Webinar Series - Running Microservices with Amazon EC2 Contain...
 
Infrastructure as Code: Manage your Architecture with Git
Infrastructure as Code: Manage your Architecture with GitInfrastructure as Code: Manage your Architecture with Git
Infrastructure as Code: Manage your Architecture with Git
 
EC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and PackerEC2 AMI Factory with Chef, Berkshelf, and Packer
EC2 AMI Factory with Chef, Berkshelf, and Packer
 
DevOps on AWS: Deep Dive on Infrastructure as Code - Toronto
DevOps on AWS: Deep Dive on Infrastructure as Code - TorontoDevOps on AWS: Deep Dive on Infrastructure as Code - Toronto
DevOps on AWS: Deep Dive on Infrastructure as Code - Toronto
 
Tech connect aws
Tech connect  awsTech connect  aws
Tech connect aws
 
Monitoring Containers at Scale - September Webinar Series
Monitoring Containers at Scale - September Webinar SeriesMonitoring Containers at Scale - September Webinar Series
Monitoring Containers at Scale - September Webinar Series
 
OpenSource ToolChain for the Hybrid Cloud
OpenSource ToolChain for the Hybrid CloudOpenSource ToolChain for the Hybrid Cloud
OpenSource ToolChain for the Hybrid Cloud
 
AWS Serverless Workshop
AWS Serverless WorkshopAWS Serverless Workshop
AWS Serverless Workshop
 
infrastructure as code
infrastructure as codeinfrastructure as code
infrastructure as code
 
DevOps for the Enterprise: Virtual Office Hours
DevOps for the Enterprise: Virtual Office HoursDevOps for the Enterprise: Virtual Office Hours
DevOps for the Enterprise: Virtual Office Hours
 

Plus de Manish Pandit

OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at NetflixOSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
Manish Pandit
 

Plus de Manish Pandit (20)

Disaster recovery - What, Why, and How
Disaster recovery - What, Why, and HowDisaster recovery - What, Why, and How
Disaster recovery - What, Why, and How
 
Serverless Architectures on AWS in practice - OSCON 2018
Serverless Architectures on AWS in practice - OSCON 2018Serverless Architectures on AWS in practice - OSCON 2018
Serverless Architectures on AWS in practice - OSCON 2018
 
Disaster Recovery and Reliability
Disaster Recovery and ReliabilityDisaster Recovery and Reliability
Disaster Recovery and Reliability
 
OAuth2 primer
OAuth2 primerOAuth2 primer
OAuth2 primer
 
AWS Primer and Quickstart
AWS Primer and QuickstartAWS Primer and Quickstart
AWS Primer and Quickstart
 
Securing your APIs with OAuth, OpenID, and OpenID Connect
Securing your APIs with OAuth, OpenID, and OpenID ConnectSecuring your APIs with OAuth, OpenID, and OpenID Connect
Securing your APIs with OAuth, OpenID, and OpenID Connect
 
Silicon Valley 2014 - API Antipatterns
Silicon Valley 2014 - API AntipatternsSilicon Valley 2014 - API Antipatterns
Silicon Valley 2014 - API Antipatterns
 
Scalabay - API Design Antipatterns
Scalabay - API Design AntipatternsScalabay - API Design Antipatterns
Scalabay - API Design Antipatterns
 
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at NetflixOSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
 
API Design Antipatterns - APICon SF
API Design Antipatterns - APICon SFAPI Design Antipatterns - APICon SF
API Design Antipatterns - APICon SF
 
Motivation : it Matters
Motivation : it MattersMotivation : it Matters
Motivation : it Matters
 
Building Apis in Scala with Playframework2
Building Apis in Scala with Playframework2Building Apis in Scala with Playframework2
Building Apis in Scala with Playframework2
 
Scala at Netflix
Scala at NetflixScala at Netflix
Scala at Netflix
 
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGNIntroducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
 
Evolving IGN’s New APIs with Scala
 Evolving IGN’s New APIs with Scala Evolving IGN’s New APIs with Scala
Evolving IGN’s New APIs with Scala
 
IGN's V3 API
IGN's V3 APIIGN's V3 API
IGN's V3 API
 
Java and the JVM
Java and the JVMJava and the JVM
Java and the JVM
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Silicon Valley Code Camp 2011: Play! as you REST
Silicon Valley Code Camp 2011: Play! as you RESTSilicon Valley Code Camp 2011: Play! as you REST
Silicon Valley Code Camp 2011: Play! as you REST
 
Silicon Valley Code Camp: 2011 Introduction to MongoDB
Silicon Valley Code Camp: 2011 Introduction to MongoDBSilicon Valley Code Camp: 2011 Introduction to MongoDB
Silicon Valley Code Camp: 2011 Introduction to MongoDB
 

Dernier

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 

Immutable AWS Deployments with Packer and Jenkins

  • 1. Immutable AWS Deployments with Packer and Jenkins Scale by the Bay, 2017 Manish Pandit
  • 2. About Manish Pandit Director of Platform Engineering @Marqeta Twitter : @lobster1234 Blog: lobster1234.github.io
  • 3. Show of hands Deployments DevOps, CI/CD, Tooling,.. AWS (or something similar!)
  • 4. Deployments The process of pushing code beyond the development environment Multi-step Usually (heavily) scripted Complete, or Partial
  • 5. Complete Provisioning the stack from ground up Installation of O/S, Runtime, Application Server, Code, Agents, ... # mkfs –t ext4 /dev/sda0 # mkdir /apps # mount –t ext4 /dev/sda0 /apps
  • 6. Partial Very common across the board In-place deployment “Saves time” Gives a false sense of automation
  • 7. Typical Steps ~ scp builds/myService-1.0.2.war mpandit@prd.example.com:/usr/local/tomcat8/webapps ~ ssh mpandit@prd.example.com ~ sudo /usr/local/tomcat8/bin/catalina.sh restart
  • 8. Typical Steps ~ ssh mpandit@prd.example.com ~ wget https://nx.example.com/com/foo/myService.war -O /usr/local/tomcat8/webapps ~ sudo /usr/local/tomcat8/catalina.sh restart
  • 9. Automation? Script this all Run via a Jenkins job Fabric (Python), Capistrano, etc.
  • 10. What could go wrong?
  • 11. What could go wrong? Unpatched, outdated dependencies Inconsistent app behavior Changes outside of the deployment cycle Human Error(s) Does not scale
  • 12. Immutability Build the entire runtime infrastructure from ground up Automate it!
  • 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
  • 20. Install ~ packer -v 1.1.1 ~ Install via brew, or, Download the binary from the packer.io website
  • 21. Credentials EC2 = Use IAM Role for Packer * Non-EC2 = Use AWS Credentials * Packer website has the IAM role details
  • 22. Builders Define Machine Images for many platforms JSON-based Popular : AWS AMI, VMWare, Docker, Azure, GCP… Custom
  • 23. AWS AMI Builder { "_comment":"Simple Packer Template using Amazon Linux 2017.09.0", "variables":{ "aws_access_key":"", "aws_secret_key":"" }, "builders":[ { "type":"amazon-ebs", "access_key":"{{user `aws_access_key`}}", "secret_key":"{{user `aws_secret_key`}}", "region":"us-east-1", "source_ami":"ami-8c1be5f6", "instance_type":"t2.micro", "ssh_username":"ec2-user", "ami_name":"ScaleByTheBay AMI" } ] }
  • 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
  • 26.
  • 27.
  • 28. Provisioners JSON based Install and configure packages and components +many, many more tasks Popular : Ansible, Chef, Puppet, Shell, ..
  • 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
  • 30. Let’s Provision our AMI "provisioners": [{ "type": "shell", "inline": [ "sudo yum update -y", "sudo yum install java-1.8.0 java-1.8.0-openjdk-devel tomcat8-webapps -y", "sudo yum remove java-1.7.0-openjdk -y", "sudo wget https://github.com/lobster1234/helloworld-api/files/953511/helloworld-api.war.gz -O /usr/share/tomcat8/webapps/helloworld-api.war.gz", "sudo gunzip /usr/share/tomcat8/webapps/helloworld-api.war.gz", "sudo chkconfig tomcat8 on" ] }]
  • 31. { "_comment":"Simple Packer Template using Amazon Linux 2017.09.0", "variables":{ "aws_access_key":"", "aws_secret_key":"" }, "builders":[ { "type":"amazon-ebs", "access_key":"{{user `aws_access_key`}}", "secret_key":"{{user `aws_secret_key`}}", "region":"us-east-1", "source_ami":"ami-8c1be5f6", "instance_type":"t2.micro", "ssh_username":"ec2-user", "ami_name":"ScaleByTheBay AMI with Tomcat8" } ], "provisioners": [{ "type": "shell", "inline": [ "sleep 30", "sudo yum update -y", "sudo yum install java-1.8.0 java-1.8.0-openjdk-devel tomcat8-webapps -y", "sudo yum remove java-1.7.0-openjdk -y", "sudo wget https://github.com/lobster1234/helloworld-api/files/953511/helloworld-api.war.gz -O /usr/share/tomcat8/webapps/helloworld- api.war.gz", "sudo gunzip /usr/share/tomcat8/webapps/helloworld-api.war.gz", "sudo chkconfig tomcat8 on" ] }] }
  • 32. Build! ~ packer build packer.json .... ==> amazon-ebs: Connected to SSH! ==> amazon-ebs: Provisioning with shell script: /var/folders/vf/d0q4kjg964581kjjz4969dbny407x7/T/packer-shell539435218 amazon-ebs: Loaded plugins: priorities, update-motd, upgrade-helper amazon-ebs: Resolving Dependencies amazon-ebs: --> Running transaction check amazon-ebs: ---> Package amazon-ssm-agent.x86_64 0:2.1.4.0-1.amzn1 will be updated amazon-ebs: amazon-ebs: 2017-11-11 07:51:33 (64.0 MB/s) - ‘/usr/share/tomcat8/webapps/helloworld-api.war.gz’ saved [1918559/1918559] amazon-ebs: ==> amazon-ebs: Creating the AMI: ScaleByTheBay AMI with Tomcat8 amazon-ebs: AMI: ami-73ed5509 ==> amazon-ebs: Waiting for AMI to become ready... Build 'amazon-ebs' finished. ==> Builds finished. The artifacts of successful builds are: --> amazon-ebs: AMIs were created: us-east-1: ami-73ed5509
  • 33.
  • 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
  • 40. Resources Packer - https://packer.io AWS EC2 - https://aws.amazon.com/documentation/ec2/ My Blog Post - https://tinyurl.com/packer-jenkins