从本地机器推送后,从远程 DigitalOcean 服务器上的 GitHub 存储库自动拉取? [英] Auto pull from GitHub repository on remote DigitalOcean server after push from local machine?

查看:30
本文介绍了从本地机器推送后,从远程 DigitalOcean 服务器上的 GitHub 存储库自动拉取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从本地机器推送到 GitHub 存储库的项目.我将这个项目部署在 DigitalOcean droplet 上,我目前必须通过 ssh 进入并执行 git pull,然后手动重新部署.有没有一种简单的方法可以让它自动拉动,然后自动构建和重新部署?我已经研究了 git hooks,但找不到任何关于我正在尝试做的事情的明确答案.我在远程机器上设置了一个更新后的 git 钩子,它只回显一行,但我不知道在哪里检查该行是否得到回显.

I have a project that I push to a GitHub repository from my local machine. I deploy this project on a DigitalOcean droplet that I currently have to ssh into and do a git pull, then redeploy manually. Is there an easy way to have it auto pull, and then auto build and redploy itself? I have looked into git hooks but couldn't find any clear answers on what I am trying to do. I set up a post-update git hook on my remote machine which just echos a line but I don't know where to check if the line got echoed or not successfully.

推荐答案

你需要运行 Git 钩子的地方是在服务器端,在 post-receive更新后 钩子.但是,GitHub 默认不允许您运行任意挂钩,因为这会带来安全风险.相反,您可以使用 GitHub 的 webhooks 通过向

The place you'd need to run the Git hooks is on the server side, in the post-receive or post-update hook. However, GitHub doesn't allow you to run arbitrary hooks by default, since that would be a security risk. Instead, you can use GitHub's webhooks to trigger your droplet to perform some action by making a POST request to it.

您还可以设置某种持续集成,以自动触发构建并将构建部署到您的 Droplet.这通常是管理此类任务的方式.

You could also have some sort of continuous integration set up that would trigger and deploy a build to your droplet automatically. This is usually how this type of task is managed.

最后,您可以设置一个具有多个 remote.foo.url 条目的远程名称(例如,foo),其中一个是 GitHub,一个是这是你的水滴.然后,您可以使用该遥控器同时推送到两者,在这种情况下,您的 post-receivepost-update 钩子将在液滴上触发(因为它收到推).如果有签出,您可以使用 receive.denyCurrentBranch=updateInstead,这将让您推送到已经签出的同一分支.详情请参阅 git-config(1).

Finally, you can set up a remote name (say, foo) that has multiple remote.foo.url entries, one of which is GitHub, and one of which is your droplet. You can then push to both at the same time by using that remote, in which case your post-receive or post-update hook will trigger on the droplet (since it received the push). If there's a checkout, you can use receive.denyCurrentBranch=updateInstead, which will let you push to the same branch that's already checked out. See git-config(1) for more details.

这篇关于从本地机器推送后,从远程 DigitalOcean 服务器上的 GitHub 存储库自动拉取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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