---
# It is necessary to shut the projects down, when reset is activated. 
# Otherwise it can lead to this bug:
# https://github.com/ansible/ansible/issues/10244
#- name: shut down docker compose project 
#  command:
#    cmd: docker-compose -p "{{application_id}}" down
#  listen: docker compose project setup
#  when: mode_reset | bool

# default setup for docker compose files
- name: docker compose project setup
  command:
    cmd: "docker-compose -p {{application_id}} up -d --force-recreate --remove-orphans"
    chdir: "{{docker_compose.directories.instance}}"
  environment:
    COMPOSE_HTTP_TIMEOUT: 600
    DOCKER_CLIENT_TIMEOUT: 600
  listen: docker compose project setup

# it's necessary to rebuild when a build in the docker compose files is defined
# for performance reasons it's not recommended to use this if there is no build tag specified
- name: docker compose project build and setup 
  command:
    cmd: "docker-compose -p {{application_id}} up -d --force-recreate --build --remove-orphans"
    chdir: "{{docker_compose.directories.instance}}"
  environment:
    COMPOSE_HTTP_TIMEOUT: 600
    DOCKER_CLIENT_TIMEOUT: 600
  listen: docker compose project build and setup

- name: docker compose restart
  command:
    cmd: "docker compose restart"
    chdir: "{{docker_compose.directories.instance}}"
  listen: docker compose restart
