使用git将我的node.js应用程序部署到我的生产服务器 [英] using git to deploy my node.js app to my production server

查看:108
本文介绍了使用git将我的node.js应用程序部署到我的生产服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的开发机器上有一个本地git仓库。



我想用git将代码推送到我的生产服务器。并在代码被推送到那里时触发Web服务器的重启。



执行此操作的命令是什么?我使用的是debian。



/var/www/example.com 是我的本地存储库



生产主机名是 production.example.com 我已经设置了ssh + keys。

解决方案

将代码直接推送到实时网站通常不是一个好主意。为此,您可以在公用目录之外的服务器上创建裸存储库。这个存储库会将更改推送到您的Live网站存储库,并且将成为您网站的门卫。要设置,请在您的网站目录中创建一个存储库:
$ git add。
$ git commit -m初始导入已存在的Web文件

创建,移动到通过HTTP无法访问的目录。为了简单起见,我们可以将这个裸目录HUB和网站目录LIVE称为。在这里初始化一个仓库:

  $ cd; mkdir site_hub.git; cd site_hub.git 
$ git --bare init

然后,从您的网站工作目录,将此裸仓库添加为远程服务器并推送实时网站的主分支。

  $ cd〜/ www 
$ git remote add hub〜/ site_hub.git
$ git remote show hub
* remote hub
URL:/home/rizwan/site_hub.git
$ git push hub master

您需要使用挂钩将更改提交到实时存储库。在HUB存储库中创建一个更新后的钩子:

 #! / bin / sh 

echo
echo****将更改拉入Live [Hub的更新后的挂钩]
echo

cd $ HOME / www ||退出
取消设置GIT_DIR
git拉中心大师

执行git-update-server-info

在这个钩子中,你可以让代码在完成pull之后重启服务器。



另外,创建一个 post-commit 在LIVE repo上挂钩,将修改后的内容发送到HUB。

 #!/ bin / sh 

echo
echo****将更改推送到Hub [Live的提交后挂接]
echo

git push hub

在您的本地机器上,将HUB存储库添加为远程推送更改:

  git remote add hub< hub-repository-url> 

这是如何工作的,您可以编写一些代码并将其推送到裸仓库, -update挂钩将更改推送到实时存储库并重新启动服务器。


I have a local git repository on my development machine.

I want to use git to push the code up to my production server. and trigger a restart of the web server once the code has been pushed there.

What are the commands to do this? I'm using debian.

/var/www/example.com is my local repository

Production hostname is production.example.com I have ssh + keys already setup.

解决方案

It is usually not a good idea to push code directly to a live website. For this you can create a bare repository on your server, outside the public directory. This repository will push changes to your Live website repository and will be like the gate keeper for your Website. To set things up, create a repository around your live website directory:

$ cd ~/www
$ git init
$ git add .
$ git commit -m"initial import of pre-existing web files"

With this created, move to a directory not accessible via HTTP. To keep things simple,lets call this bare directory HUB and the website directory LIVE. Initialize a bare repository here:

$ cd; mkdir site_hub.git; cd site_hub.git
$ git --bare init

Then, from inside your live website working directory, add this bare repository as a remote and push live website’s master branch.

$ cd ~/www
$ git remote add hub ~/site_hub.git
$ git remote show hub
* remote hub
  URL: /home/rizwan/site_hub.git
$ git push hub master

You need hooks to commit changes to the live repository. Create a post-update hook inside the HUB repository :

#!/bin/sh

echo
echo "**** Pulling changes into Live [Hub's post-update hook]"
echo

cd $HOME/www || exit
unset GIT_DIR
git pull hub master

exec git-update-server-info

Inside this hook, you can have the code to restart the server after the pull is completed.

Also, create a post-commit hook on the LIVE repo to send changes done to the live website back to HUB.

#!/bin/sh

echo
echo "**** pushing changes to Hub [Live's post-commit hook]"
echo

git push hub

On your local machine, add the HUB repository as a remote and push changes to it:

git remote add hub <hub-repository-url>

How this works is, you write some code and push it to the bare repository, which using its post-update hook to push changes to the live respository and restart the server.

这篇关于使用git将我的node.js应用程序部署到我的生产服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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