---
# Datei: ansible/playbooks/deploy/includes/docker_compose.yml
# Verwaltet die Docker-Compose-Konfiguration und -Ausführung

- name: Erstelle Docker-Compose-Datei
  copy:
    dest: "{{ docker_compose_project_path }}/docker-compose-simple.yml"
    content: |
      version: '3.8'

      services:
        php:
          container_name: michaelschiemer_php
          build:
            context: ./docker/php
            dockerfile: Dockerfile-simple
          volumes:
            - ./src:/var/www/html/src:rw
            - ./public:/var/www/html/public:rw
          networks:
            - backend

        nginx:
          container_name: michaelschiemer_nginx
          image: nginx:alpine
          ports:
            - "80:80"
            - "443:443"
          volumes:
            - ./public:/var/www/html/public:ro
            - ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
            - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
          depends_on:
            - php
          networks:
            - frontend
            - backend

        redis:
          container_name: michaelschiemer_redis
          image: redis:alpine
          volumes:
            - ./docker/redis/redis.conf:/usr/local/etc/redis/redis.conf:ro
          command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
          networks:
            - cache

      networks:
        frontend:
        backend:
        cache:
    owner: root
    group: root
    mode: '0644'

- name: Erstelle .env-Datei falls nicht vorhanden
  copy:
    dest: "{{ docker_compose_project_path }}/.env"
    content: |
      COMPOSE_PROJECT_NAME=michaelschiemer
      APP_ENV=production
      APP_PORT=80
      APP_SSL_PORT=443
    owner: root
    group: root
    mode: '0644'
  when: not lookup('vars', 'project_root', default=false)
