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.09k stars 3.33k forks source link

Packer fails to run shell provisioner with Docker #1894

Closed jcarapet closed 9 years ago

jcarapet commented 9 years ago

This looks like a repeat of a couple issues, but I am getting a slightly different output from the following. https://github.com/mitchellh/packer/issues/1752 https://github.com/mitchellh/packer/issues/1782

Components:

Template.json file looks as such

{
    "builders": [
    {
        "type": "docker",
        "image": "jenkins",
        "commit": true
        }],
    "provisioners": [
    {
        "type": "shell",
        "inline": [
        "echo foo"]
    }]
}

Problem lies in that whenever I try to provision it with a shell script it gets stuck at the provisioning step

 ==> docker: Provisioning with shell script: /tmp/packer-shell580127490 

I have tried this with Docker 1.4.1 and Packer 0.5.1 as well. I can run the same command through terminal and it will build container.

sethvargo commented 9 years ago

Hi there,

This is either a duplicate of https://github.com/mitchellh/packer/issues/1752 or potentially https://github.com/mitchellh/packer/issues/1804. Do you see any additional output when you run packer? Could you supply the debug output please?

nathwill commented 9 years ago

i've been seeing this as well with packer 0.7.5 and docker 1.3.2-2.fc21.

here's the debug output:

2015/03/05 18:08:02 ui:     workspaces_console: [2015-03-06T02:08:02+00:00] INFO: Chef Run complete in 2947.116752103 seconds
2015/03/05 18:08:02 ui:     workspaces_console: [2015-03-06T02:08:02+00:00] INFO: Skipping removal of unused files from the cache
2015/03/05 18:08:02 ui:     workspaces_console: [2015-03-06T02:08:02+00:00] INFO: Running report handlers
2015/03/05 18:08:02 ui:     workspaces_console: [2015-03-06T02:08:02+00:00] INFO: Report handlers complete
2015/03/05 18:08:03 packer-builder-docker: 2015/03/05 18:08:03 Executed command exit status: 0
2015/03/05 18:08:04 packer-builder-docker: 2015/03/05 18:08:04 [INFO] RPC endpoint: Communicator ended with: 0
2015/03/05 18:08:04 [INFO] 0 bytes written for 'stderr'
2015/03/05 18:08:04 [INFO] 43435 bytes written for 'stdout'
2015/03/05 18:08:04 [INFO] RPC client: Communicator ended with: 0
2015/03/05 18:08:04 [INFO] RPC endpoint: Communicator ended with: 0
2015/03/05 18:08:04 packer-provisioner-chef-solo: 2015/03/05 18:08:04 [INFO] RPC client: Communicator ended with: 0
2015/03/05 18:08:04 packer-provisioner-chef-solo: 2015/03/05 18:08:04 [INFO] 0 bytes written for 'stderr'
2015/03/05 18:08:04 packer-provisioner-chef-solo: 2015/03/05 18:08:04 [INFO] 43435 bytes written for 'stdout'
2015/03/05 18:08:04 ui: ==> workspaces_console: Uploading tests => /tmp
2015/03/05 18:08:04 packer-builder-docker: 2015/03/05 18:08:04 Executing in container 89e30ca5b06a3e8c6cf80fbdc052a2223691956165e57e9e84fdd03676a4e10a: "(set -e; mkdir -p /tmp/tests; cp -R /packer-files/dirupload105353668/* /tmp/tests) >/packer-files/cmd313436243 2>&1; echo $? >/packer-files/cmd313436243-exit"
2015/03/05 18:08:06 packer-builder-docker: 2015/03/05 18:08:06 Waiting for exit code to appear for remote command...
2015/03/05 18:08:07 packer-builder-docker: 2015/03/05 18:08:07 Executed command exit status: 0
2015/03/05 18:08:08 ui: ==> workspaces_console: Provisioning with shell script: scripts/validate.sh
2015/03/05 18:08:08 packer-provisioner-shell: 2015/03/05 18:08:08 Opening scripts/validate.sh for reading
2015/03/05 18:08:08 packer-provisioner-shell: 2015/03/05 18:08:08 [INFO] 119 bytes written for 'uploadData'
2015/03/05 18:08:08 [INFO] 119 bytes written for 'uploadData'
2015/03/05 18:08:08 packer-builder-docker: 2015/03/05 18:08:08 Executing in container 89e30ca5b06a3e8c6cf80fbdc052a2223691956165e57e9e84fdd03676a4e10a: "(cp /packer-files/upload748437398 /tmp/script.sh) >/packer-files/cmd523900925 2>&1; echo $? >/packer-files/cmd523900925-exit"
2015/03/05 18:08:10 packer-builder-docker: 2015/03/05 18:08:10 Waiting for exit code to appear for remote command...
2015/03/05 18:08:10 packer-builder-docker: 2015/03/05 18:08:10 Command stdout: "cp: overwrite '/tmp/script.sh'? "
nathwill commented 9 years ago

after a bit of digging, looks like i was caught by #1712

nathwill commented 9 years ago

so, for any other poor souls bit by EL's "helpful" aliases, it's basically impossible to get packer to override the aliases once they're sourced until the patched version that uses "command" to escape the aliases comes out (or you build your own packer binary with the patch included), but you can stop them from being sourced at all by updating the docker builder's run_command to invoke bash with the --noprofile and --norc options.

jcarapet commented 9 years ago

nathwill, thanks for following up with this. I will have to look at this issue. I

@sethvargo, At this point based on duplicate ticket, and my work putting this on hold for a bit, you are welcome to close the ticket.