composer gitlab 搭建私包

Posted 一根PHP

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了composer gitlab 搭建私包相关的知识,希望对你有一定的参考价值。

一、建立私包git

1、执行composer init 根据提示生成composer.json

2、编辑composer.json 目录格式

{
    "name": "iaround/lib",
    "description": "iaround lib",
    "license": "MIT","require": {
        "dingo/api": "[email protected]",
        "predis/predis":"^1.1",
        "illuminate/redis":"^5.4",
        "cheprasov/php-redis-client": "^1.6",
        "webpatser/laravel-uuid": "2.*",
        "newiep/httpsqs": "dev-master",
        "stomp-php/stomp-php": "^4.2"
    },
    "autoload": {
        "psr-4": {
            "App\\Lib\\Cache\\": "src/Lib/Cache/",
            "App\\Lib\\DataStore\\": "src/Lib/DataStore/",
            "App\\Lib\\Enums\\": "src/Lib/Enums/",
            "App\\Lib\\I18N\\": "src/Lib/I18N/",
            "App\\Lib\\MemCache\\": "src/Lib/MemCache/",
            "App\\Lib\\Models\\": "src/Lib/Models/",
            "App\\Lib\\MQ\\": "src/Lib/MQ/",
            "App\\Lib\\SQS\\": "src/Lib/SQS/",
            "App\\Lib\\Struct\\": "src/Lib/Struct/",
            "App\\Lib\\Tools\\": "src/Lib/Tools/"
        },
        "files": [
            "src/Lib/Helps.php"
        ]
    },
    "minimum-stability": "stable"
}

3、提交代码到gitlab.

 

二、引用私包

1、以laravel框架为例,安装初始化laravel自行完成。

2、编辑laravel的composer.json 

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "minimum-stability": "dev",
    //私包配置修改1
    "repositories": [
        {
            "type": "git",
            "url": "http://g.x.com/private-package.git",
            "reference":"master"
        }
    ],
    "require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.4.*",
        "laravel/tinker": "~1.0",
        "iaround/lib": "*" // 载入私包 修改2
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~5.7"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-root-package-install": [
            "php -r \"file_exists(‘.env‘) || copy(‘.env.example‘, ‘.env‘);\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postInstall",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "php artisan optimize"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true,
        "secure-http": false //开启http请求 修改3
    }
}

3、最后

composer update 

大功告成

以上是关于composer gitlab 搭建私包的主要内容,如果未能解决你的问题,请参考以下文章

Docker搭建Gitlab代码管理平台

基于docker-compose搭建gitlab

基于docker-compose搭建gitlab

使用 docker-compose 搭建私服 Gitlab

jenkins + gitlab 快速搭建(docker-compose) 时间,时区 同步

搭建Jenkins,Gitlab自动化打包部署项目