Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
188 views
in Technique[技术] by (71.8m points)

git - Sync the local code to Amazon server through GitHub webhook

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://[email protected]/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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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://[email protected]/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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...