通过GitHub webhook将本地代码同步到Amazon服务器

编程入门 行业动态 更新时间:2024-10-21 20:25:35
本文介绍了通过GitHub webhook将本地代码同步到Amazon服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在关注部署的教程使用GitHub的webhook将Node.js应用程序加载到Amazon服务上。

在Amazon服务器上,我创建了一个名为hook的存储库,并将其初始化为GitHub仓库 $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $

然后我创建了一个githook

$ cat> hooks / post-receive GIT_WORK_TREE = / home / ubuntu / myapp git checkout -f echo安装依赖关系... cd / home / ubuntu / myapp npm install echoRestarting node.js ... $ chmod + x hooks / post-receive

我认为这是在服务器端完成的,所以我回到GitHub存储库并添加一个WebHook URL。但我不知道如何填写这个网址,所以我输入

ssh://ubuntu@54.201.12.68/ home / ubuntu / hook

我认为这是不正确的。

我在Windows平台上提交并推送本地存储库,因此预计Amazon服务器端不会收到任何内容。

我认为这很可能由于在GitHub存储库设置中输入了错误的webhook URL,您认为什么?

为了接收更新,我必须使用URL设置服务器吗?并执行bash?

解决方案

当提交到服务器时,您的AWS服务器的post-receive git钩子将被执行:

#在你的开发机器上 git remote add aws ssh://ubuntu@54.201.12.68/home/ubuntu/ git push aws master

GitHub的Web挂钩通过发送HTTP POST请求到URL你脓的时候提供的h新的提交给GitHub。如果您希望在将代码推送到GitHub 时自动更新您的站点,则需要更多的部分:在您的机器上运行的HTTP服务器,它将接受 webhook有效负载,从GitHub中取出新代码,然后重新部署。有另一个问题,有很多可能的尝试。

I am following a tutorial on deploying a Node.js app onto the Amazon service with GitHub's webhook.

On the Amazon server, I have created a repository named hook, and initialized it as a GitHub repository

$ mkdir hook $ cd hook $ git init --bare

Then I created a githook

$ cat > hooks/post-receive GIT_WORK_TREE=/home/ubuntu/myapp git checkout -f echo "Installing dependencies..." cd /home/ubuntu/myapp npm install echo "Restarting node.js..." $ chmod +x hooks/post-receive

I think this is done on the server side, so I go back to the GitHub repository and add a WebHook URL. But I don't know how to fill in this URL, so I input

ssh://ubuntu@54.201.12.68/home/ubuntu/hook

which I think it is not right.

I commit and push my local repository on Windows platform, so as expected nothing is received on the Amazon server side.

I think it is probably due to the wrong webhook URL input at the GitHub repository setting, what do you think?

Do I have to set up a server with a URL in order to receive the updates and execute the bash?

解决方案

Your AWS server's post-receive git hooks will be executed when commits are pushed to that server:

# On your development machine git remote add aws ssh://ubuntu@54.201.12.68/home/ubuntu/ git push aws master

GitHub's web hooks work by sending an HTTP POST request to the URL that you provide when you push new commits to GitHub. If you want your site to be updated automatically when you push code to GitHub, you need one more piece: an HTTP server running on your machine that will accept the webhook payload, pull the new code from GitHub, and then redeploy. There's another question that has a bunch of possiblities you might try.

更多推荐

通过GitHub webhook将本地代码同步到Amazon服务器

本文发布于:2023-10-11 22:49:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483060.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   服务器   GitHub   webhook   Amazon

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!