4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

capistrano3.0で非railsを配置してみる

Last updated at Posted at 2013-11-27

capistrano 3.0.1使って非railsアプリをサーバ上に配置してみた。
capistrano2でやってみた記事はこちら capistrano2で非railsを配置してみる - Qiita [キータ]

試してみた手順

$ mkdir test
$ cd test

$ bundle init
$ echo 'gem "capistrano"' >> Gemfile
$ bundle install --path vendor/bundle

$ bundle exec cap install
mkdir -p config/deploy
create config/deploy.rb
create config/deploy/staging.rb
create config/deploy/production.rb
mkdir -p lib/capistrano/tasks
Capified

$ tree -L 3
.
├── Capfile
├── Gemfile
├── Gemfile.lock
├── config
│   ├── deploy
│   │   ├── production.rb
│   │   └── staging.rb
│   └── deploy.rb
├── lib
│   └── capistrano
│       └── tasks
└── vendor
    └── bundle
        └── ruby
  • config/deploy/staging.rbで接続サーバを設定

    • コメントアウトしてあるところを参照
  • config/deploy.rbを設定

    • 一部コメントアウトを外して設定
set :application, 'MyTips'                                                                                          
set :repo_url, 'https://github.com/mechamogera/MyTips'
set :scm, :git

set :deploy_to, '/var/www/my_app'
set :keep_releases, 5
...
  • EC2(AmazonLinux)を作成
    • 以下のように初期設定
# EC2上
$ sudo yum install git httpd -y
$ sudo mkdir /var/www/my_app
$ sudo chown ec2-user:ec2-user /var/www/my_app
  • capistrano実行
$ bundle exec cap staging deploy
  • EC2側確認
    • current:現在のリリースへのシンボルリンク
    • releases/[日時]:リリース毎にリポジトリーのミラーから作成されるgit archiveの解凍ディレクトリ
    • repo:リポジトリのミラー(ディレクトリなければclone --mirror、あればgit remote updateかな)
    • share:各リリース間で共通なファイルが配置され各リリースにリンクされるはず
$ tree -L 2 /var/www/my_app/
/var/www/my_app/
├── current -> /var/www/my_app/releases/20131127025659 
├── releases
│   └── 20131127025659
├── repo
│   ├── branches
│   ├── config
│   ├── description
│   ├── FETCH_HEAD
│   ├── HEAD
│   ├── hooks
│   ├── info
│   ├── objects
│   ├── packed-refs
│   └── refs
├── revisions.log
└── shared

capistranoのフローメモ

  • Flow - Capistrano
    • 複数サーバーを指定した場合各フロー毎に各サーバーに処理を実施
    • 1つでも処理に失敗すると即停止
  1. deploy:starting 初期化
  2. deploy:started started hook
  3. deploy:updating releaseを取得して配置
  4. deploy:updated updated hook
  5. deploy:publishing currentのシンボルリンクを更新
  6. deploy:published published hook
  7. deploy:finishing 余分なreleaseを削除
  8. deploy:finished finished hook
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?