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

Packer "shell" provisioner doesn't move files between directories #11873

Closed cristian98149 closed 2 years ago

cristian98149 commented 2 years ago

Community Note

Overview of the Issue

I'm trying to build a Docker image starting from gitlab/gitlab-runner official image. I have two files that are uploaded to the container using "file" provisioner. As docs say, the best way to upload file in root dirs is to upload files in /tmp and move them using "shell" provisioner. This is what I'm trying to do but the shell provisioner doesn't work. The strange thing is that the files disappear from /tmp when shell provisioner is executed and I cannot find them in the entire container.

Reproduction Steps

provisioner "file" {
  source      = "./templates/config.toml"
  destination = "/tmp/config.toml"
}
provisioner "file" {
  source      = "./templates/fargate.toml"
  destination = "/tmp/fargate.toml"
}
provisioner "shell" {
  inline = ["mv /tmp/*.toml /etc/gitlab-runner/"]
}

Packer version

From v1.8.2

Simplified Packer Template

source "docker" "gitlab_runner_manager" {
  image  = "gitlab/gitlab-runner"
  commit = true
}
build {
  name    = "gitlab-runner-manager"
  sources = ["source.docker.gitlab_runner_manager"]
  # add provisioners here.
  provisioner "file" {
    source      = "./templates/config.toml"
    destination = "/tmp/config.toml"
  }
  provisioner "file" {
    source      = "./templates/fargate.toml"
    destination = "/tmp/fargate.toml"
  }
  provisioner "shell" {
    inline = ["mv /tmp/*.toml /etc/gitlab-runner/*.toml"]
  }
}

Operating system and Environment details

Docker container gitlab/gitlab-runner ubuntu based.

Log Fragments and crash.log files

https://gist.github.com/Cristian98149/bc48c801fe81b98bc7360e85b6aee7a3

cristian98149 commented 2 years ago

I discovered that the container image I'm using is mounting a volume, so packer cannot write in it.

github-actions[bot] commented 2 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.