Skip to content

Automatically create parent folders for files in Windows containers- #208

@wbpascal

Description

@wbpascal

Please search the existing issues for relevant feature requests, and use the
reaction feature
(https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/)
to add upvotes to pre-existing requests.

Community Note

Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request.
Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request.
If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Description

We currently use Packer to create Linux and Windows VM images using the vsphere_clone builder. Now we want to create container images using these same Packer files. This already works with a few small changes for the Linux Containers. However, we are currently having trouble with the Windows containers.

When building the Windows VMs, we heavily rely on the powershell provisioner. For this provisioner, we define both the remote_path and the remote_env_var_path with a path to a file for which the parent folder does not exist at the start of the provisioner. This works with the vsphere_clone builder using the winrm operator. The missing folders in the path chain are simply created. The same goes for the file provisioner. If we give it a destination path that does not yet exist, it simply gets created. The same also seems to go for the file provisioner when building Linux containers; the path is created due to how docker cp behaves.

According to the documentation, the difference in behavior for the file provisioner when building Linux vs. Windows containers is due to docker cp not properly working for Windows containers and therefore PowerShell commands being used as a workaround. It looks like the Upload function of the Windows communicator could be modified to create the parent folder before uploading/copying the file from the temp volume. Therefore, would it be of interest to the plugin if such an (optional) feature that automatically creates the missing folders would be implemented?

Use Case(s)

Allow easier transition from VM builders such as the vsphere_clone to this container builder. Additionally, reduce behavioral differences when execution the file provisioner between Linux and Windows containers.

Potential configuration

Although I do not currently see a use case for relying on the parent folder not being created, we could create a new configuration option in order to not break such cases:

source "docker" "windows" {
    image = "microsoft/windowsservercore:1709"
    windows_container = true
    windows_create_parent_dirs = true
}

If the configuration option windows_create_parent_dirs is set to true, the Windows communicator would create the parent directories during its Upload or UploadDir.

Potential References

https://github.com/hashicorp/packer-plugin-docker/blob/main/docs/builders/docker.mdx#docker-for-windows

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions