-
Notifications
You must be signed in to change notification settings - Fork 40
leverage exec for transport and implements connect_to_machine and stop_machine #56
Conversation
if @command && transport.container.info['Config']['Cmd'].join(' ') != @command | ||
transport.container.delete(:force => true) | ||
container = image.run(Shellwords.split(@command)) | ||
container.rename(machine_spec.reference['container_name']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
container = Docker::Container.create('Image' => image.id, 'Cmd' => Shellwords.split(@command), 'name' => container_name)
more convenient way to run container.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its kind of a wash since create
doesn't start the container so either way you have to perform 2 operations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it does https://github.com/swipely/docker-api/blob/master/lib/docker/container.rb#L227 . Anyways it's minor and totally up to you.
@marc- I found a different approach to writing to the container that works on both ubuntu and centos hosts. Just commited it but it writes to the |
Yes, this will work (I actually didn't know, that one can access container's file system this way, good finding).
This is for writing file. And following for reading:
This will work both for local docker daemon and remote. |
squashed and rebased |
end | ||
|
||
args << image.id | ||
args += Shellwords.split("/bin/sh -c 'while true;do sleep 1; done'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have concerns regarding to while
loop here. What if we rather use /bin/sh -l
with -i
docker run
flag instead. Check this:
docker run -i -d ubuntu /bin/sh -l
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are your concerns? changing this to running interactively fundamentally changes how this all flows. I don't think cmd.run_command
would simply return and leave you with a running container.
@@ -70,66 +70,116 @@ def self.connection_url(driver_url) | |||
end | |||
end | |||
|
|||
|
|||
def allocate_machine(action_handler, machine_spec, machine_options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @mwrock - now that chef-boneyard/chef-provisioning#366 is merged you should just be able to use from_image = machine_options.from_image
correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right . As long as this gem takes a dependency on the new version of chef-provisioning.
Hey @mwrock - do you need any help getting this across the finish line? |
It has been a couple weeks, but last I checked this all worked well. The only outstanding issue would be refactoring the Is there anything else here we think needs changing? |
leverage exec for transport and implements connect_to_machine and stop_machine
ah sweet thanks! |
This PR simplifies reconverging and changing the state of running containers by levereging
exec
in the transport. It also implementsconnect_to_machine
and thus allows one to use themachine_execute
andmachine_file
resources on docker containers.This ended up being bringing in some fairly deep changes so here are some implementation notes:
Gemfile.lock
and adds basic entries to the empty.gitignore
file to provide a better dev experience.readme
example with thessh_server
cookbook. Currently the apache example fails to start the container. Theapache::default
recipe is empty and the command/usr/sbin/httpd
is not applicable to theubuntu
base image used. Even using/usr/sbin/apache2
and theapache2::default
cookbook had some config errors. Thessh_server
cookbook just worked and results in a running container.execute_old
code deleted over a year ago and I found it added confusion to the class.machine_allocate
and simple runs a vanilla bash loop as suggested by @marc- .machine_allocate
now creates the container but it is "unconverged" and not running the final command. However it does have the ports, volumes, etc properly configured.Docker::Container.exec
/var/lib/docker
stream_chunk
docker_container_machine
commits images after convergence and if the command has changed, starts a new containerOne thing that is a definite hack and I think is due to a bug in chef-provisioning is this line in
allocate_machine
:from_image
is not set in the provider until after the call toallocate_machine
I'll submit a separate PR to chef-provisioning to address tis unless someone thinks this is necessary.