hashicorp / packer-plugin-docker

Packer plugin for Docker Builder
https://www.packer.io/docs/builders/docker
Mozilla Public License 2.0
31 stars 25 forks source link

docker-push: use isolated client configuration #96

Closed sudomateo closed 2 years ago

sudomateo commented 2 years ago

When running multiple docker-push post processors concurrently, there was a race condition where one docker-push post processor would finish and call docker logout to remove the credentials for a given registry while another docker-push post processor was still running, causing the other docker-push post processor to no longer have access to the registry credentials to perform a docker push.

Since the underlying DockerDriver shells out to raw docker commands, calls to Login store registry credentials in the default Docker client configuration directory. Additionally, calls to Logout remove registry credentials from the default Docker client configuration directory. Since Packer post processors are unaware of each other, one docker-push post processor was removing registry credentials that another docker-push post processor relied on.

These changes modify the docker-push post processor to use a temporary, isolated Docker client configuration directory. This allows each docker-push post processor to store registry credentials in an isolated file that will not be accessed by another docker-push post processor.

The implementation not modify the Driver interface, choosing instead to add an exported field to the DockerDriver type that the docker-push sets.

Closes #81

nywilken commented 2 years ago

I requested a quick spot check from the original poster to validate the fix on their end. I'll give them a little time to respond before merging. Thanks again for the fix.

sudomateo commented 2 years ago

I requested a quick spot check from the original poster to validate the fix on their end. I'll give them a little time to respond before merging. Thanks again for the fix.

Sounds good to me! Thank you for the review!