adnichols / kitchen-docker-api

Docker driver for test-kitchen using a ruby based docker client
Other
11 stars 2 forks source link

Add support for custom dockerfile used for container build #1

Closed adnichols closed 10 years ago

adnichols commented 10 years ago

This adds support for fetching a custom Dockerfile either from a local file or a URL (anything compatible with open-uri. The Dockerfile is parsed as erb allowing for more control over the contents of the Dockerfile based on your kitchen config.

damm commented 10 years ago

Any thoughts about docker images instead of just a dockerfile?

So you just pull apt-get update and install chef and run?

adnichols commented 10 years ago

Hey @damm - This allows for that, granted you have to host something that looks like a Dockerfile (though it's not required to be named that). This approach allows for supporting a much broader range of possible variations and platforms. I agree with your approach, my concern is just that the Dockerfile generation method (internal one) is already pretty complex given the # of platforms it supports - having a variant which only updated things would be at least 3 more variants (centos, ubuntu, arch).

My other concern is that if this was just a toggle to enable this behavior it wouldn't be clear what the image dependencies are for test-kitchen to work. In any case, I could see supporting this in the future but I wanted to get the Dockerfile approach in here to allow for any variants that may come along - hopefully reducing the overall complexity required in the driver.

damm commented 10 years ago

Yeah the internal Dockerfile generation is fairly complex and trying to drive home a .kitchen.yml that supports multiple arch's so you can easily test your cookbook on centos, debian and ubuntu?

The problem with the stock images as they are super minimal and as we are adding our own configuration and changes that's roughly 3minutes sucked out of my life. If the Docker cache somehow does not work on the subsequent run that's another 3minutes sucked out.

The complexity is :( I realize I'm basically saying I want to create damm/kitchen-ubuntu and damm/kitchen-centos and damm/kitchen-debian but pulling the images down only happens once and you never have to rebuild them again :) So up front complexity instead of a continual? Does not really sound better but I'm trying to find a way to use kitchen-docker again.

adnichols commented 10 years ago

@damm I feel like I'm missing something. Assuming you can add a Dockerfile to your repository or host it somewhere and include an http URL in .kitchen.yml I believe this change makes your request possible. You can choose how aggressively to cache w/ some erb. Take the following dockerfile for example:

<%
cache_daily = Time.now().strftime("%Y%m%d")
cache_never = Time.now().strftime("%s")
%>
FROM damm/kitchen-ubuntu
RUN apt-get -y update #<%= cache_daily %>
RUN curl -L https://www.opscode.com/chef/install.sh | bash #<%= cache_daily %>
RUN anythingelse #<%= cache_never %>
CMD /bin/bash

Is that not what you are looking for? I realize having this logic built into the build generator is more ideal, but you should be able to do whatever you need in the Dockerfile for any platform you choose to support w/out interference from the driver.

damm commented 10 years ago

@adnichols hrm at that point I would use ONBUILD. Such as:

kitchen-ubuntu's Dockerfile to install this stuff using ONBUILD

ONBUILD RUN apt-get -y update 
RUN curl -L https://www.opscode.com/chef/install.sh | bash
RUN apt-get install openssh-server -y
RUN useradd -m kitchen 
RUN apt-get clean
CMD ["/sbin/init"]

Then the dockerfile would be

FROM damm/kitchen-ubuntu

Yeah I think that would work well.