我想将我所有的网站都移到 GitHub 上,以获得所有明显的好处。我不是命令行的忠实粉丝,所以我喜欢 GitHub,因为它让我避免接触所有这些。在 GitHub 上设置存储库,然后将其与我的计算机同步非常简单。我需要能够自动从 GitHub 推送到网络服务器,所以当我在本地将某些内容更新到主分支时,将其与 GitHub 同步,它就会在网站上生效。通过谷歌搜索这个主题,似乎大多数技术要么需要命令行,要么看起来相当复杂。我想对大约 15-20 个站点执行此操作(其中许多站点托管在来自不同客户端的不同服务器上)。我想找到一个在我的技能范围内并且每个站点不需要 2-3 小时的选项。有人知道最好、最简单的设置方法吗?
最佳答案
复杂的部分是 webhook on GitHub
Every GitHub repository has the option to communicate with a web server whenever the repository is pushed to.
这意味着您的网站必须有一个进程来监听 GitHub 在收到提交后发送的那些 JSON 消息。
您可以看到这些监听器的多个示例,例如 webhook-deployer ,带有 auto.php(用于 php 服务器):
<?php
// Prevent accidental XSS
header("Content-type: text/plain");
// Run the script
if ( $_POST['payload'] ) {
shell_exec("./pull.sh");
}
那个 GitHub 项目推荐了一个没有密码的 SSH key ,我一开始同意(测试一下)。
但是,特别是对于私有(private)项目,最好运行一个 ssh-agent 并管理一个 ssh key 密码保护。
作为杰诺斯 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.
关于git - 从 GitHub 推送到 Web 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17367247/