Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker_compose does not allow to choose the project-directory when specifying more than one docker-compose file #48648

Closed
giovannipizzi opened this issue Nov 14, 2018 · 13 comments
Labels
affects_2.7 This issue/PR affects Ansible v2.7 bot_closed bug This issue/PR relates to a bug. cloud collection:community.general collection Related to Ansible Collections work docker module This issue/PR relates to a module. needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md support:community This issue/PR relates to code supported by the Ansible community.

Comments

@giovannipizzi
Copy link

SUMMARY

When specifying more than one file in the docker_service, the project-directory is assumed to be the one of the first docker-compose.yml file provided, and cannot be changed (even if project_src is provided).

ISSUE TYPE
  • Bug Report
COMPONENT NAME

docker_service

ANSIBLE VERSION
ansible 2.7.1
  config file = None
  configured module search path = [u'/Users/pizzi/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/pizzi/.virtualenvs/generic/lib/python2.7/site-packages/ansible
  executable location = /Users/pizzi/.virtualenvs/generic/bin/ansible
  python version = 2.7.10 (default, Oct  6 2017, 22:29:07) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)]
CONFIGURATION
OS / ENVIRONMENT

Mac OS 10.13.6, but also happens on Ubuntu Linux 16.04 and 18.04
Using docker-compose==1.23.1 from pip

STEPS TO REPRODUCE

Inside a folder, create two subfolders a and b.
Inside folder a, put the following docker-compose.yml file:

version: '2'
services: 
  a:
    image: busybox

Inside folder b, put the following docker-compose.yml file:

version: '2'
services: 
  b:
    build: ./dir

and finally inside the b folder, create a b/dir subfolder containing a Dockerfile with only the following line:

FROM busy box

The playbook to run (and to put in the b folder) is:

- name: test
  hosts: localhost

  tasks:
  - name: docker-compose build and up
    docker_service:
      state: present
      build: True
      project_src: "./"
      project_name: 'c'
      restarted: True
      files:
      - ../a/docker-compose.yml
      - ./docker-compose.yml
EXPECTED RESULTS

The two docker-compose files are used, and the current folder is used as project-directory as well (i.e. the Dockerfile in the subdirectory ./dir is found and used).

ACTUAL RESULTS
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Configuration error - build path /Users/pizzi/Desktop/test/a/dir either does not exist, is not accessible, or is not a valid URL."}
	to retry, use: --limit @/Users/pizzi/Desktop/test/b/playbook.retry

This means that the project-directory is set from the path of the first file provided, and cannot be changed, even if project_src is provided.

Note that this is the behaviour of docker-compose. I.e. if I am in the b folder,
the command

docker-compose --project-name=c -f ../a/docker-compose.yml -f ./docker-compose.yml up

Fails with

ERROR: build path /Users/pizzi/Desktop/test/a/dir either does not exist, is not accessible, or is not a valid URL.

and instead swapping the order works:

docker-compose --project-name=c -f ./docker-compose.yml -f ../a/docker-compose.yml up

However, from the command line specifying explicitly a --project-directory=. makes it work correctly:

docker-compose --project-name=c --project-directory=. -f ../a/docker-compose.yml -f ./docker-compose.yml up

The problem in ansible is that it is not possible to specify a --project-directory.

Possible suggestions:

  • add --project-directory to self.options in the code before calling compose.cli.command.project_from_options in the module taking the value from project_src, if specified (however, I don't know if the two have a different meaning and it's not a good idea to merge them)
  • add a project_directory option to the docker_service module that would set this option

I would favour option 2.

In any case (or even if this is already possible somehow) I would suggest to add an entry to the examples in the documentation of the module, explaining how to properly deal with this use case.

If you let me know how you prefer to proceed, I can also prepare a PR.

@ansibot
Copy link
Contributor

ansibot commented Nov 14, 2018

Hi @giovannipizzi, thank you for submitting this issue!

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Nov 14, 2018

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Nov 14, 2018

@ansibot ansibot added affects_2.7 This issue/PR affects Ansible v2.7 bug This issue/PR relates to a bug. cloud docker module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:community This issue/PR relates to code supported by the Ansible community. labels Nov 14, 2018
@gundalow gundalow removed needs_triage Needs a first human triage before being processed. labels Nov 22, 2018
@ansibot
Copy link
Contributor

ansibot commented Dec 12, 2018

@giovannipizzi
Copy link
Author

It would be great to get some feedback, so I can prepare a PR if you agree

@felixfontein
Copy link
Contributor

@giovannipizzi docker_service is pretty much unmaintained, so feel free to create a PR! Also, you might be interested in ansible/community#408. I know too little about docker_service's code to comment on your proposed solution right now, but if you can create a PR which works, that should be fine :)

@ansibot
Copy link
Contributor

ansibot commented Jan 24, 2019

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@felixfontein
Copy link
Contributor

!component =lib/ansible/modules/cloud/docker/docker_compose.py

@ansibot
Copy link
Contributor

ansibot commented Feb 9, 2019

@ansibot
Copy link
Contributor

ansibot commented Apr 6, 2019

@ansibot
Copy link
Contributor

ansibot commented Apr 14, 2019

Files identified in the description:
None

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added support:core This issue/PR relates to code supported by the Ansible Engineering Team. and removed module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community. labels Apr 14, 2019
@ansibot
Copy link
Contributor

ansibot commented Apr 22, 2019

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community. and removed support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Apr 22, 2019
@ansibot ansibot added collection Related to Ansible Collections work collection:community.general needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md labels Apr 29, 2020
@ansibot
Copy link
Contributor

ansibot commented Aug 16, 2020

Thank you very much for your interest in Ansible. Ansible has migrated much of the content into separate repositories to allow for more rapid, independent development. We are closing this issue/PR because this content has been moved to one or more collection repositories.

For further information, please see:
https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md

@ansibot ansibot closed this as completed Aug 16, 2020
@ansible ansible locked and limited conversation to collaborators Sep 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.7 This issue/PR affects Ansible v2.7 bot_closed bug This issue/PR relates to a bug. cloud collection:community.general collection Related to Ansible Collections work docker module This issue/PR relates to a module. needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

No branches or pull requests

4 participants