ansible / ansible-container

DEPRECATED -- Ansible Container was a tool to build Docker images and orchestrate containers using only Ansible playbooks.
GNU Lesser General Public License v3.0
2.19k stars 394 forks source link

Do we need temporary directories? #188

Open concaf opened 8 years ago

concaf commented 8 years ago

Hi,

A docker compose file relies on relative paths, like in case of build, volumes, env_file directives. Since we copy the generated docker compose file to a temporary directory under /tmp/, the relative files also have to be copied. This operation could be time consuming in some cases.

Does it make sense to not use temporary directories and supply docker compose files as python objects or some such?

Thoughts? Pointers?

chouseknecht commented 8 years ago

We should not need to copy files. In docker/engine.py the orchestrate() method sets the project path to the project base_path + '/ansible'. It should find the files. If it's not, then we're doing something wrong.

project = project_from_options(self.base_path + '/ansible', options)

Do you have an example where this is not working?

dustymabe commented 8 years ago

one example where this is a problem is where docker compose files have the build directive set and a relative path to a build context directory specified. Right now ansible-container creates a temporary directory and then creates a docker-compose file in there and then does a docker-compose up: https://github.com/ansible/ansible-container/blob/f5f425aaf40aec4d948d629a1201c349c63931b3/container/docker/engine.py#L776-L786

It appears that even though the real CWD is in the right location, docker-compose actually takes the relative path to be relative to the specified docker compose file (which is in /tmp/) and not CWD. This seems to be further proven by the comments in https://github.com/docker/compose/issues/3568

It looks like if we want this to work we need to put the templated out docker-compose file into the same directory as the original container.yml file was.

chouseknecht commented 8 years ago

Or, since we're constructing the docker-compose anyway, we could inspect the build: directive and turn the context path into an absolute path.

dustymabe commented 8 years ago

Or, since we're constructing the docker-compose anyway, we could inspect the build: directive and turn the context path into an absolute path.

Absolute paths probably won't work since only the CWD gets bind mounted inside the ansible-container container.

chouseknecht commented 8 years ago

No. We call the compose up method to start all of the containers, and that's where the build would occur. It would be handled by the compose module, and thus outside of the Ansible build container. In fact, the Ansible process inside the build container never looks at the container.yml file. So in fact, we could alter the container.yml file in the temp directory, making the context path an absolute path.