DevOps and CloudOps Engineer
@h3ct0rjs @c1b3rh4ck
www.devops.com.co
www.linkedin.com/in/h3ct0rjs/
"Tu conocimiento es valioso y tu voz tiene el poder de inspirar, educar y transformar vidas. No guardes tus ideas, compártelas con el mundo y sé el cambio que deseas ver."
In media production, a gold image is the final cut of an album or film after all edits and mixing have been completed. It’s in its final, perfect form–it’s gold.
In our context a golden image is an intentionally configured snapshot of a system, (server, virtual desktop environment, disk drives...) which can be used to deploy new instances.
Sometimes they're also named :
📸
👩💻🧑💻
Contains :
Sometimes terrible images practices accross Cloud Vendors:
https://www.packer.io
Packer lets you create identical machine images for multiple platforms from a single source configuration. A common use case is creating golden images for organizations to use in cloud infrastructure.
* Open Source
* Create Machine Images
* Multi Cloud
* Combine with Config Management Tools
* Highly Performant
* Highly Performant
* Multi-Provider Portability
# Manizales Tech Talks
Name: Packer
Developer: HashiCorp
Initial Release: 2013
First Stable Version: 1.0
Current Version: v1.8.7
Operating System: Linux, FreeBSD, OS X, and Microsoft
Interface: Command line
Website: https://www.packer.io/ [*]
[*] https://www.hashicorp.com/blog/packer-1-0
How does Packer work?
# Manizales Tech Talks
Post-processors run after builders and provisioners. Post-processors are optional, and you can use them to upload artifacts, re-package files, and more.
Builders create machines and generate images from those machines for various platforms. Packer also has some builders that perform helper tasks, like running provisioners.
Provisioners use built-in and third-party software to install and configure the machine image after booting.
Let Packer fetch data to use in a template, including information defined outside of Packer.
Packer Block
Source Block
Build Block
# Manizales Tech Talks
Post-Processors Block
(Optional)
// Required Blocks to create a Golden Image with Packer
packer {
...
}
source {
...
}
build {
...
}
# Manizales Tech Talks
// Required Blocks to create a Golden Image with Packer
packer {
//configure some behaviors of Packer, plugins
//ensure that everyone is using a specific Packer version
...
}
source {
...
}
build {
...
}
# Manizales Tech Talks
// Required Blocks to create a Golden Image with Packer
packer {
required_plugins {
amazon = {
version = ">= 1.2.5 "
source = "github.com/hashicorp/amazon"
}
}
}
source {
...
}
build {
...
}
# Manizales Tech Talks
// Required Blocks to create a Golden Image with Packer
packer {
required_plugins {
amazon = {
version = ">= 1.2.5 "
source = "github.com/hashicorp/amazon"
}
digitalocean = {
version = ">= 1.0.4"
source = "github.com/digitalocean/digitalocean"
}
}
}
# Manizales Tech Talks
// Required Blocks to create a Golden Image with Packer
packer {
//configure some behaviors of Packer
//ensure that everyone is using a specific Packer version
...
}
source {
//What is going to be our source, base image, vhd file
//ami id and so on..
...
}
build {
...
}
# Manizales Tech Talks
// Required Blocks to create a Golden Image with Packer
source "amazon-ebs" "this" {
profile = "profile"
region = "us-east-1"
ami_name = "ami-name"
ami_description = "AMI-Description"
source_ami_filter {
filters = {
virtualization-type = "hvm"
name = "ubuntu/images/ubuntu-xenial-16.04-amd64-server-*"
root-device-type = "ebs"
}
owners = ["099720109477"]
most_recent = true
}
instance_type = "t2.micro"
ssh_username = "ubuntu"
}
# Manizales Tech Talks
// Required Blocks to create a Golden Image with Packer
build {
//Build configurations
//shell scripts
//Config management Cheff, Puppet, Ansible
//Copy of files
//set custom configurations
...
}
# Manizales Tech Talks
// Required Blocks to create a Golden Image with Packer
build {
sources = [ "source.amazon-ebs.this"]
provisioner "shell" {
script = "./provisioner.sh"
}
}
# Manizales Tech Talks
// Required Blocks to create a Golden Image with Packer
build {
sources = [ "source.amazon-ebs.this"]
provisioner "shell" {
script = "./provisioner.sh"
}
provisioner "file" {
source = "app.tar.gz"
destination = "/tmp/app.tar.gz"
}
provisioner "shell-local" {
inline = ["echo foo"]
}
}
# Manizales Tech Talks
// Required Blocks to create a Golden Image with Packer
build {
sources = [ "source.amazon-ebs.this"]
provisioner "ansible" {
playbook_file = "./playbook.yml"
}
provisioner "file" {
source = "app.tar.gz"
destination = "/tmp/app.tar.gz"
}
provisioner "shell-local" {
inline = ["echo foo"]
}
}
# Manizales Tech Talks
Discovery of requirements and purpose to build the Golden Image.software stacks, and configurations needed for the target environment
Begin with a clean and minimal base image provided by the operating system vendor or a trusted source
Apply appropriate security measures to the golden image. This includes patching the operating system, installing security updates, also Remove any default or insecure configurations
Use Version Control Implement version control for golden images to track changes and facilitate rollbacks if needed
Install and configure necessary applications, libraries, and dependencies required by your target environment.
Automate Image Creation, use automation tools to do Image Size Optimization
Testing and Validation and do rollbacks
[*] https://hub.docker.com/r/hashicorp/packer
[1] https://gitlab.com/h3ct0rjs/manizales-tech-talks-packer , check the reference section.
@h3ct0rjs @c1b3rh4ck
h@devops.com.co
www.devops.com.co
www.linkedin.com/in/h3ct0rjs/