HashiCorp Packer in Production

Book description

Set up automated workflows to keep systems and applications consistent globally, regardless of architecture, cloud, or container runtime Purchase of the print or Kindle book includes a free PDF eBook

Key Features

  • Automate building and modifying complex software images across multiple OSs and container engines
  • Minimize cost by keeping your systems ready across multiple architectures, including ARM and future RISC-V processors
  • Speed up your time to market by building and testing apps using upstream and future releases

Book Description

Creating machine images can be time-consuming and error-prone when done manually. HashiCorp Packer enables you to automate this process by defining the configuration in a simple, declarative syntax. This configuration is then used to create machine images for multiple environments and cloud providers.

The book begins by showing you how to create your first manifest while helping you understand the available components. You’ll then configure the most common built-in builder options for Packer and use runtime provisioners to reconfigure a source image for desired tasks. You’ll also learn how to control logging for troubleshooting errors in complex builds and explore monitoring options for multiple logs at once. As you advance, you’ll build on your initial manifest for a local application that’ll easily migrate to another builder or cloud. The chapters also help you get to grips with basic container image options in different formats while scaling large builds in production. Finally, you’ll develop a life cycle and retention policy for images, automate packer builds, and protect your production environment from nefarious plugins.

By the end of this book, you’ll be equipped to smoothen collaboration and reduce the risk of errors by creating machine images consistently and automatically based on your defined configuration.

What you will learn

  • Build and maintain consistent system images across multiple platforms
  • Create machine images that can be used in multiple environments
  • Write a spec for a local Packer virtual machine in JSON and HCL
  • Build a container image with Packer in different formats
  • Automate Packer with continuous delivery pipelines
  • Discover how to customize Packer by writing plugins

Who this book is for

This book is for DevOps engineers, Cloud engineers, and teams responsible for maintaining platform and application images for enterprise private, hybrid, or multi-cloud environments. Familiarity with operating systems and virtualization concepts, with or without using a cloud provider, is a prerequisite.

Table of contents

  1. HashiCorp Packer in Production
  2. Foreword
  3. Contributors
  4. About the author
  5. About the reviewers
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Share Your Thoughts
    9. Download a free PDF copy of this book
  7. Part 1: Packer’s Beginnings
  8. Chapter 1: Packer Fundamentals
    1. Technical requirements
    2. Packer architecture
    3. History of Packer
    4. Who uses Packer?
    5. Alternatives to Packer
    6. Installing Packer
    7. HCL versus JSON
      1. Example legacy JSON
      2. Example PKR.JSON
      3. Example HCL
    8. Summary
  9. Chapter 2: Creating Your First Template
    1. Technical requirements
    2. Hello World template for a local VM
    3. Breakdown of components, variables, and artifacts
    4. Using an IDE to guide templates
    5. Applying the VirtualBox builder
    6. Summary
  10. Chapter 3: Configuring Builders and Sources
    1. Technical requirements
    2. Simplifying your template with variables
    3. Utilizing local system builders
      1. Using VirtualBox builders – ISO, OVF, and VM
      2. Using VMware builders – ISO, VMX, and vSphere clone
    4. Using the QEMU builder
    5. Adding cloud builders
      1. Providing your cloud credentials
      2. Using the AWS builders
      3. Using the Azure builders
      4. Using the GCP builders
      5. Exploring other cloud builders
    6. Building containers
      1. Using the null builder
    7. Summary
  11. Chapter 4: The Power of Provisioners
    1. Technical requirements
    2. Configuring communicators
    3. Injecting your config or artifacts
    4. Seeding a file or directory into your image once booted
    5. Using templates to populate configuration resources with variables
    6. Running a script or job across all builders
    7. Developing provisioners with the null builder
    8. Summary
  12. Chapter 5: Logging and Troubleshooting
    1. Technical requirements
    2. Managing stderr and stdout
    3. Using environment variables for logging and debugging
    4. Controlling flow and using breakpoints
    5. Summary
  13. Part 2: Managing Large Environments
  14. Chapter 6: Working with Builders
    1. Technical requirements
    2. Adding applications deployable from vSphere
    3. Adding an AWS EC2 AMI build
      1. Using HashiCorp Vault for credentials
    4. Adding an Azure build
    5. Adding a Google GCP build
    6. Parallel builds
    7. CI testing against multiple OS releases
    8. Pitfalls and things to avoid
    9. Summary
  15. Chapter 7: Building an Image Hierarchy
    1. Technical requirements
    2. Starting with LXC/LXD images
    3. Docker container image format
    4. Podman plugin for the OCI container image format
    5. Base image strategy
    6. Aggregation and branching out multiple pipelines
    7. Summary
  16. Chapter 8: Scaling Large Builds
    1. Technical requirements
    2. Speeding up your builds with parallel processes
    3. Preventing parallel processes from causing DoS
    4. Troubleshooting logs in a parallel world
    5. Using image compression
    6. Selecting a compression algorithm for Packer images
    7. Selecting the right storage type for the image lifecycle
    8. Building delta and patch strategies
    9. Summary
  17. Part 3: Advanced Customized Packer
  18. Chapter 9: Managing the Image Lifecycle
    1. Technical requirements
    2. Tracking image lifecycle
    3. Using the manifest post-processor
    4. Creating a retention policy
    5. Summary
  19. Chapter 10: Using HCP Packer
    1. Technical requirements
    2. Creating an HCP organization
    3. Configuring HCP Packer in your templates
    4. Using HCP ancestry
    5. Consuming HCP Packer from Terraform
    6. Exploring the HCP REST API
    7. Summary
  20. Chapter 11: Automating Packer Builds
    1. Technical requirements
    2. Identifying common automation requirements
    3. Exploring basic GitHub Actions support
    4. Exploring GitLab CI pipeline support
    5. Using HashiCorp Vault integration for automation
      1. GitLab CI
      2. GitHub Actions
    6. Summary
  21. Chapter 12: Developing Packer Plugins
    1. Technical requirements
    2. Basics of Go
    3. Sample plugin source
    4. Building and testing your plugin
    5. Protecting Packer from bad plugins
    6. Summary
    7. Grand conclusion
  22. Index
    1. Why subscribe?
  23. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts
    3. Download a free PDF copy of this book

Product information

  • Title: HashiCorp Packer in Production
  • Author(s): John Boero, Armon Dadgar
  • Release date: July 2023
  • Publisher(s): Packt Publishing
  • ISBN: 9781803246857