github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/examples/packer-docker-example/README.md (about) 1 # Packer Docker Example 2 3 This folder contains a Packer template to demonstrate how you can use Terratest to write automated tests for your 4 Packer templates. The template creates an Ubuntu AMI with a simple web app (built on top of Ruby / Sinatra) installed. 5 This template _also_ creates a Docker image with the same web app installed, and contains a `docker-compose.yml` file 6 for running that Docker image. These allow you to test your Packer template completely locally, without having to 7 deploy to AWS. 8 9 Check out [test/packer_docker_example_test.go](/test/packer_docker_example_test.go) to see how you can write 10 automated tests for this simple template. 11 12 The Docker-based tests in this folder are in some sense "unit tests" for the Packer template. To see an example of 13 "integration tests" that deploy the AMI to AWS, check out the 14 [terraform-packer-example](/examples/terraform-packer-example). 15 16 17 18 19 ## Building a Docker image for local testing 20 21 1. Install [Packer](https://www.packer.io/) and make sure it's on your `PATH`. 22 1. Install [Docker](https://www.docker.com/) and make sure it's on your `PATH`. 23 1. Run `packer build -only=ubuntu-docker build.json`. 24 1. Run `docker-compose up`. 25 1. You should now be able to access the sample web app at http://localhost:8080 26 27 28 29 30 ## Building an AMI for testing in AWS 31 32 1. Sign up for [AWS](https://aws.amazon.com/). 33 1. Configure your AWS credentials using one of the [supported methods for AWS CLI 34 tools](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html), such as setting the 35 `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables. 36 1. Install [Packer](https://www.packer.io/) and make sure it's on your `PATH`. 37 1. Run `packer build -only=ubuntu-ami build.json`. 38 39 40 41 42 ## Running automated tests locally against this Packer template 43 44 1. Install [Packer](https://www.packer.io/) and make sure it's on your `PATH`. 45 1. Install [Docker](https://www.docker.com/) and make sure it's on your `PATH`. 46 1. Install [Golang](https://golang.org/) and make sure this code is checked out into your `GOPATH`. 47 1. `cd test` 48 1. `dep ensure` 49 1. `go test -v -run TestPackerDockerExampleLocal` 50 51 52 53 54 ## Running automated tests in AWS against this Packer template 55 56 See [terraform-packer-example](/examples/terraform-packer-example).