ansible-container
ansible-container copied to clipboard
Support Mechanism for .dockerignore
DESCRIPTION
I have several files that I don't want copied into the container, like .git, .vagrant, node_modules/, that will significantly fatten the container, or in the case of compiled code, such as local node module like bcrypt, I would want linux node_modules, not Mac OS X version. Please have a mechanism to .dockerignore.
In a Dockerfile, I could specify something like this
ENV APP_ROOT /usr/src/app
RUN mkdir -p ${APP_ROOT}/
COPY . ${APP_ROOT}/
In Ansible-container, my work around is to do something like this:
- hosts: express
vars:
app_root: "/usr/src/app"
tasks:
- name: Make APP_ROOT direcotry
file: name="{{ app_root }}" state=directory recurse=true
- name: Copy Source to APP_ROOT
copy: src="{{ lookup('pipe','dirname `pwd`') }}/" dest="{{ app_root }}"
- name: Apply .dockerignore
shell: /bin/cat .dockerignore | /usr/bin/xargs -n 1 rm -rf
args:
chdir: "{{ app_root }}"
Not sure how/where we would implement this. Ansible Container runs the main.yml playbook. It does not interpret it or attempt to examine what it does. It doesn't know whether or not files were copied, where they might have been copied to, etc.
Maybe I'm missing something, but it seems this would need to be a module parameter. Maybe a new parameter on the copy module?
I was thinking about this and how to solve it. Within the scope of this project, I thought of two ideas; this might be crazy: Have a layer above main.yml, that creates the playbook, and provides some of the Dockerfile usability. Another idea, is to have some perhaps, ansible-container specific modules (or something that looks like modules) that provides the same functionality.
Outside this project scope, it would be nice if the copy could support an exception list. I could write an enhancement request, cite this use case, and hopefully with some evangelism from this team, we can get it in there.
Another idea, is a mixture of both, have docker_copy, which in turn calls copy with an exception list from items in the .dockerignore.
Both are really good ideas - thank you for putting some thought into this.
I'm disinclined to support the creation of a docker-specific copy module... the least amount of specialization needed for Ansible Container, I think the more likely the project is to be successful. We could, upon run, duplicate the project directory into temp-space, honoring the .dockerignore, and mount that temp directory - but that has performance implications. And any changes to the copy module would have to wait until 2.2 at the earliest, so that's not an awesome solution. I'm going to leave this open as an enhancement while we continue to brainstorm. Thank you for reporting this!
Any Update?
You could give a try to rsync, kind of
rsync -azP --delete --filter=":- .gitignore" <SRC> <DEST>
on example above, rsync about to ignore files/paths specified in git ignore.