version: '2.1'
services:
  db:
    hostname: db.magento2.test
    image: 'mariadb-v1: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'
      - 'magento-magento-db:/var/lib/mysql'
    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.test
  redis:
    hostname: redis.magento2.test
    image: 'redis-v1:5'
    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.test
  elasticsearch:
    hostname: elasticsearch.magento2.test
    image: 'elasticsearch-v1:7.6'
    ulimits:
      memlock:
        soft: -1
        hard: -1
    environment:
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
    networks:
      magento:
        aliases:
          - elasticsearch.magento2.test
  fpm:
    hostname: fpm.magento2.test
    image: 'php-v1:7.4-fpm'
    extends: generic
    volumes:
      - '.:/app:ro,delegated'
      - './dev:/app/dev:rw,delegated'
      - 'magento-vendor:/app/vendor:ro,delegated'
      - 'magento-generated:/app/generated:ro,delegated'
      - 'magento-var:/app/var:rw,delegated'
      - 'magento-app-etc:/app/app/etc:rw,delegated'
      - 'magento-pub-media:/app/pub/media:rw,delegated'
      - 'magento-pub-static:/app/pub/static:rw,delegated'
      - '.docker/mnt:/mnt:rw,delegated'
    networks:
      magento:
        aliases:
          - fpm.magento2.test
    depends_on:
      db:
        condition: service_healthy
  web:
    hostname: web.magento2.test
    image: 'nginx-v1:1.24'
    extends: generic
    volumes:
      - '.:/app:ro,delegated'
      - './dev:/app/dev:rw,delegated'
      - 'magento-vendor:/app/vendor:ro,delegated'
      - 'magento-generated:/app/generated:ro,delegated'
      - 'magento-var:/app/var:rw,delegated'
      - 'magento-app-etc:/app/app/etc:rw,delegated'
      - 'magento-pub-media:/app/pub/media:rw,delegated'
      - 'magento-pub-static:/app/pub/static:rw,delegated'
      - '.docker/mnt:/mnt:rw,delegated'
    environment:
      - WITH_XDEBUG=0
      - NGINX_WORKER_PROCESSES=auto
      - NGINX_WORKER_CONNECTIONS=4096
    networks:
      magento:
        aliases:
          - web.magento2.test
    depends_on:
      fpm:
        condition: service_started
  varnish:
    hostname: varnish.magento2.test
    image: 'varnish-v1:6.2'
    networks:
      magento:
        aliases:
          - varnish.magento2.test
    depends_on:
      web:
        condition: service_started
  tls:
    hostname: tls.magento2.test
    image: 'nginx-v1:1.24'
    extends: generic
    networks:
      magento:
        aliases:
          - magento2.test
    environment:
      - NGINX_WORKER_PROCESSES=auto
      - NGINX_WORKER_CONNECTIONS=4096
      - UPSTREAM_HOST=varnish
      - UPSTREAM_PORT=80
    ports:
      - '8080:80'
      - '443:443'
    depends_on:
      varnish:
        condition: service_started
  test:
    hostname: test.magento2.test
    image: 'php-v1:7.4-cli'
    extends: generic
    volumes:
      - '.:/app:rw,delegated'
      - './dev:/app/dev:rw,delegated'
      - 'magento-vendor:/app/vendor:rw,delegated'
      - 'magento-generated:/app/generated:rw,delegated'
      - 'magento-var:/app/var:rw,delegated'
      - 'magento-app-etc:/app/app/etc:rw,delegated'
      - 'magento-pub-media:/app/pub/media:rw,delegated'
      - 'magento-pub-static:/app/pub/static:rw,delegated'
      - '.docker/mnt:/mnt:rw,delegated'
      - '~/.composer/cache:/composer/cache:rw,delegated'
    networks:
      magento:
        aliases:
          - test.magento2.test
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy
      elasticsearch:
        condition: service_healthy
  generic:
    hostname: generic.magento2.test
    image: 'php-v1:7.4-cli'
    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'
      - 'SENDMAIL_PATH=/usr/local/bin/mhsendmail --smtp-addr=mailhog:1025'
  build:
    hostname: build.magento2.test
    image: 'php-v1:7.4-cli'
    extends: generic
    volumes:
      - '.:/app:rw,delegated'
      - 'magento-vendor:/app/vendor:rw,delegated'
      - 'magento-generated:/app/generated:rw,delegated'
      - '~/.composer/cache:/composer/cache:rw,delegated'
    networks:
      magento-build:
        aliases:
          - build.magento2.test
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy
      elasticsearch:
        condition: service_healthy
  deploy:
    hostname: deploy.magento2.test
    image: 'php-v1:7.4-cli'
    extends: generic
    volumes:
      - '.:/app:ro,delegated'
      - './dev:/app/dev:rw,delegated'
      - 'magento-vendor:/app/vendor:ro,delegated'
      - 'magento-generated:/app/generated:ro,delegated'
      - 'magento-var:/app/var:rw,delegated'
      - 'magento-app-etc:/app/app/etc:rw,delegated'
      - 'magento-pub-media:/app/pub/media:rw,delegated'
      - 'magento-pub-static:/app/pub/static:rw,delegated'
      - '.docker/mnt:/mnt:rw,delegated'
    networks:
      magento:
        aliases:
          - deploy.magento2.test
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy
      elasticsearch:
        condition: service_healthy
  mailhog:
    hostname: mailhog.magento2.test
    image: 'magento/magento-cloud-docker-mailhog:1.0-1.2.0'
    ports:
      - '1026:1025'
      - '8026:8025'
    networks:
      magento:
        aliases:
          - mailhog.magento2.test
volumes:
  magento-vendor: {  }
  magento-generated: {  }
  magento-var: {  }
  magento-app-etc: {  }
  magento-pub-media: {  }
  magento-pub-static: {  }
  magento-magento-db: {  }
networks:
  magento:
    driver: bridge
  magento-build:
    driver: bridge
