229 用 composer 管理私有包

最近在搭建api脚手架,需要在项目中使用私有的包,只想在公司中重用,但不是真的想开源,不能放在 github 或者 packagist上面。
需要引入的包的 git 地址为 testRepo
原文地址 :https://getcomposer.org/doc/articles/handling-private-packages-with-satis.md

修改 testRepo

testRepo 项目是最终会被引入到 vendor 目录下的包,这个包暂时只需要一个文件 composer.json

{
    "name":"fancive/test",
    "homepage": "https://codebowl.juhe.cn/fancive/test",
    "description":"just anothor test",
    "authors":[
        {
            "name":"fancivez",
            "email":"wujc@think-land.com"
        }
    ]
}

编辑完成后 add , commit , push 三板斧就不用管他了

创建测试项目

  • 我在 /home/fancivez/ 下新建了一个空项目 MyRepository
  • 在 MyRepository 中新建了一个 composer.json 文件
{
    "name": "My Repository",
    "require": {
        "fancive/test": "dev-master"
    },
    "repositories": [
        {
            "type": "git",
            "url": "https://codebowl.juhe.cn/fancive/test.git"
        }
    ]
}

执行 composer update
可能需要输入 git 用户名和密码

Loading composer repositories with package information
Updating dependencies (including require-dev)        
  - Installing fancive/test (dev-master aef1dad)
    Cloning aef1dad0f91361c05eb1541d17cdc1917fe6e76b
Writing lock file
Generating autoload files

可以在 vendor 下看到 fancive/test 包被成功添加

通过 ssh 认证托管

继续修改 composer.json

  • 添加 options ,认证类型为 ssh2
  • username 为 git 用户名
  • 加上 pubkey_file 和 privkey_file 路径
{
    "name": "My Repository",
    "require": {
        "fancive/test": "dev-master"
    },
    "repositories": [
        {
            "type": "git",
            "url": "git@codebowl.juhe.cn:fancive/test.git",
            "options": {
                "ssh2": {
                    "username": "wujc@think-land.com",
                    "pubkey_file": "/home/.ssh/id_rsa.pub",
                    "privkey_file": "/home/.ssh/id_rsa"
                }
            }
        }
    ]
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值