You may be able to get the behavior you want by setting `keep_input_artifact` in your shell-local post-processor. https://www.packer.io/docs/templates/post-processors.html#input-artifacts
On Mon, Nov 19, 2018 at 7:49 AM <[email protected]> wrote: > I'm trying to get Packer to build a Docker image, then run a container > from that image and execute a few tests against the running container > _before_ pushing the image back to a Docker registry. I want to _only_ > push the image if tests pass. Otherwise, I want the build to fail and > _not_ push anything. > > I've tried putting a "shell-local" post-processing step in between the > "docker-tag" and the "docker-push" post-processing steps (pasted below). > The tests run as expected, but then the build fails on "docker-push" with > "Can only import from docker-import and docker-tag artifacts". This makes > sense I guess - I lose the Docker artifact once I run the shell-local step > so it doesn't know what I'm asking it to push. I've explored "manifest" > and "artifice" post-processors among other things but I haven't yet figured > out how to make it work the way I want. > > Is what I'm trying to do possible with Packer? > > Thanks! > > ... > "builders": [ > { > "type": "docker", > "image": "{{user `base_image_repository`}}:latest", > "commit": true, > "ecr_login": true, > "login_server": "{{user `ecr_login_server`}}", > "changes": [ > "CMD /opt/app/run.sh" > ] > } > ], > "provisioners": [ > ... > ], > "post-processors": [ > [ > { > "type": "docker-tag", > "repository": "{{user `docker_repository`}}", > "tag": "{{user `version`}}" > }, > { > "type": "shell-local", > "script": "./test-container.sh", > "environment_vars": ["IMAGE_AND_TAG={{user > `docker_repository`}}:{{user `version`}}", "LEVEL={{user `level`}}"] > }, > { > "type": "docker-push", > "ecr_login": true, > "login_server": "{{user `ecr_login_server`}}" > } > ] > ] > } > > -- > This mailing list is governed under the HashiCorp Community Guidelines - > https://www.hashicorp.com/community-guidelines.html. Behavior in > violation of those guidelines may result in your removal from this mailing > list. > > GitHub Issues: https://github.com/mitchellh/packer/issues > IRC: #packer-tool on Freenode > --- > You received this message because you are subscribed to the Google Groups > "Packer" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/packer-tool/08bec5d1-4c5e-4161-b0b6-cca6de9ae533%40googlegroups.com > <https://groups.google.com/d/msgid/packer-tool/08bec5d1-4c5e-4161-b0b6-cca6de9ae533%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list. GitHub Issues: https://github.com/mitchellh/packer/issues IRC: #packer-tool on Freenode --- You received this message because you are subscribed to the Google Groups "Packer" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/CAGPV1ursoBfNBoJ2%3DXxP-KtSefpDtfOCzt_dh6xHCvrQQ4hX%2Bg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
