11
14

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.

Deployerでサブディレクトリをデプロイする

Last updated at Posted at 2017-06-26

Laravelアプリケーションのデプロイに deployer を使い始めました。deployerにはLaravel用のレシピがあるのですぐに始められました。キューワーカーの再起動も1行追加すれば動きます。

サブディレクトリのデプロイができない

標準のdeployerはGitリポジトリのルートにアプリケーションが配置されていることが前提になっています。composer.jsonがルートに存在しないとエラーでデプロイできませんでした。
以下の構成のように webapp/ にアプリケーションを配置しているとき、deployerの標準設定ではエラーになります。

git@grohiro.github.com/myapp/
  webapp/ # ウェブ用のアプリ
    coposer.json
    app/
    ...
  api/ # API用のアプリ
    composer.json
    app/
  docs/ # 開発ドキュメントなど
    README.md
    ...

myappの階層でcomposer installを実行してエラーになる。webapp/の下で実行したい。

release_path 変数を書き換える

deployerのワーキングディレクトリは変数 release_path で定義されています。composer コマンドもここで実行されるのでエラーになります。
では release_path を書き換えればいいじゃないかと考えるんですが、ここを書き換えるとGitリポジトリからcloneしてくるディレクトリも変わってしまうので別の箇所がエラーになります。

git cloneが正常に動くようにしたままサブディレクトリをデプロイするため、git cloneが実行されたあとにrelease_pathを書き換えてしまいましょう。deplyerではafter()関数を使用します。

// deployer.php
task('change_cwd', function () {
  $subdir = get('release_path') . DIRECTORY_SEPARATOR . 'webapp';
  set('release_path', $subdir);
  run('cd {{release_path}}');
});

after('deploy:update_code', 'change_cwd');

deploy:update_codeタスクの後にディレクトリを変更することでcomposer installも動くようになりました。

参考

リポジトリに登録されているレシピは以下のようなものがあります(2017年6月)。

  • CakePHP
  • CodeIgniter
  • FuelPHP
  • Laravel
  • Symfony
  • Wordpress
  • Yii

リンク

11
14
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
11
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?