volumes:
  docker-in-docker:
    driver: ${VOLUMES_DRIVER}
services:
  prod-backend-service:
    image: lpc/php-fpm:latest
    restart: always
    volumes:
      - ./php-fpm/php${PHP_VERSION}.ini:/usr/local/etc/php/php.ini
      - ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}${APP_CODE_CONTAINER_FLAG}
      - docker-in-docker:/certs/client
    ports:
      - "9000"
      - "80"
    extra_hosts:
      - "dockerhost:${DOCKER_HOST_IP}"
    environment:
      - PHP_IDE_CONFIG=${PHP_IDE_CONFIG}
      - DOCKER_HOST=tcp://docker-in-docker:2376
      - DOCKER_TLS_VERIFY=1
      - DOCKER_TLS_CERTDIR=/certs
      - DOCKER_CERT_PATH=/certs/client
      - FAKETIME=${PHP_FPM_FAKETIME}
      - TZ=${WORKSPACE_TIMEZONE}
    depends_on:
      - workspace
    links:
      - docker-in-docker
    networks:
      - lpc-saas

  dev-backend-service:
    image: lpc/php-fpm:latest
    restart: always
    volumes:
      - ./php-fpm/php${PHP_VERSION}.ini:/usr/local/etc/php/php.ini
      - ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}${APP_CODE_CONTAINER_FLAG}
      - docker-in-docker:/certs/client
    ports:
      - "9000"
      - "80"
    extra_hosts:
      - "dockerhost:${DOCKER_HOST_IP}"
    environment:
      - PHP_IDE_CONFIG=${PHP_IDE_CONFIG}
      - DOCKER_HOST=tcp://docker-in-docker:2376
      - DOCKER_TLS_VERIFY=1
      - DOCKER_TLS_CERTDIR=/certs
      - DOCKER_CERT_PATH=/certs/client
      - FAKETIME=${PHP_FPM_FAKETIME}
      - TZ=${WORKSPACE_TIMEZONE}
    depends_on:
      - workspace
    links:
      - docker-in-docker
    networks:
      - lpc-saas

  prod-frontend-service:
    image: lpc/vue:latest
    ports:
      - "80"
    networks:
      - lpc-saas

  dev-frontend-service:
    image: lpc/vue:latest
    ports:
      - "80"
    networks:
      - lpc-saas

  openresty:
    image: lpc/openresty:latest
    volumes:
      - ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}${APP_CODE_CONTAINER_FLAG}
      - ${OPENRESTY_HOST_LOG_PATH}:/var/log/nginx
      - ${OPENRESTY_SITES_PATH}:/etc/nginx/sites-available
      - ${OPENRESTY_SSL_PATH}:/etc/nginx/ssl
      - ${OPENRESTY_LUA_PATH}:/usr/local/openresty/lualib/resty
    ports:
      - "${OPENRESTY_HOST_HTTP_PORT}:80"
      - "${OPENRESTY_HOST_HTTPS_PORT}:443"
      - "${VARNISH_BACKEND_PORT}:81"
    depends_on:
      - prod-backend-service
      - dev-backend-service
      - prod-frontend-service
      - dev-frontend-service

    networks:
      - lpc-saas

  workspace:
    image: lpc/workspace:latest
    restart: always
    volumes:
      - ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}${APP_CODE_CONTAINER_FLAG}
      - docker-in-docker:/certs/client
      - ./php-worker/supervisord.d:/etc/supervisord.d
    extra_hosts:
      - "dockerhost:${DOCKER_HOST_IP}"
    ports:
      - "${WORKSPACE_SSH_PORT}:22"
      - "${WORKSPACE_BROWSERSYNC_HOST_PORT}:3000"
      - "${WORKSPACE_BROWSERSYNC_UI_HOST_PORT}:3001"
      - "${WORKSPACE_VUE_CLI_SERVE_HOST_PORT}:8080"
      - "${WORKSPACE_VUE_CLI_UI_HOST_PORT}:8000"
      - "${WORKSPACE_ANGULAR_CLI_SERVE_HOST_PORT}:4200"
      - "${WORKSPACE_VITE_PORT}:5173"
    tty: true
    environment:
      - PHP_IDE_CONFIG=${PHP_IDE_CONFIG}
      - DOCKER_HOST=tcp://docker-in-docker:2376
      - DOCKER_TLS_VERIFY=1
      - DOCKER_TLS_CERTDIR=/certs
      - DOCKER_CERT_PATH=/certs/client
      - CHOKIDAR_USEPOLLING=true
    networks:
      - lpc-saas
    links:
      - docker-in-docker

  redis:
    restart: always
    build: ./redis
    volumes:
      - ${DATA_PATH_HOST}/redis:/data
    command: --requirepass ${REDIS_PASSWORD}
    ports:
      - "${REDIS_PORT}:6379"
    networks:
      - lpc-saas

  docker-in-docker:
    restart: always
    image: lpc/docker:latest
    environment:
      DOCKER_TLS_SAN: DNS:docker-in-docker
    privileged: true
    volumes:
      - ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}
      - docker-in-docker:/certs/client
    expose:
      - 2375
    networks:
      - lpc-saas

networks:
  lpc-saas:
    driver: bridge
