version: '3.8'
services:
  #PHP
  app:
    build:
      args:
        user: ${APP_USER}
        uid: ${APP_UID}
      context: ./
      dockerfile: Dockerfile
    image: 8.1.26
    container_name: app
    restart: unless-stopped
    tty: true
    environment:
      SERVICE_NAME: ${APP_SERVICE_NAME}
      SERVICE_TAGS: ${ENVIRONMENT}
    working_dir: /var/www/
    volumes:
      - ./:/var/www
      - ./docker_conf/php/local.ini:/usr/local/etc/php/conf.d/local.ini
    depends_on:
      - db
      - composer
      - webserver
    networks:
      - app-network

  #Nginx
  webserver:
    image: nginx:alpine
    container_name: webserver
    restart: unless-stopped
    tty: true
    ports:
      - ${APP_PORT}:8080
    volumes:
      - ./:/var/www
      - ./docker_conf/nginx:/etc/nginx/conf.d
    networks:
      - app-network

  #MySQL
  db:
    image: mariadb:11.2.2
    container_name: db
    restart: unless-stopped
    tty: true
    ports:
      - ${DB_PORT}:3307
    environment:
      MYSQL_DATABASE: ${DB_DATABASE}
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
      MYSQL_USER: ${DB_USERNAME}
      MYSQL_PASSWORD: ${DB_PASSWORD}
      SERVICE_TAGS: ${ENVIRONMENT}
      SERVICE_NAME: ${DB_SERVICE_NAME}
    volumes:
      - dbdata:/var/lib/mysql/
      - ./docker_conf/db/maria.cnf:/etc/mysql/my.cnf
      #- ./docker_conf/db/migrations/:/docker-entrypoint-initdb.d
    networks:
      - app-network
  composer:
    container_name: amc_composer
    image: composer:latest
    environment:
      - COMPOSER_PROCESS_TIMEOUT=${COMPOSER_TIMEOUT}
    volumes:
      - ./:/app:delegated
    command: >
      sh -c "composer --ignore-platform-reqs update && composer --ignore-platform-reqs install"

  node_carte_jeunes:
      container_name: node_carte_jeunes
      #image: node:current-alpine3.19
      build:
        context: ./
        dockerfile: docker_conf/npm_modules/Dockerfile
      volumes:
          - ./:/usr/src/app
      depends_on:
          - app

#Networks
networks:
  app-network:
    driver: bridge
#Volumes
volumes:
  dbdata:
    driver: local
