git - Git post-receive hook实时输出流
问题描述
我正在使用 nginx 和 fastCGI (fcgiwrap) 托管一个 git-http-backend。当我推送具有接收后挂钩的应用程序时,似乎只有在挂钩终止后,输出才会发送到我的 git 客户端。
#!/bin/sh
echo "foo"
sleep 5
echo "bar"
它在终止后在某处缓冲输出并立即发送。所以实际看到“foo”需要 5 秒。我不太确定这种缓冲发生在哪里。
我认为我想要的是可能的,例如 Heroku 也能够流式传输他们的 post-receive 钩子的输出。
这是我的nginx.conf
:
user nginx;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
server {
server_name _;
listen 80 default_server;
listen [::]:80 default_server;
location /ping {
add_header Content-Type text/plain;
return 200 'pong';
}
location ~ ^.*\.git/objects/([0-9a-f]+/[0-9a-f]+|pack/pack-[0-9a-f]+.(pack|idx))$ {
root /var/lib/git;
}
location ~ ^.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ {
client_max_body_size 0;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/libexec/git-core/git-http-backend;
fastcgi_param GIT_HTTP_EXPORT_ALL "";
fastcgi_param GIT_PROJECT_ROOT /var/lib/git;
fastcgi_param PATH_INFO $uri;
fastcgi_param REMOTE_USER $remote_user;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_buffering off;
fastcgi_keep_conn on;
}
location / {
try_files $uri $uri/ =404;
}
}
}
daemon off;
解决方案
原因既不是git也不是nginx,而是fastcgi。我发现这篇文章很有帮助:https ://serverfault.com/questions/852564/nginx-and-fcgiwrap-incremental-output-problems 。
然而,提供的补丁仅适用于 Debian。当我使用 Alpine 时,我最终基于https://github.com/petercolberg/fcgiwrap/tree/unbuffered编译了我自己的二进制文件
之后,我所要做的就是将以下行添加到我的 nginx 配置中:
fastcgi_param NO_BUFFERING 1;
推荐阅读
- python - 从 SKLearn StackingClassifier 检索系数
- python - 如何在 HTML id 中使用来自 Django 的变量标签
- javascript - 在 ES6 中解构大对象时自动分配变量
- c - 如何从字符串中获取特定的子字符串?
- sql - 如何添加将以正确顺序显示的日期(月份),现在它在递归 CTE SQL 中倒退
- javascript - 如何在本机反应中从javascript激活TouchablePpacity onPress?
- qt - 使用着色器可视化两个图像的交集
- android - OnClick 用于片段中的 2/3 回收器视图(其本身托管/放置在另一个片段上)不起作用
- excel - 日期操作以输出相同的日期
- git - Theia 工作区中的多个 Git 存储库