github.com/swisspost/terratest@v0.0.0-20230214120104-7ec6de2e1ae0/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  ## Installation steps
    18  1. Install [Packer](https://www.packer.io/) and make sure it's on your `PATH`.
    19  1. Install [Docker](https://www.docker.com/) and make sure it's on your `PATH`.
    20  
    21  
    22  ## Building a Docker image for local testing (Packer >= 1.7.0)
    23  1. Run `packer init build.pkr.hcl`.
    24  1. Run `packer build build.pkr.hcl`.
    25  
    26  
    27  ## Building a Docker image for local testing (Packer < 1.7.0)
    28  1. Run `packer build build.json`.
    29  
    30  
    31  ## Run the container
    32  1. Run `docker compose up`.
    33  1. You should now be able to access the sample web app at http://localhost:8080
    34  
    35  
    36  
    37  
    38  ## Building an AMI for testing in AWS
    39  
    40  1. Sign up for [AWS](https://aws.amazon.com/).
    41  1. Configure your AWS credentials using one of the [supported methods for AWS CLI
    42     tools](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html), such as setting the
    43     `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables.
    44  1. Install [Packer](https://www.packer.io/) and make sure it's on your `PATH`.
    45  1. Run `packer build -only=ubuntu-ami build.json`.
    46  
    47  
    48  
    49  
    50  ## Running automated tests locally against this Packer template
    51  
    52  1. Install [Packer](https://www.packer.io/) and make sure it's on your `PATH`.
    53  1. Install [Docker](https://www.docker.com/) and make sure it's on your `PATH`.
    54  1. Install [Golang](https://golang.org/) and make sure this code is checked out into your `GOPATH`.
    55  1. `cd test`
    56  1. `dep ensure`
    57  1. `go test -v -run TestPackerDockerExampleLocal`
    58  
    59  
    60  
    61  
    62  ## Running automated tests in AWS against this Packer template
    63  
    64  See [terraform-packer-example](/examples/terraform-packer-example).