version: '3.6'

services:
  database:
    image: mysql:latest
    container_name: ${APP_NAME}_mysql
    restart: always
    volumes:
      - ./db_data:/var/lib/mysql
      - ./mysql/sql:/docker-entrypoint-initdb.d/
    ports:
      - '${MYSQL_PORT}:3306'
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: ${APP_NAME}_phpmyadmin
    restart: always
    ports:
      - ${PORT_PHPMYADMIN}:80
    environment:
      PMA_ARBITRARY: 1
      MYSQL_HOST: database
      MYSQL_PORT: 3306
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
  redis:
    container_name: ${APP_NAME}_redis
    image: redis
    ports:
      - "${PORT_REDIS}:6379"
    volumes:
      - "./data/redis:/data"
    restart: always

  php:
    build:
      context: .
      dockerfile: ./fpm/Dockerfile
      args:
        - INSTALL_OPCACHE=false
    container_name: ${APP_NAME}_php
    environment:
      - DB_HOST=database
      - DB_PORT=3306
    entrypoint: sh /bin/entrypoint.sh php-fpm
    restart: always
    volumes:
      - "./fpm/php.ini:/usr/local/etc/php/conf.d/php.ini"
      -  './fpm/opcache.ini:/usr/local/etc/php/conf.d/opcache.ini'
      - ./fpm/entrypoint.sh:/bin/entrypoint.sh
      - type: bind
        source: ${APP_PATH}
        target: /var/www/html

    depends_on:
      - database

  web:
    build:
      context: .
      dockerfile: ./nginx/Dockerfile
    container_name: ${APP_NAME}_nginx
    ports:
      - ${PORT_HTTP}:80
      - ${PORT_HTTPS}:443
    restart: always
    volumes:
      - "./nginx/nginx.conf:/etc/nginx/nginx.conf"
      - "./nginx/app.conf:/etc/nginx/conf.d/application.conf"
      - "./nginx/ssl:/etc/ssl"
      - type: bind
        source: ${APP_PATH}
        target: /var/www/html 

    depends_on:
      - php
      - database

volumes:
  db_data:
