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

builder: force an empty cmd/entrypoint if unset #177

Closed lbajolet-hashicorp closed 1 month ago

lbajolet-hashicorp commented 1 month ago

The code to set the default values for cmd/entrypoint in order to inherit what was set from the original image was working well if both the cmd and entrypoint were set, but if the entrypoint was null, the resulting image would inherit the temporary container's, which was /bin/sh.

This resulted in some images being built incorrectly, with /bin/sh as entrypoint, regardless of what we had as CMD/ENTRYPOINT in this case.

To fix this issue, we return a JSON array with an empty string if the entrypoint or the CMD was null in the image, and we haven't decided to override it.

This effectively forces the resulting image to have an equivalent of null as the CMD/ENTRYPOINT, which makes the final image honour the behaviour from the source image.

Closes #176

cc: @gardar for insights, as you had submitted the implementation originally, this fixes the case where there's some null in the base image, please refer to the linked issue for a summary of the problem, if you have suggestions regarding my code please feel free to share!