Deploy Node Application in Docker with Capistrano

之前有尝试过 shipit,不过其方式,插件和 bug,都蛮让人失望的。


Prepare

1
$ bundle init

修改 Gemfile 内容为以下:

1
2
3
source "http://ruby.taobao.org"
gem 'capistrano'

初始化当前目录为 Cap:

1
$ bundle exec cap install

会生成下面的一个目录结构(为简单,修改为prod.rb):

1
2
3
4
5
6
7
8
9
10
.
├── Capfile
├── config
│ ├── deploy
│ │ ├── prod.rb
│ │ └── staging.rb
│ └── deploy.rb
└── lib
└── capistrano
└── tasks


Cap Config

deploy.rb 文件主要是配置所有发布环境的公共配置

config/deploy.rb
1
2
3
set :application, 'd2labs_beta'
set :deploy_user, 'deploy'
set :repo_url, 'git@github.org:lanvige/test.git'

除了公共配置文件外,每个环境都有自己的配置文件:

config/depoly/prod.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
set :stage, :production
set :branch, 'master'
# Extended Server Syntax
server '10.10.10.1', user: 'deploy', roles: %w{web app db}
# used in case we're deploying multiple versions of the same
# app side by side. Also provides quick sanity checks when looking
# at filepaths
set :full_app_name, "#{fetch(:application)}"
## where to put the app
set :deploy_to, "/home/#{fetch(:deploy_user)}/apps/#{fetch(:full_app_name)}"

在Deploy 前,我们还需要添加一些功能,将site-enabled/nginx.conf的配置文件添加到Remote Server下。


Prepare


Deploy