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_v2 is incompatible with non-standard or stacked compose file names #838

Closed
traviswaelbro opened this issue Apr 19, 2024 · 2 comments · Fixed by #839
Closed
Labels
docker-compose-v2 Docker Compose v2

Comments

@traviswaelbro
Copy link

SUMMARY

Ansible is unable to operate if the project_src does not have one of the hard-coded DOCKER_COMPOSE_FILES listed (source).

('compose.yaml', 'compose.yml', 'docker-compose.yaml', 'docker-compose.yml')

Furthermore, this appears to make it impossible to manage any project that is using Multiple Compose Files.

In our use case, we have a docker-compose.base.yml file which gets merged with additional file(s) depending on environment. The files to be loaded is controlled via the .env file's COMPOSE_FILE variable. This functionality is supported according to Docker's documentation and functions as expected outside of Ansible. Additionally, it was operating via Ansible as expected when we were using community.docker.docker_compose.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.docker.docker_compose_v2

ANSIBLE VERSION
ansible [core 2.15.10]
  config file = /Users/travis/playground/ansible_odoo/ansible.cfg
  configured module search path = ['/Users/travis/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/travis/.ansible/collections:/usr/share/ansible/collections
  executable location = /Library/Frameworks/Python.framework/Versions/3.9/bin/ansible
  python version = 3.9.13 (v3.9.13:6de2ca5339, May 17 2022, 11:37:23) [Clang 13.0.0 (clang-1300.0.29.30)] (/Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9)
  jinja version = 3.0.3
  libyaml = True
COLLECTION VERSION
$ ansible-galaxy collection list community.docker

# /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/ansible_collections
Collection       Version
---------------- -------
community.docker 3.4.11

# /Users/travis/.ansible/collections/ansible_collections
Collection       Version
---------------- -------
community.docker 3.8.1
CONFIGURATION
ANSIBLE_PIPELINING(/Users/travis/playground/ansible_odoo/ansible.cfg) = True
CONFIG_FILE() = /Users/travis/playground/ansible_odoo/ansible.cfg
DEFAULT_HOST_LIST(/Users/travis/playground/ansible_odoo/ansible.cfg) = ['/Users/travis/playground/ansible_odoo/inventory']
EDITOR(env: EDITOR) = nvim
INVENTORY_IGNORE_EXTS(/Users/travis/playground/ansible_odoo/ansible.cfg) = ['~', '.orig', '.bak', '.cfg', '.retry', '.pyc', '.pyo', '.sample']
PAGER(env: PAGER) = less
OS / ENVIRONMENT

Target OS: Ubuntu 22.04.4

STEPS TO REPRODUCE
  1. Using any Docker project, remove any of the standard "allowed" file names ('compose.yaml', 'compose.yml', 'docker-compose.yaml', 'docker-compose.yml')
  2. Provide a non-standard compose file, such as docker-compose.base.yml
  3. Use one of the various methods to specify a non-standard compose file
    1. Include COMPOSE_FILE=docker-compose.base.yml in /path/to/project/.env
    2. Include the env_files parameter (source) in your Ansible playbook (shouldn't be necessary, because .env is default)
    3. Include the files parameter (source) in your Ansible playbook
  4. Try to manage the container using Ansible
- name: Stop container
  community.docker.docker_compose_v2:
    project_src: /path/to/project
    state: stopped
EXPECTED RESULTS

The container(s) are stopped.

ACTUAL RESULTS

An error is raised:

fatal: [server_name]: FAILED! => {"changed": false, "msg": "\"/path/to/project\" does not contain compose.yaml, compose.yml, docker-compose.yaml, or docker-compose.yml"}

The same error is described in #756 and was addressed in #759, but that only added additional options to the hard-coded standard file names.

@felixfontein felixfontein added the docker-compose-v2 Docker Compose v2 label Apr 19, 2024
@felixfontein
Copy link
Collaborator

  1. Include the files parameter (source) in your Ansible playbook

Are you saying that this doesn't work? From the code it should not complain about a missing file in ('compose.yaml', 'compose.yml', 'docker-compose.yaml', 'docker-compose.yml') if the files option is specified.

  1. Include COMPOSE_FILE=docker-compose.base.yml in /path/to/project/.env

  2. Include the env_files parameter (source) in your Ansible playbook (shouldn't be necessary, because .env is default)

I wasn't able to find any information on the COMPOSE_FILE env variable in the Compose specification (https://github.com/compose-spec/compose-spec/blob/master/spec.md), but it is mentioned in the Docker Compose documentation: https://github.com/docker/compose/blob/main/docs/reference/compose.md#specifying-a-path-to-a-single-compose-file - I guess this is a Docker Compose specific extension.

I don't think it's a good idea to re-implement all this specific logic in the Python code (it does work for the old docker_compose because that one literally includes Docker Compose itself and uses its logic).

I'm currently thinking about either simply disabling the check, or allowing the user to disable it. The latter has the advantage that in most cases, none of the files ('compose.yaml', 'compose.yml', 'docker-compose.yaml', 'docker-compose.yml') being there is likely a user mistake.

@felixfontein
Copy link
Collaborator

I created #839 to add a check_files_existing option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docker-compose-v2 Docker Compose v2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants