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

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

问题描述

我有一个项目,我将其从本地计算机推送到GitHub存储库.我将这个项目部署在我现在必须ssh并执行git pull的DigitalOcean Droplet上,然后手动重新部署.是否有一种简单的方法可以使其自动拉动,然后自动进行构建和重新部署?我已经研究过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-receivepost-update钩子中.但是,GitHub默认情况下不允许您运行任意挂钩,因为这会带来安全风险.相反,您可以使用 GitHub的webhooks 通过发出POST请求来触发您的Droplet执行某些操作它.

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.

最后,您可以设置一个远程名称(例如foo),该名称具有多个remote.foo.url条目,其中之一是GitHub,其中之一是您的Droplet.然后,您可以使用该遥控器同时推送到两个对象,在这种情况下,您的post-receivepost-update挂钩将在Droplet上触发(因为它已收到推送).如果有签出,则可以使用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天全站免登陆