services:
  caddy:
    container_name: caddy
    env_file: "stack.env"
    image: caddy:alpine
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile # Monta el archivo de configuración
      - caddy_data:/data # Almacena los certificados en este volumen
      - caddy_config:/config # Configuración de Caddy
      - /opt/presupuestador-uecko/dist/client:/srv
    ports:
      - 80:80 # Puerto HTTP (Caddy lo redirige automáticamente a HTTPS)
      - 443:443 # Puerto HTTPS
      - 13001:13001
    networks:
      - reverse_proxy
    restart: on-failure

  mariadb:
    container_name: mariadb
    env_file: "stack.env"
    image: mariadb:latest
    ports:
      - 3306:3306
    volumes:
      - mariadb_data:/var/lib/mysql
    networks:
      - private
    restart: on-failure

  wait-for-mariadb:
    image: atkrad/wait4x
    depends_on:
      - mariadb
    command: tcp mariadb:3306 -t 30s -i 250ms
    networks:
      - private

  phpmyadmin:
    container_name: phpmyadmin
    env_file: "stack.env"
    image: phpmyadmin/phpmyadmin
    ports:
      - 8080:80
    networks:
      - private
    depends_on:
      - mariadb

  backend:
    container_name: "backend"
    env_file: "stack.env"
    build:
      args:
        - NODE_ENV=production
      context: ./
      dockerfile: Dockerfile.server
    environment:
      - NODE_ENV=production
    volumes:
      - backend_logs:/var/log
      - backend_uploads:/api/uploads
    ports:
      - 3001:3001
    networks:
      - private
      - reverse_proxy
    depends_on:
      wait-for-mariadb:
        condition: service_completed_successfully
    restart: on-failure

  # frontend:
  #   container_name: "frontend"
  #   env_file: "stack.env"
  #   build:
  #     args:
  #       - NODE_ENV=production
  #     context: ./
  #     dockerfile: Dockerfile.client
  #   environment:
  #     - NODE_ENV=production
  #   volumes:
  #     - shared_frontend:/www
  #   networks:
  #     - reverse_proxy
  #   depends_on:
  #     - caddy
  #     - backend

volumes:
  # shared_frontend:
  caddy_data:
  caddy_config:
  mariadb_data:
  backend_logs:
  backend_uploads:

networks:
  private:
  reverse_proxy:
