Files
ulthon_admin/source/stack/full/Dockerfile
augushong e0e2580646 feat(stack): 所有 Docker 模式集成 XHProf 性能分析
在 docker-dev/docker-dev-sync/docker-serve/full 四个模式中集成 XHProf
性能分析能力,默认不启用(--profile xhprof 按需开启),零侵入不改
业务代码和 run.sh。

核心组件:
- source/docker/xhprof-bootstrap.php: 采集器初始化(auto_prepend_file)
- source/docker/xhgui-config.php: XHGui 认证配置(Basic Auth)+ PDO 存储
- 各 Dockerfile: 安装 PECL xhprof 扩展 + php-profiler 到 /opt/xhprof/
- 各 docker-compose: 新增 xhgui 服务(profiles: xhprof),端口 8142

存储方案:PDO MySQL(复用现有 MySQL),避免 MongoDB PHP 驱动兼容性问题。
docker-dev/docker-dev-sync 开箱即用;docker-serve/full 需配置 XHGUI_PDO_DSN。

认证:HTTP Basic Auth,默认 admin/xhgui123,环境变量可覆盖。
采集控制:XHPROF_ENABLE 环境变量 + cookie _profiler 强制触发 + 1% 采样。
Dockerfile.base 同步新增 xhprof 扩展(框架作者需重建推送基础镜像)。
2026-08-09 09:07:10 +08:00

98 lines
3.8 KiB
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

FROM php:8.2-fpm-bookworm
RUN rm -rf /etc/apt/sources.list.d/* \
&& echo "deb http://mirrors.ustc.edu.cn/debian/ bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list \
&& echo "deb http://mirrors.ustc.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list \
&& echo "deb http://mirrors.ustc.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list
RUN apt-get update
# 安装nginx
RUN apt-get install -y nginx
ADD --chmod=0755 https://nexus.hl7.top:1243/repository/github-raw-proxy/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
# 配置代理
RUN sed -i 's|aomedia.googlesource.com|nexus.hl7.top:1243/repository/raw-aomedia.googlesource.com|g' /usr/local/bin/install-php-extensions
RUN sed -i 's|chromium.googlesource.com|nexus.hl7.top:1243/repository/raw-chromium.googlesource.com|g' /usr/local/bin/install-php-extensions
RUN sed -i 's|https://github.com|https://nexus.hl7.top:1243/repository/github-raw-proxy|g' /usr/local/bin/install-php-extensions
RUN install-php-extensions pdo_mysql
RUN install-php-extensions gd
RUN install-php-extensions fileinfo
RUN install-php-extensions opcache
RUN install-php-extensions redis
RUN install-php-extensions event
RUN install-php-extensions imagick
RUN install-php-extensions zip
RUN install-php-extensions pcntl
RUN install-php-extensions xhprof
# 清理默认 Nginx 配置
RUN rm /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
# 安装其他需要的依赖
# RUN apt-get install -y ffmpeg
# RUN apt-get install -y libreoffice
# RUN apt-get install -y redis-server
# RUN apt-get install -y git
# 设置工作目录
WORKDIR /var/www/html
# 安装 Composer
COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer
RUN chmod +x /usr/local/bin/composer
RUN composer config -g repos.packagist composer https://nexus.hl7.top:1243/repository/composer-proxy/
# 设置工作目录
WORKDIR /var/www/html
# 预先拷贝 composer 文件并安装依赖,利用 Docker 缓存
COPY composer.json composer.lock /var/www/html/
RUN composer install --no-dev --no-interaction --no-scripts --no-autoloader
# 将当前目录下的文件拷贝到工作目录
COPY . /var/www/html
# B-route: build context 为仓库根,模式配置在 source/stack/<mode>/source/docker/
RUN rm -rf /var/www/html/source/docker && ln -sf /var/www/html/source/stack/full/source/docker /var/www/html/source/docker
# 生成自动加载文件
RUN composer dump-autoload --optimize --no-dev --classmap-authoritative
# XHProf: 安装 php-profiler 到独立目录
RUN mkdir -p /opt/xhprof \
&& cd /opt/xhprof \
&& composer require perftools/php-profiler --no-dev
# XHProf: 复制采集器 bootstrap全局配置不受 bind mount 影响)
COPY source/docker/xhprof-bootstrap.php /opt/xhprof/xhprof-bootstrap.php
# XHProf: 配置 auto_prepend_filezzz 前缀确保最后加载)
RUN echo 'auto_prepend_file = /opt/xhprof/xhprof-bootstrap.php' > /usr/local/etc/php/conf.d/zzz-xhprof.ini
# 内部安装compsoer并安装依赖如果不需要可以注释掉
# RUN install-php-extensions @composer
VOLUME /var/www/html/runtime
VOLUME /var/www/html/public/storage
VOLUME /var/www/html/public/build
VOLUME /var/www/html/storage
# 挂载主目录,也可以选择直接挂载主目录,可以把上面的几个指定的目录删掉
# VOLUME ["/var/www/html"]
# 暴露 Nginx 端口
EXPOSE 8000
# B-route bind mount 模式ENTRYPOINT 必须用完整路径build 期 symlink 被 bind mount 覆盖)
RUN chmod +x /var/www/html/source/stack/full/source/docker/run.sh
# 启动 Nginx PHP 然后阻塞
ENTRYPOINT ["/bin/bash", "/var/www/html/source/stack/full/source/docker/run.sh"]
CMD ["server"]