LoginSignup
7
2

More than 5 years have passed since last update.

Capistrano 3 でデプロイサーバから対象サーバにコピー

Last updated at Posted at 2017-02-09

デプロイサーバはインターネットとやりとりできる環境にあるけど、デプロイ対象のサーバはプライベートなネットワークで、外には繋がらない(デプロイサーバとはsshで繋がる)、というような環境で、Capistranoを使ってデプロイする場合。

これを使うのが良さげ。

Creates a tar archive locally from the git repository and uploads it to the remote server.

とのことで、ローカルでgitリポジトリの内容をアーカイブしてからリモートサーバに転送するよ、とのこと。

背景

同じ目的で、 https://github.com/xuwupeng2000/capistrano-scm-gitcopy もあるが、ReadMe通りに設定すると、現行のバージョン(3.7)では次のような警告が出る。
なので、代替物を探してみた。

[Deprecation Notice] `set :scm, :gitcopy` is deprecated.
To ensure this custom SCM will work with future versions of Capistrano,
please upgrade it to a version that uses the new SCM plugin mechanism
documented here:

http://capistranorb.com/documentation/advanced-features/custom-scm

セットアップ

ReadMeに従って設定。

Capfile

Capfile
# Load the SCM plugin appropriate to your project:
#
# require "capistrano/scm/hg"
# install_plugin Capistrano::SCM::Hg
# or
# require "capistrano/scm/svn"
# install_plugin Capistrano::SCM::Svn
# or
# require "capistrano/scm/git"
# install_plugin Capistrano::SCM::Git

# Capistrano::GitCopy plugin
# https://github.com/ydkn/capistrano-git-copy
require 'capistrano/git_copy'
install_plugin Capistrano::GitCopy::SCM

通常は、この部分、

# require "capistrano/scm/git"
# install_plugin Capistrano::SCM::Git

が活きているが、コメントアウトして、 git_copy のものに設定する。

実行

あとは、通常通り、デプロイすればOK。

$ bundle exec cap develop deploy
00:00 git_copy:check
      01 git ls-remote --heads ssh://precure@git.example.com:11234/hoge/fuga.git

...

00:10 git_copy:create_release
      01 /home/precure/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/capistrano-git-copy-1.3.0/vendor/git-archive-all/git_archive_all.py --prefix='' /tmp/hogefuga…
    ✔ 01 precure@localhost 0.172s
      02 mkdir -p /var/www/magical.example.com/releases/20170209132532
    ✔ 02 precure@app-magical-001 1.146s
    ✔ 02 precure@app-magical-002 1.158s
      Uploading /tmp/hogefuga_develop_7a0eea46_43432c0e/archive.tar.gz 12.81%
      Uploading /tmp/hogefuga_develop_7a0eea46_43432c0e/archive.tar.gz 25.62%
      Uploading /tmp/hogefuga_develop_7a0eea46_43432c0e/archive.tar.gz 38.44%
      ...

といった感じで、固めた上でコピーしてくれる。

7
2
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
7
2