version: '2.1'
services:
  db:
    hostname: db.magento2.docker
    image: 'mariadb:10.2'
    shm_size: 2gb
    environment:
      - MYSQL_ROOT_PASSWORD=magento2
      - MYSQL_DATABASE=magento2
      - MYSQL_USER=magento2
      - MYSQL_PASSWORD=magento2
    ports:
      - '3306'
    volumes:
      - '.docker/mnt:/mnt:rw,delegated'
      - '.docker/mysql/mariadb.conf.d:/etc/mysql/mariadb.conf.d'
      - 'mymagento-magento-db:/var/lib/mysql'
      - '.docker/mysql/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d'
    healthcheck:
      test: 'mysqladmin ping -h localhost -pmagento2'
      interval: 30s
      timeout: 30s
      retries: 3
    command: '--auto_increment_increment=3 --auto_increment_offset=2'
    networks:
      magento:
        aliases:
          - db.magento2.docker
  redis:
    hostname: redis.magento2.docker
    image: 'redis:5.0'
    volumes:
      - /data
    ports:
      - 6379
    sysctls:
      net.core.somaxconn: 1024
    ulimits:
      nproc: 65535
      nofile:
        soft: 20000
        hard: 40000
    healthcheck:
      test: 'redis-cli ping || exit 1'
      interval: 30s
      timeout: 30s
      retries: 3
    networks:
      magento:
        aliases:
          - redis.magento2.docker
  fpm:
    hostname: fpm.magento2.docker
    image: 'magento/magento-cloud-docker-php:8.0-fpm-1.2.0'
    extends: generic
    volumes:
      - '.:/app:ro,delegated'
      - './dev:/app/dev:rw,delegated'
      - 'mymagento-vendor:/app/vendor:ro,delegated'
      - 'mymagento-generated:/app/generated:ro,delegated'
      - 'mymagento-var:/app/var:rw,delegated'
      - 'mymagento-app-etc:/app/app/etc:rw,delegated'
      - 'mymagento-pub-media:/app/pub/media:rw,delegated'
      - 'mymagento-pub-static:/app/pub/static:rw,delegated'
      - '.docker/mnt:/mnt:rw,delegated'
    networks:
      magento:
        aliases:
          - fpm.magento2.docker
    depends_on:
      db:
        condition: service_healthy
  web:
    hostname: web.magento2.docker
    image: 'magento/magento-cloud-docker-nginx:1.24-1.2.0'
    extends: generic
    volumes:
      - '.:/app:ro,delegated'
      - './dev:/app/dev:rw,delegated'
      - 'mymagento-vendor:/app/vendor:ro,delegated'
      - 'mymagento-generated:/app/generated:ro,delegated'
      - 'mymagento-var:/app/var:rw,delegated'
      - 'mymagento-app-etc:/app/app/etc:rw,delegated'
      - 'mymagento-pub-media:/app/pub/media:rw,delegated'
      - 'mymagento-pub-static:/app/pub/static:rw,delegated'
      - '.docker/mnt:/mnt:rw,delegated'
    environment:
      - WITH_XDEBUG=1
      - NGINX_WORKER_PROCESSES=auto
      - NGINX_WORKER_CONNECTIONS=1024
    networks:
      magento:
        aliases:
          - web.magento2.docker
    depends_on:
      fpm:
        condition: service_started
  varnish:
    hostname: varnish.magento2.docker
    image: 'magento/magento-cloud-docker-varnish:6.6-1.2.0'
    networks:
      magento:
        aliases:
          - varnish.magento2.docker
    depends_on:
      web:
        condition: service_started
  tls:
    hostname: tls.magento2.docker
    image: 'magento/magento-cloud-docker-nginx:1.24-1.2.0'
    extends: generic
    networks:
      magento:
        aliases:
          - magento2.docker
    environment:
      - NGINX_WORKER_PROCESSES=auto
      - NGINX_WORKER_CONNECTIONS=1024
      - UPSTREAM_HOST=varnish
      - UPSTREAM_PORT=80
    ports:
      - '80:80'
      - '4443:443'
    depends_on:
      varnish:
        condition: service_started
  test:
    hostname: test.magento2.docker
    image: 'magento/magento-cloud-docker-php:8.0-cli-1.2.0'
    extends: generic
    volumes:
      - '.:/app:rw,delegated'
      - './dev:/app/dev:rw,delegated'
      - 'mymagento-vendor:/app/vendor:rw,delegated'
      - 'mymagento-generated:/app/generated:rw,delegated'
      - 'mymagento-var:/app/var:rw,delegated'
      - 'mymagento-app-etc:/app/app/etc:rw,delegated'
      - 'mymagento-pub-media:/app/pub/media:rw,delegated'
      - 'mymagento-pub-static:/app/pub/static:rw,delegated'
      - '.docker/mnt:/mnt:rw,delegated'
      - '~/.composer/cache:/composer/cache:rw,delegated'
    networks:
      magento:
        aliases:
          - test.magento2.docker
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy
  fpm_xdebug:
    hostname: fpm_xdebug.magento2.docker
    image: 'magento/magento-cloud-docker-php:8.0-fpm-1.2.0'
    extends: generic
    volumes:
      - '.:/app:ro,delegated'
      - './dev:/app/dev:rw,delegated'
      - 'mymagento-vendor:/app/vendor:ro,delegated'
      - 'mymagento-generated:/app/generated:ro,delegated'
      - 'mymagento-var:/app/var:rw,delegated'
      - 'mymagento-app-etc:/app/app/etc:rw,delegated'
      - 'mymagento-pub-media:/app/pub/media:rw,delegated'
      - 'mymagento-pub-static:/app/pub/static:rw,delegated'
      - '.docker/mnt:/mnt:rw,delegated'
    environment:
      - 'PHP_EXTENSIONS=bcmath bz2 calendar exif gd gettext intl mysqli pcntl pdo_mysql soap sockets sysvmsg sysvsem sysvshm opcache zip xsl sodium zookeeper xdebug'
    networks:
      magento:
        aliases:
          - fpm_xdebug.magento2.docker
    depends_on:
      db:
        condition: service_started
  generic:
    hostname: generic.magento2.docker
    image: 'magento/magento-cloud-docker-php:8.0-cli-1.2.0'
    env_file: ./.docker/config.env
    environment:
      - 'PHP_EXTENSIONS=bcmath bz2 calendar exif gd gettext intl mysqli pcntl pdo_mysql soap sockets sysvmsg sysvsem sysvshm opcache zip xsl sodium zookeeper'
  build:
    hostname: build.magento2.docker
    image: 'magento/magento-cloud-docker-php:8.0-cli-1.2.0'
    extends: generic
    volumes:
      - '.:/app:rw,delegated'
      - 'mymagento-vendor:/app/vendor:rw,delegated'
      - 'mymagento-generated:/app/generated:rw,delegated'
      - '~/.composer/cache:/composer/cache:rw,delegated'
    networks:
      magento-build:
        aliases:
          - build.magento2.docker
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy
  deploy:
    hostname: deploy.magento2.docker
    image: 'magento/magento-cloud-docker-php:8.0-cli-1.2.0'
    extends: generic
    volumes:
      - '.:/app:ro,delegated'
      - './dev:/app/dev:rw,delegated'
      - 'mymagento-vendor:/app/vendor:ro,delegated'
      - 'mymagento-generated:/app/generated:ro,delegated'
      - 'mymagento-var:/app/var:rw,delegated'
      - 'mymagento-app-etc:/app/app/etc:rw,delegated'
      - 'mymagento-pub-media:/app/pub/media:rw,delegated'
      - 'mymagento-pub-static:/app/pub/static:rw,delegated'
      - '.docker/mnt:/mnt:rw,delegated'
    networks:
      magento:
        aliases:
          - deploy.magento2.docker
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy
  cron:
    hostname: cron.magento2.docker
    image: 'magento/magento-cloud-docker-php:8.0-cli-1.2.0'
    extends: generic
    command: run-cron
    environment:
      CRONTAB: '* * * * * root cd /app && /usr/local/bin/php bin/magento cron:run >> /app/var/log/cron.log'
    volumes:
      - '.:/app:ro,delegated'
      - './dev:/app/dev:rw,delegated'
      - 'mymagento-vendor:/app/vendor:ro,delegated'
      - 'mymagento-generated:/app/generated:ro,delegated'
      - 'mymagento-var:/app/var:rw,delegated'
      - 'mymagento-app-etc:/app/app/etc:rw,delegated'
      - 'mymagento-pub-media:/app/pub/media:rw,delegated'
      - 'mymagento-pub-static:/app/pub/static:rw,delegated'
      - '.docker/mnt:/mnt:rw,delegated'
    networks:
      magento:
        aliases:
          - cron.magento2.docker
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy
  zookeeper:
    hostname: zookeeper.magento2.docker
    image: 'zookeeper:latest'
    networks:
      magento:
        aliases:
          - zookeeper.magento2.docker
volumes:
  mymagento-vendor: {  }
  mymagento-generated: {  }
  mymagento-var: {  }
  mymagento-app-etc: {  }
  mymagento-pub-media: {  }
  mymagento-pub-static: {  }
  mymagento-magento-db: {  }
networks:
  magento:
    driver: bridge
  magento-build:
    driver: bridge
