使用Git push部署项目

是否可使用git push部署网站? 我有一种预感,它与使用git钩子在服务器端执行git reset --hard有关,可是我将如何实现呢? html


#1楼

我最终建立了本身的基本部署工具,该工具会自动从存储库中提取新更新-https: //github.com/jesalg/SlimJim-基本上,它会侦听github post-receive-hook并使用代理触发更新脚本。 git


#2楼

咱们使用capistrano来管理部署。 咱们构建了capistrano以部署在登台服务器上,而后与咱们全部的服务器运行rsync。 github

cap deploy
cap deploy:start_rsync (when the staging is ok)

使用capistrano,咱们能够在发生错误的状况下轻松回滚 web

cap deploy:rollback
cap deploy:start_rsync

#3楼

我对基督徒的解决方案的见解。 api

git archive --prefix=deploy/  master | tar -x -C $TMPDIR | rsync $TMPDIR/deploy/ --copy-links -av username@server.com:/home/user/my_app && rm -rf $TMPDIR/deploy
  • 将主分支归档到tar中
  • 将tar存档提取到系统temp文件夹中的deploy dir中。
  • rsync更改到服务器
  • 从临时文件夹中删除deploy目录。

#4楼

我正在使用toroid.org提供的如下解决方案,该解决方案具备更简单的挂钩脚本。 服务器

在服务器上: app

$ mkdir website.git && cd website.git
$ git init --bare
Initialized empty Git repository in /home/ams/website.git/

并将钩子安装在服务器上: ssh

$ mkdir /var/www/www.example.org
$ cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/var/www/www.example.org git checkout -f
GIT_WORK_TREE=/var/www/www git clean -f -d # clean directory from removed files

$ chmod +x hooks/post-receive

在您的客户上: 工具

$ mkdir website && cd website
$ git init
Initialized empty Git repository in /home/ams/website/.git/
$ echo 'Hello, world!' > index.html
$ git add index.html
$ git commit -q -m "The humble beginnings of my web site."

$ git remote add web ssh://server.example.org/home/ams/website.git
$ git push web +master:refs/heads/master

而后发布,只需键入 post

$ git push web

网站上有完整的描述: http : //toroid.org/ams/git-website-howto


#5楼

我这样作的方法是,在个人部署服务器上有一个裸露的Git存储库,用于推送更改。 而后,我登陆到部署服务器,更改成实际的Web服务器docs目录,而后执行git pull。 我不使用任何钩子来尝试自动执行此操做,这彷佛比它值得的麻烦更多。

相关文章
相关标签/搜索