fgrehm / ventriloquist

Development environments made easy
MIT License
359 stars 20 forks source link

a way to pass arguments to the docker files #17

Closed danmayer closed 11 years ago

danmayer commented 11 years ago

I was trying to start up a file using -h and a hostname

https://github.com/dotcloud/docker/issues/243

I don't see a way to pass any option to the docker images when using ventriloquist

basically I have

env.services << {
  graphite: { image: 'nickstenning/graphite' },
  statsd: { image: 'danmayer/statsd' }
}

was thinking

env.services << {
  graphite: { image: 'nickstenning/graphite' },
  statsd: { image: 'danmayer/statsd', h:my.hostname.net }
}

could make statsd run like docker run -h my.hostname.net danmayer/statsd

Or some other way to inject options... Thoughts?

fgrehm commented 11 years ago

I can't test this right now but I think you should be able to provide a cmd parameter to the service hash in order to do that. I need to document this somewhere but Ventriloquist builds on top of [Vocker]() and Vocker supports a cmd parameter as you can see on the README

Something along the lines of:

env.services << {
  graphite: { image: 'nickstenning/graphite' },
  statsd: { image: 'danmayer/statsd', cmd: 'YOUR_CMD -h my.hostname.net' }
  # OR this if you have an ENTRYPOINT set
  statsd: { image: 'danmayer/statsd', cmd: '-h my.hostname.net' }
}

Please LMK if it works :)

danmayer commented 11 years ago

awesome headed out tonight, but will try that tomorrow morning. Thanks

danmayer commented 11 years ago

thanks that does pass through unfortunately it looks like I am not grabbing and using the param correctly but this should let me pass in data.

4c56a14fa74a579e05b49586f7db0f11b05162a1cc9d84d96f8c7c05daee8398   danmayer/statsd:latest                      node /statsd-0.6.0/stats.js /data/config.js -h utils.mysite.com

I am going to explain what I am trying to do as you might have a better way. Opposed to actually passing in a pre known host name I want to pass in the hostname of the current host machine that this docker will be set up on. Basically this is because I was trying to make the statsd docker point to the graphite docker and it seems to fail when statsd uses a config with localhost (assuming that ends up at localhost inside that container which doesn't have graphite). It works if I change the config to point to the host machine's hostname. So I feel like I might be trying to solve this the wrong way.

For now I got it working but I did that by combining the graphite and statsd dockerfiles into a single dockerfile that does both as then the localhost hits the graphite setup in the same container.

fgrehm commented 11 years ago

I'll try one thing before getting back to you but I'm thinking that this issue might be better suited on Vocker's issue tracker unless there is some additional logic you need to be performed when those services are configured (like installing additional packages on the guest vm similar to the postgres service)

If I got it right this is only related to provisioning VMs with docker images that is Vocker's job :)

WDYT?

danmayer commented 11 years ago

yeah I think at this point your right it is getting out of scope of that ventriloquist does. I figured you might know a bit better way to achieve what I am doing. I think since I can now pass args when starting up docker images that covers what ventriloquist should do. The only feature that might make sense if a way to collect information about the host machine after installing docker prior to running commands

env.ventriloquist_host = Ventriloquist.fetch_environment['host']

If it isn't clear, I am using ventriloquist with vagrant with AWS as a provider which is why I don't know the host name until the machine comes up.

That still might be out of scope for this tool though.

By the way thanks for the awesome tool really enjoying it.

fgrehm commented 11 years ago

Tks for the kind words, I'm glad you liked the project :)

Just throwing in an idea: wouldn't you be able to use Vagrant to configure a pre-defined hostname with config.vm.hostname and use the same value when running the container? Something like:

HOSTNAME = 'my.hostname.net'
Vagrant.configure("2") do |config|
  config.vm.hostname = HOSTNAME
  config.vm.provision :ventriloquist do |env|
    env.services << {
      graphite: { image: 'nickstenning/graphite' },
      statsd: { image: 'danmayer/statsd', cmd: "CMD -h #{HOSTNAME}" }
    }
  end
end

Another option would be to "calculate" the argument during runtime:

Vagrant.configure("2") do |config|
  config.vm.provision :ventriloquist do |env|
    env.services << {
      graphite: { image: 'nickstenning/graphite' },
      statsd: { image: 'danmayer/statsd', cmd: "CMD -h $(hostname -f)" }
    }
  end
end

I just did some experimenting and as tricky as it might look like it works :P

vagrant@dev:~$ hostname
dev.ventriloquist.vagrant

vagrant@dev:~$ sudo docker run busybox hostname
c23df763f6f8

vagrant@dev:~$ sudo docker run busybox echo $(hostname -f)
dev.ventriloquist.vagrant

Not sure if it solves your problem but at least I learned something new :P

danmayer commented 11 years ago

Marking this closed as I think this solved the various issues I was having. Thanks

fgrehm commented 11 years ago

Awesome :)

danmayer commented 11 years ago

I am sure you will see that I sent a related PR over to the vocker project. As I can now pass various args to the command, I think there is still cases where you want to pass args to docker itself. Anyways, I think it is different enough that I didn't tack it on to this thread ;)