从GitHub推送到Web服务器 [英] Pushing from GitHub to a Web Server

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

问题描述

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

解决方案

复杂的部分是 GitHub上的webhook


每个GitHub存储库都可以选择在存储库推送到时与Web服务器通信。


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

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

 <?php 

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

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

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

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

As janos 评论



  • 如果GitHub存储库是公共的,那么他甚至不需要它。

  • 如果回购是私人的,那么他需要它,但这不应该这么轻率。如果可能的话,他应该使用密钥代理。

    如果这太复杂了,那么他可以使用专用的SSH密钥而不使用密码短语来进行此部署,并且该密钥不应该离开部署PC。
  • b $ b


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

Every GitHub repository has the option to communicate with a web server whenever the repository is pushed to.

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:

  • If the GitHub repository is public, then he doesn't even need one.
  • If the repo is private, then he needs it, but this should not be taken so lightly. If possible he should use a key agent.
    If that's too complicated then he could use a dedicated SSH key without passphrase just for this deployment, and that key should never leave the deployment PC.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆