Open ghost opened 3 years ago
I think this should be way better with HCL2 config files. Please tell me if that is not the case. We'll soon close this issue otherwise.
I've noticed the same issue in my.pkr.hcl
changes = [
"ENTRYPOINT [\"powershell.exe\", \"-NoProfile\", \"-ExecutionPolicy\", \"Bypass\", \"-Command\", \"C:\\entrypoint.ps1\", \";\"]"
]
which generates
"Entrypoint": [
"cmd /S /C [\"powershell.exe\", \"-NoProfile\", \"-ExecutionPolicy\", \"Bypass\", \"-Command\", \"C:\\entrypoint.ps1\", \";\"]"
],
Changing my.pkr.hcl
to
changes = [
"ENTRYPOINT [\"powershell.exe\", \"-NoProfile\", \"-ExecutionPolicy\", \"Bypass\", \"-Command\", \"Set-Location\", \"C:/\", \";\"]",
"CMD [\"./entrypoint.ps1\"]"
]
seems to be the right workaround and it generates correct syntax:
"Cmd": [
"./entrypoint.ps1"
],
"Entrypoint": [
"powershell.exe",
"-NoProfile",
"-ExecutionPolicy",
"Bypass",
"-Command",
"Set-Location",
"C:/",
";"
],
By the way, there is this old issue which also touches on this topic, but the documented syntax does not seem working, https://github.com/hashicorp/packer/issues/8225
$ packer version
Packer v1.8.7
$ packer plugins installed
C:\Users\MateuszL\AppData\Roaming\packer.d\plugins\github.com\hashicorp\docker\packer-plugin-docker_v1.0.8_x5.0_windows_amd64.exe
This issue was originally opened by @Yoshiiiiiii as hashicorp/packer#9092. It was migrated here as a result of the Packer plugin split. The original body of the issue is below.
The docker builder for windows images behaves unexpected when trying to change the ENTRYPOINT and CMD of the image. Double backslash breaks exec form of changes and turns it into shell form. Escaping the backslash with another backslash felt like a thing that should have worked.
Overview of the Issue
I was trying to build an image that executes a powershell script on startup. I tried to change the ENTRYPOINT and the CMD the following way:
This resulted in the following image:
So it turned the change of the CMD into shell form.
"CMD [\"./Start.ps1\"]"
does work. It took a while to figure this out. I couldn't find anything in the docs that adresses this. Maybe it was just me approaching this the wrong way.Before doing it correct I tried this:
which resulted into this via docker inspect:
So the WORKINGDIR is translated into double backslashes from docker. And you can see that the backslashes also break the exec form of the ENTRYPOINT.
Reproduction Steps
Try to escape '\' in a change like this '\\' and the docker builder is not able to detect the exec form of the CMD. Same with the ENTRYPOINT.
Packer version
From
packer_1.5.5_windows_amd64
.Simplified Packer Buildfile
Operating system and Environment details
Windows Server 2019 Datacenter