从GitLab安装自定义Composer软件包

lys*_*xia 5 php git wordpress composer-php

我创建了一个简单的测试wordpress插件。该插件包含一个php文件(kreplach.php)和一个composer.json:

kreplach.php

<?php
    /*
    Plugin Name: kreplach
    Plugin URI: http://gitlab.example.com/sales/kreplach
    Description: just a test
    Author: Foo Bartok
    Version: 1.0
    Author URI: http://example.com
    */
?>
Run Code Online (Sandbox Code Playgroud)

composer.json

{
    "license": "MIT",
    "name": "sales/kreplach",
    "type": "wordpress-plugin",
    "description": "just a test",
    "authors": [
        {
            "name": "Foo Bartok",
            "email": "foo@example.com",
            "homepage": "example.com"
        }
    ],
    "require": {
        "composer/installers": "*"
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的开发服务器上,我有以下composer.json

服务器的composer.json

{
    "repositories": [
        {
            "type": "composer",
            "url": "https://wpackagist.org"
        },
        {
            "type": "vcs",
            "url": "git@gitlab.example.com:sales/kreplach.git"
        }
    ],
    "require": {
        "php": ">=5.4",
        "wpackagist-plugin/akismet": "*",
        "wpackagist-plugin/contact-form-7": "*",
        "wpackagist-plugin/wordpress-importer": "*",
        "sales/kreplach": "master",
        "johnpbloch/wordpress": "4.*",
        "composer/installers": "*"
    },
    "extra": {
        "wordpress-install-dir": "wp"
    }
}
Run Code Online (Sandbox Code Playgroud)

我认为应该发生的事情:

  1. Composer通过git repo查找composer.json
  2. Composer与在构建主机的composer.json中找到的名称“ sales / kreplach”匹配
  3. Composer将master分支的内容复制到wp-content/plugins/kreplach我的构建主机上。
  4. 按照设计,我的假插件没有任何作用。

实际发生的情况:

苦,苦的失败。

Loading composer repositories with package information Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - The requested package sales/kreplach could not be found in any version, there may be a typo in the package name.

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
     see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.

Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
Run Code Online (Sandbox Code Playgroud)

我已经测试过将存储sales/kreplach库克隆到要安装插件的主机上。

为了确保composer实际上是从git repo读取composer.json文件,我引入了一个错字(是的,完全是故意的,例如),并抛出“嘿,这个json文件已损坏,Foam Head”错误。

我的gitlab版本是omnibus版本8.6.4(今天安装)。

我已经成功地使用pip / requirements.txt完成了相同的技巧,以安装自定义python模块,因此我并没有遵循以下说明。我错过了一步,还是某种(至少对我来说)不明显的术语?

Dav*_*ara 0

我没有使用过 gitlab,但在 Bitbucket 和 GitHub 上经常使用这种方法。

您需要"sales/kreplach": "dev-master"在服务器的composer.json中指定 - 请注意,分支名称必须以“dev-”为前缀。

显然,Composer 对 GitHub 和 BitBucket 有特殊支持,而 Gitlab 可能不存在……因此您可能需要指定git为存储库类型而不是vcs.

祝你好运!

参考文献: