最近在搭建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"
}
}
}
]
}