# 使用构建好的镜像运行
# 官方稳定版
version: '3.3'
services:

  # Redis
  blog-redis:
    image: redis
    restart: always
    container_name: blog-redis
    hostname: blog-redis
    command: redis-server --appendonly yes --requirepass ${ONEBLOG_REDIS_PASSWORD} --bind blog-redis
    ports:
      - ${ONEBLOG_EXPORT_PORT_REDIS}:6379
    volumes:
      - ${ONEBLOG_APP_DIR}/redis/:/data/
    healthcheck:
      test: [ "CMD", "redis-cli" ]
      timeout: 20s
      retries: 10
    networks:
      - oneblog

  # MySQL
  blog-mysql:
    image: justauth/blog-mysql
    environment:
      MYSQL_ROOT_PASSWORD: ${ONEBLOG_DATASOURCE_PASSWORD}
      TZ: Asia/Shanghai
    restart: always
    container_name: blog-mysql
    hostname: blog-mysql
    volumes:
      - ${ONEBLOG_APP_DIR}/mysql:/var/lib/mysql
    ports:
      - ${ONEBLOG_EXPORT_PORT_MYSQL}:3306
    command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci
    healthcheck:
      test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
      timeout: 20s
      retries: 10
    networks:
      - oneblog

  # admin 服务
  blog-admin:
    image: justauth/blog-admin
    restart: always
    container_name: blog-admin
    hostname: blog-admin
    env_file:
      - .env
    volumes:
      - ${ONEBLOG_APP_DIR}:/var/tmp/oneblog
    depends_on:
      blog-redis:
        condition: service_healthy
      blog-mysql:
        condition: service_healthy
    links:
      - blog-redis
      - blog-mysql
    ports:
      - ${ONEBLOG_EXPORT_PORT_ADMIN}:8085
    networks:
      - oneblog

  # admin 服务
  blog-web:
    image: justauth/blog-web
    restart: always
    container_name: blog-web
    hostname: blog-web
    env_file:
      - .env
    volumes:
      - ${ONEBLOG_APP_DIR}:/var/tmp/oneblog
    depends_on:
      blog-redis:
        condition: service_healthy
      blog-mysql:
        condition: service_healthy
    links:
      - blog-redis
      - blog-mysql
    ports:
      - ${ONEBLOG_EXPORT_PORT_WEB}:8443
    networks:
      - oneblog

networks:
  oneblog:
    driver: bridge
