你是对的@ojb。当我想使用 gulp 作为我的自动化工作流程的一部分在线推送我的生产就绪代码时,我也陷入了类似的境地。
gulp-rsync 中基本上没有标准参数可以作为 ssh_key_location 传递。所以一种解决方法是使用 ssh 配置文件来创建一个本地 伪主机名。此过程用 伪主机名 屏蔽 实际主机名。
(ec2-xx-xxx-xxx-xxx.ap-west-2.compute.amazonaws.com + key) =>
主机名.com
由于没有关于如何解决此问题的适当文档,因此此处为可能面临此问题的每个人提供详细的操作方法
第一步:更新 ~/.ssh/config 文件以使其正常工作:$ ssh hostname.com
Host hostname.com
HostName ec2-xx-xxx-xxx-xxx.ap-west-2.compute.amazonaws.com
User ec2-user
IdentityFile ~/<path-to-file>/keyfile.pem
第二步:
将此添加到您的 gulp 函数中
// Dirs and Files to sync
rsyncPaths = ['directory-names', './file-name',....];
// Default options for rsync
rsyncConf = {
progress: true,
incremental: true,
relative: true,
emptyDirectories: true,
recursive: true,
clean: true,
exclude: [],
};
第三步:在gulp中创建如下函数
//something-on-top
return gulp.src(rsyncPaths)
.pipe($.rsync(rsyncConf));
疑难解答:
1.检查文件是否有400访问权限
2.检查$ ssh hostname.com是否有效