This change ensures the deletion of the external envVarFile (use_env_var_file = true) occurs after all script files have been executed and deleted. Build results before change ``` > packer build build.pkr.hcl [~0] docker: output will be in this color. ==> docker: Creating a temporary directory for sharing data... ==> docker: Pulling Docker image: ubuntu:bionic docker: bionic: Pulling from library/ubuntu docker: Digest: sha256:8d31dad0c58f552e890d68bbfb735588b6b820a46e459672d96e585871acc110 docker: Status: Image is up to date for ubuntu:bionic docker: docker.io/library/ubuntu:bionic ==> docker: Starting docker container... docker: Run command: docker run -v /home/wilken/.packer.d/tmp476880774:/packer-files -d -i -t --entrypoint=/bin/sh -- ubuntu:bionic docker: Container ID: 812069b4d70746a6d4592a8f75c06867c6774b8b0bd81ade76eae7926a30f64b ==> docker: Using docker communicator to connect: 172.17.0.2 ==> docker: Provisioning with shell script: sample.sh docker: Sample Script docker: wilken is NotForSale! ==> docker: Provisioning with shell script: foobar.sh ==> docker: /bin/sh: 1: .: Can't open /tmp/varfile_2555.sh ==> docker: Provisioning step had errors: Running the cleanup provisioner, if present... ==> docker: Killing the container: 812069b4d70746a6d4592a8f75c06867c6774b8b0bd81ade76eae7926a30f64b Build 'docker' errored: Script exited with non-zero exit status: 2.Allowed exit codes are: [0] ==> Some builds didn't complete successfully and had errors: --> docker: Script exited with non-zero exit status: 2.Allowed exit codes are: [0] ==> Builds finished but no artifacts were created. ``` Build results after change ``` > packer build build.pkr.hcl docker: output will be in this color. ==> docker: Creating a temporary directory for sharing data... ==> docker: Pulling Docker image: ubuntu:bionic docker: bionic: Pulling from library/ubuntu docker: Digest: sha256:8d31dad0c58f552e890d68bbfb735588b6b820a46e459672d96e585871acc110 docker: Status: Image is up to date for ubuntu:bionic docker: docker.io/library/ubuntu:bionic ==> docker: Starting docker container... docker: Run command: docker run -v /home/wilken/.packer.d/tmp819845000:/packer-files -d -i -t --entrypoint=/bin/sh -- ubuntu:bionic docker: Container ID: d8ed9100ff5017379bfc0d80703b2b2d10c4104941663aa5ddbbf18f6dcf74a5 ==> docker: Using docker communicator to connect: 172.17.0.2 ==> docker: Provisioning with shell script: sample.sh docker: Sample Script docker: wilken is NotForSale! ==> docker: Provisioning with shell script: foobar.sh docker: FooBar Script docker: wilken is NotForSale! ==> docker: Committing the container docker: Image ID: sha256:a412e43f134431f2049a7d06d5d691aad3717d91dd2ee5e2575e05b89384a4b3 ==> docker: Killing the container: d8ed9100ff5017379bfc0d80703b2b2d10c4104941663aa5ddbbf18f6dcf74a5 Build 'docker' finished. ==> Builds finished. The artifacts of successful builds are: --> docker: Imported Docker image: sha256:a412e43f134431f2049a7d06d5d691aad3717d91dd2ee5e2575e05b89384a4b3 ```
Packer
- Website: https://www.packer.io
- IRC:
#packer-tool
on Freenode - Mailing list: Google Groups
Packer is a tool for building identical machine images for multiple platforms from a single source configuration.
Packer is lightweight, runs on every major operating system, and is highly performant, creating machine images for multiple platforms in parallel. Packer comes out of the box with support for many platforms, the full list of which can be found at https://www.packer.io/docs/builders/index.html.
Support for other platforms can be added via plugins.
The images that Packer creates can easily be turned into Vagrant boxes.
Quick Start
Note: There is a great introduction and getting started guide for those with a bit more patience. Otherwise, the quick start below will get you up and running quickly, at the sacrifice of not explaining some key points.
First, download a pre-built Packer binary for your operating system or compile Packer yourself.
After Packer is installed, create your first template, which tells Packer
what platforms to build images for and how you want to build them. In our
case, we'll create a simple AMI that has Redis pre-installed. Save this
file as quick-start.json
. Export your AWS credentials as the
AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
environment variables.
{
"variables": {
"access_key": "{{env `AWS_ACCESS_KEY_ID`}}",
"secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}"
},
"builders": [{
"type": "amazon-ebs",
"access_key": "{{user `access_key`}}",
"secret_key": "{{user `secret_key`}}",
"region": "us-east-1",
"source_ami": "ami-af22d9b9",
"instance_type": "t2.micro",
"ssh_username": "ubuntu",
"ami_name": "packer-example {{timestamp}}"
}]
}
Next, tell Packer to build the image:
$ packer build quick-start.json
...
Packer will build an AMI according to the "quick-start" template. The AMI will be available in your AWS account. To delete the AMI, you must manually delete it using the AWS console. Packer builds your images, it does not manage their lifecycle. Where they go, how they're run, etc., is up to you.
Documentation
Comprehensive documentation is viewable on the Packer website:
Developing Packer
See CONTRIBUTING.md for best practices and instructions on setting up your development environment to work on Packer.