hashicorp / packer

Packer is a tool for creating identical machine images for multiple platforms from a single source configuration.
http://www.packer.io
Other
15.05k stars 3.32k forks source link

File provisioner incorrectly embeds source/ directory into dest when downloading #12193

Open nirvana-msu opened 1 year ago

nirvana-msu commented 1 year ago

Community Note

Overview of the Issue

File provisioner appears to embed source directory within destination when source directotory is specified with a trailing slash, and direction is download, contrary to the docs.

The issue appears to only be present when direction = "download". When uploading, it works as documented.

Reproduction Steps

provisioner "file" {
    direction   = "download"
    source      = "~/source/"
    destination = "./dest"
  }

results in downloading files under ./dest/source/, instead of under ./dest/ as specified in documentation.

Result is the same whether or not destination includes a trailing slash.

Packer version

Packer v1.8.3 (slightly out of date, but I couldn't find any related bug report so haven't tried updating).

Operating system and Environment details

Both source and destination systems run Ubuntu 22.04.

ghost commented 1 year ago

Also happens with Packer 1.8.5. Source OS Arch Linux, target OS Ubuntu 22.04. I used the Hetzner Cloud builder. My reproduction example:

build {
  sources = ["source.hcloud.aufziehvogel"]

  provisioner "shell" {
    inline = ["cloud-init status --wait"]
  }

  provisioner "shell" {
    inline = [
      "mkdir /tmp/debug",
      "touch /tmp/debug/file1",
      "touch /tmp/debug/file2",
    ]
  }

  provisioner "file" {
    direction = "download"
    source = "/tmp/debug/"
    destination = "outdir"
  }
}
nywilken commented 1 year ago

This sounds like a bug for sure. Thanks for reporting.