Programing

Git 푸시 (GitHub 및 node.js) 후 내 앱을 자동으로 배포하려면 어떻게해야합니까?

lottogame 2020. 9. 1. 07:55
반응형

Git 푸시 (GitHub 및 node.js) 후 내 앱을 자동으로 배포하려면 어떻게해야합니까?


내 애플리케이션 (node.js)이 VPS (리눅스)에 배포되어 있습니다. git 허브를 저장소로 사용하고 있습니다. git push에서 애플리케이션을 자동으로 배포하려면 어떻게해야합니까?


PHP의 예 :

github 저장소로 이동하여 "Admin"을 클릭하십시오.

'서비스 후크'=> 'WebHook URL'탭을 클릭하십시오.

추가

http://your-domain-name/git_test.php

그런 다음 git_test.php를 만듭니다.

<?php 
try
{
  $payload = json_decode($_REQUEST['payload']);
}
catch(Exception $e)
{
  exit(0);
}

//log the request
file_put_contents('logs/github.txt', print_r($payload, TRUE), FILE_APPEND);


if ($payload->ref === 'refs/heads/master')
{
  // path to your site deployment script
  exec('./build.sh');
}

build.sh에서 github에서 사이트를 검색하려면 일반적인 명령을 입력해야합니다.


답변 / 코멘트로 Git 후크에 대한 언급이 몇 개 있었는데, 이는 과거에 저에게 효과적이었습니다. 다른 사람이 더 구체적인 정보를 필요로하는 경우 여기에 제 레시피가 있습니다.

git post-receive hooknode-supervisor 의 조합을 사용하여 간단한 자동 배포를 수행합니다 (해당 머신에서 git 원격 저장소를 사용한다고 가정).


수신 후 후크 설정

저장소에서 : sudo vi hooks/post-receive

그리고 다음과 같이 보일 것입니다.

#!/bin/sh
GIT_WORK_TREE=/home/path/to/your/www
export GIT_WORK_TREE
git checkout -f

파일 권한 설정 : chmod +x hooks/post-receive

Git은 저장소에 푸시 한 후 앱 디렉토리의 파일을 새로 고칩니다.


Node-Supervisor로 노드 실행

머신에 전역 노드 모듈로 Node-Supervisor를 설치해야합니다. sudo npm install supervisor -g

이제 node-supervisor로 노드 앱을 실행하기 만하면 작업 디렉토리의 파일에 대한 변경 사항을 감시합니다.

supervisor /home/path/to/your/www/server.js( supervisor대신 참고 node).


여기에 응답하기에는 아마도 매우 늦었을 것입니다. 그러나 나는이 프로젝트를 github에서 발견하고 원하는 것을 훨씬 더 깔끔하게 수행하는 것 같습니다.

https://github.com/logsol/Github-Auto-Deploy

확인 해봐. 댓글과 찬성에 대해 다른 사람들이 어떻게 생각하는지 알고 싶을 것입니다.

건배,
S


현재 개발중인 프로젝트에서 Jez Humble의 훌륭한 책 "Continuous Delivery"(읽을만한 가치가 있음)에서 다루는 지침을 따릅니다.

즉, 어떤 형태의 지속적인 통합 서버를 사용하여 배포 파이프 라인을 생성하는 것을 의미합니다 (저는 Go의 Thoughtworks 무료 커뮤니티 에디션을 사용 합니다 ). 먼저 코드의 품질, 복잡성 및 실행 단위 테스트를 확인해야합니다. 그런 다음 배포 파이프 라인을 따라 프로덕션 서버로 푸시 할 수 있습니다.

This sounds very complicated, but doesn't have to be, and does make the whole process of writing code and it making it's way into production safe and worry free (no scary release days!).

I use a full deployment pipeline for live systems, and a cut down version for npm modules that I write, and both share the same 1-click deployment technique.


I just published a node-based solution to your problem: node-cd

It consists in a simple node app running on your VPS that will receive Github post-receive Hooks and execute a the script you like (for example a shell script that will kill your app, git pull, and restart it).


Here's another simple nodeJS implementation.

It's a very simple node server that runs on a hostname and port you configure and can be setup to handle GitHub post receive web hooks. And the actual pul/test/deploy actions can be customised to do anything you want. In the current implementation, it is a shell command that is specified inline in the nodeJS server script. And there is a very simple secret_key based security scheme in place as well.

https://github.com/shyam-habarakada/rscds

My staging server already had node installed and running, so writing this up was quick and easy.


I found the project for easy deployment uses git.

git-play

I think it's proper way for you.

Check it out.


If you want a python/tornado-based solution, I wrote a script to handle POST requests from Github's Webhook Services. You can find it at https://github.com/Akobi/ops/tree/master/autodeploy

It basically uses a JSON config file to list which repos you expect pushes from, which commands you want to run on deploy, and what directory the commands must run in. All you would have to do is modify the config file to your liking and run the script!

In addition, I use Nginx as a reverse proxy to forward these POSTs to my script. You can find the Nginx config in the same Github repo under the 'nginx' folder.

Happy pushing!


the PHP answer is totally legit in my opinion, but if you prefer Ruby, I blogged a solution. it's the same thing as the PHP answer, just in a different language. you use a web hook and you have a simple script listen for the relevant HTTP requests.

http://gilesbowkett.blogspot.com/2012/06/heroku-style-deployment-on-ec2.html


I've created my own rudimentary deployment tool which would automatically pull down new updates from the repo - https://github.com/jesalg/SlimJim - Basically it listens to the github post-receive-hook and uses a proxy to trigger an update script.


I'm the founder of https://commando.io and recently we announced an integration with GitHub via a service. The integration allows you to run executions on servers when you push to a GitHub repo. This is a perfect opportunity to automatically run deployment scripts when you push code.

An execution is a script you write inside of Commando.io that can be written in bash, perl, python, ruby, go, or node.js. To read more, and see an example execution script of running git pull, see our blog post announcement: http://blog.commando.io/run-executions-via-github-push/


Deepl.io seems to be new and promising contender in this space.

Features (taken from its website):

  • Catch webhooks from GitLab & GitHub
  • Configure multiple repositories
  • Configure multiple branches per repository
  • Use your own deploy scripts, either PHP, shell or both
  • Sends confirmation emails

Also note there are free/inexpensive services out there like REPOMAN.IO that automate almost all of this for you.

참고URL : https://stackoverflow.com/questions/9132144/how-can-i-automatically-deploy-my-app-after-a-git-push-github-and-node-js

반응형