Skip to content

Image Build Process for Packer, with files for Azure, GCP and AWS for Linux (Ubuntu, Debian and Redhat) and Windows

License

Notifications You must be signed in to change notification settings

JamesWoolfenden/packer-by-example

Repository files navigation

Packer by Example

Latest Release

By James Woolfenden

Packer-by-example is a collection of Scripts, Ansible, Makefiles and Packer files to help build images in the Public Cloud. It's designed to work with CI/CD systems such as Travis CI, CircleCI and Jenkins, or even at your console. There many different examples for different type of Linux and Windows.

It's 100% Open Source and licensed under the APACHE2.

Introduction

Install

Here's how to get started...

  1. git clone https://github.com/jameswoolfenden/packer-by-example.git to pull down the repository

  2. ./setup-packer.sh to get the tool. Or brew install packer on MacOS or cinst packer on Windows.

Usage

You can run packer directly or if it's HCL2, a folder, otherwise you can use the build wrapper scripts supplied. To run:

./build.sh -p ./packfiles/CentOS/base-aws.json  -e ./environment/personal-jgw.json

Or on Windows:

 .\build.ps1 -packfile .\packfiles\CentOS\base-aws.json -environment .\environment\personal-jgw.json

The environment files hold variables and the packfiles are the packer json templates. I'd prefer not to need the variable files at all but some values must be supplied.

Packer can be used to make an AMI that is pre-built for EC2 with support for Cloudwatch Logs and Metrics:

This Repository contains a number of other examples for using Packer, with software installed for different OS and CloudPlatforms, ready to be configured at launch time.

Instructions for setting up each authenticatiom for Cloud provider are here:

There are examples for Windows and different Linux distributions, and different versions of each. The "packfiles" have examples of using basic features of script or Ansible providers to configure your images, as well as a method for versioning the AMI's.

NEW HCL2

Packer has started adding in support for HCL2, this means that Packer is starting to look and feel like Terraform. It's still very much a in beta.

I have included a working example in the HCL2 folder.

 packer build ./hcl2/ubuntu/

With HCL2 You can separate out builders from the Provisioners.

Troubleshooting

Packer is a tidy tool and to investigate failures you need to tell it not to be. Supply the Debug Flag and the tool will leave the unfinished image behind and the SSH key to connect.

Common issue: SSH is blocked

Some Environments lock down inbound and outbound SSH connections by blocking port 22, 3389. Check you're not making your AMI'S in private subnet and waiting pointlessly.

Help

Got a question?

File a GitHub issue.

Contributing

Bug Reports & Feature Requests

Please use the issue tracker to report any bugs or file feature requests.

Copyrights

Copyright © 2019-2023 James Woolfenden

License

License

See LICENSE for full details.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Contributors

James Woolfenden
James Woolfenden |

About

Image Build Process for Packer, with files for Azure, GCP and AWS for Linux (Ubuntu, Debian and Redhat) and Windows

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published