• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

git-deploy: git deployment made easy

原作者: [db:作者] 来自: 网络 收藏 邀请

Easy git deployment

Straightforward, Heroku-style, push-based deployment. Your deploys can become as simple as this:

$ git push production master

To get started, install the "git-deploy" gem.

gem install git-deploy

Only the person who is setting up deployment for the first time needs to installthe gem. You don't have to add it to your project's Gemfile.

Which app languages/frameworks are supported?

Regardless of the fact that this tool is mostly written in Ruby, git-deploy can be useful for any kind of code that needs deploying on a remote server. The default scripts are suited for Ruby web apps, but can be edited to accommodate other frameworks.

Your deployment is customized with per-project callback scripts which can be written in any language.

The assumption is that you're deploying to a single host to which you connect over SSH using public/private key authentication.

Initial setup

  1. Create a git remote for where you'll push the code on your server. The name of this remote in the examples is "production", but it can be whatever you wish ("online", "website", or other).

    git remote add production "[email protected]:/apps/mynewapp"

    /apps/mynewapp is the directory where you want your code to reside on theremote server. If the directory doesn't exist, the next step creates it.

  2. Run the setup task:

    git deploy setup -r "production"

    This will initialize the remote git repository in the deploy directory(/apps/mynewapp in the above example) and install the remote git hook.

  3. Run the init task:

    git deploy init

    This generates default deploy callback scripts in the deploy/ directory.You should check them in git because they are going to be executed on theserver during each deploy.

  4. Push the code.

    git push production master
  5. Login to your server and manually perform necessary one-time administrative operations. This might include:

    • set up the Apache/nginx virtual host for this application;
    • check your config/database.yml and create the production database.

Everyday deployments

If you've set your app correctly, visiting http://example.com in your browsershould show it up and running.

Now, subsequent deployments are done simply by pushing to the branch that iscurrently checked out on the remote:

git push production master

Because the deployments are performed with git, nobody else on the team needs toinstall the "git-deploy" gem.

On every deploy, the default deploy/after_push script performs the following:

  1. updates git submodules (if there are any);
  2. runs bundle install --deployment if there is a Gemfile;
  3. runs rake db:migrate if new migrations have been added;
  4. clears cached CSS/JS assets in "public/stylesheets" and "public/javascripts";
  5. restarts the web application.

You can customize all this by editing generated scripts in the deploy/directory of your app.

Deployments are logged to log/deploy.log in your application's directory.

How it works

The git deploy setup command installed a post-receive git hook in the remoterepository. This is how your code on the server is kept up to date. This scriptchecks out the latest version of your project from the current branch andruns the following callback scripts:

  • deploy/setup - on first push.
  • deploy/after_push - on subsequent pushes. It in turn executes:
    • deploy/before_restart
    • deploy/restart
    • deploy/after_restart
  • deploy/rollback - executed for git deploy rollback.

All of the callbacks are optional. These scripts are ordinary Unix executables.The ones which get generated for you by git deploy init are written in shellscript and Ruby.

Extra commands

  • git deploy hooks - Updates git hooks on the remote repository

  • git deploy log [N=20] - Shows last 20 lines of deploy log on the server

  • git deploy rerun - Re-runs the deploy/after_push callback as if a git push happened

  • git deploy restart - Runs the deploy/restart callback

  • git deploy rollback - Undo a deploy by checking out the previous revision,runs deploy/rollback if exists instead of deploy/after_push

  • git deploy upload <files> - Copy local files to the remote app


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap