通过GitHub webhook将本地代码同步到Amazon服务器 [英] Sync the local code to Amazon server through GitHub webhook

查看:207
本文介绍了通过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服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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