LoginSignup
0
0

More than 5 years have passed since last update.

OctoberCMS自作プラグインを個別gitレポジトリで管理し、composerでインストールさせる

Last updated at Posted at 2016-10-22

OctoberCMSのサイトで自作プラグインを登録すれば、OctoberCMSのバックエンド(管理画面)からGUIでプラグインをインストールできるが、これだと、サーバに自動デプロイすることができない。
そこで、composerでインストールできるようにしておくと便利だ。更にgithubなどから持ってきてもらえればpackagistにも登録する必要ないし、プライベートのレポジトリを使用できる。

手順

  1. 自作プラグインのルートにcomposer.jsonを作成する。
  2. プラグインを使用する側のcomposer.jsonで、依存関係に登録し、レポジトリを指定する。

プラグインのcomposer.json

{
    "name": "pikanji/utilitycollection-plugin",
    "type": "october-plugin",
    "require": {
        "php": ">=5.5.9",
        "composer/installers": "~1.0"
    },
    "license": "MIT",
    "authors": [
        {
            "name": "Kanji Furuhashi",
            "email": "pikanji@gmail.com"
        }
    ]
}
  • nameはレポジトリ名とは関係ない。
  • typeoctober-pluginとすることで、OctoberCMSのpluginsディレクトリの下にnameの構造でインストールされる。name-pluginサフィックスがついている場合はそれを除いた部分がディレクトリ名になる。
  • 上記の場合、plugins/pikanji/utilitycollectionとなる。
  • 非公開パッケージの場合、licenseproprietaryで。こちら参考。

依存する側のcomposer.json

{
    ...
    "require": {
        ...
        "pikanji/utilitycollection-plugin": "dev-master",
        ...
    },
    ...
    "repositories": [
        {                                                           
            "url": "git@bitbucket.org:pikanjidevteam/utilitycollection-plugin.git",             
            "type": "git"                                              
        }                                                           
    ]
}
  • requireにプラグイン側のcomposer.jsonのnameの値を指定する。
  • dev-masterはバージョン・エイリアス。dev-hogeとするとhogeブランチから取ってきてくれる。
  • このプラグインのレポジトリをrepositoriesで指定する。
  • 注意:composer.jsonは最後の項目の後に","がついているとエラーになる。

これで、composer updateすることで、このレポジトリから指定したプロジェクトがプラグインディレクトリにインストールされる。

デプロイする時は、composer.lockを含めていればcomposer installで同じバージョンがインストールされる。

プライベートレポジトリを指定する場合は、composer installを実行するユーザがレポジトリにアクセスできる様にSSHキーの設定をしてある必要がある。
それはまた別の話なので割愛する。

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