本文介绍了从GitHub推送到Web服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将所有网站移至GitHub,以获得所有显而易见的好处。我不是命令行的忠实粉丝,所以我喜欢GitHub,因为它允许我避免触及所有这些。在GitHub上建立一个存储库,然后与我的电脑同步很容易。我需要能够从GitHub自动推送到Web服务器,尽管如此,当我在本地更新某个主分支时,将其与GitHub同步,它会在网站上实时显示。从谷歌搜索这个主题看来,大多数技术似乎需要命令行或看起来相当复杂。我想用大约15-20个站点(其中许多托管在来自不同客户端的不同服务器上)执行此操作。我想找到一个在我的技能范围内的选项,并且每个站点不需要2-3小时。任何人都知道设置这个最好的,最简单的方法吗?

解决方案

复杂的部分是

这意味着您的web站点必须有一个进程监听GitHub在收到提交时发送的JSON消息。

您可以看到这些监听器的多个示例,如,带有一个auto.php(用于php服务器):

 <?php 

//防止意外的XSS
标题(Content-type:文本/无格式);

//运行脚本
if($ _POST ['payload']){
shell_exec(./ pull.sh);
}

该GitHub项目建议使用不带密码的SSH密钥,我同意开始(测试它)。

但是,特别是对于私人项目,最好运行ssh-agent并管理受保护的ssh密钥密码。

As janos :


I am wanting to move all of my sites to GitHub for all of the obvious benefits. I am not a big fan of the command line, so I like GitHub because it allows me to avoid touching all of that. Setting up a repository on GitHub and then syncing it with my computer is easy enough. I need to be able to push from GitHub to the webserver automatically though so when I update something locally to the main branch, sync it with GitHub, it goes live on the site. From Googling the subject it seems like most of the techniques either require the command line or seem fairly complex. I want to do this with about 15-20 sites (many of which are hosted on different servers from different clients). I want to find an option that is within my skill set and doesn't take 2-3 hours per site. Anyone know of the best, easiest way to set this up?

解决方案

The part which is complex is the webhook on GitHub

That means your web site must have a process listening to those JSON messages sent by GitHub upon reception of a commit.

You can see multiple examples of those listeners, like this webhook-deployer, with an auto.php (for a php server):

<?php

 // Prevent accidental XSS
 header("Content-type: text/plain");

 // Run the script
 if ( $_POST['payload'] ) {
  shell_exec("./pull.sh");
}

That GitHub project recommends an SSH key with no passphrase, which I agree at first (to test it out).
However, especially for private projects, it is best to run an ssh-agent and manage an ssh key passphrase protected.
As janos comments:

这篇关于从GitHub推送到Web服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 02:38
查看更多