使用 satis 搭建 私人 composer 包仓库
前言
在工作当中,我们所开发的很多东西是不方便开源的,所以可使用内部git服务器,配合composer/satis 项目搭建私有composer处理内部依赖,优化代码结构,统一依赖。
步骤一、提交项目源码到 gitee 或 github 上面
步骤一,我就不过多叙述了。
我这里使用的是gitee,创建了一个仓库,获取到https://gitee.com/xxxxi/kw-system-lib.git 这个后面需要用到。
步骤二、使用composer建立satis项目
1.执行下面代码
$ mkdir /www/wwwroot/private-repository
$ cd /www/wwwroot/private-repository
$ composer create-project composer/satis satis --stability=dev --keep-vcs
$ cd satis
$ composer install
2.创建 satis.json 文件内容如下:
vim satis.json
内容如:
{
"name": "my repository", #名称
"homepage": "http://localhost:8083/", # 表示satis访问地址(nginx服务器配置,后续用到)
"repositories": [
{
"type": "vcs",
"url": "https://gitee.com/xxxxi/kw-system-lib.git" #写入我们要导入项目的gitee仓库地址
}
],
"require": # require:具体的包的名称,后面的版本号实际就是git里的tag
{
"kw/system-lib": "^1.0"
},
"config": {
"secure-http": false #表示支持http访问
}
"require-all": true, #获取全部
"archive":
{
"directory": "dist",
"format": "tar",
"prefix-url": "http://101.35.15.211:8083/",
"skip-dev": true
}
archive 参数说明:
下载远端项目到本地存储,会自动生成tar包保存在dist里,可以加快后续composer的速度
directory: 表示生成的压缩包存放的目录,会在我们build时的目录中
format: 压缩包格式, zip(默认) tar
prefix-url: 下载链接的前缀的Url,默认会从homepage中取
skip-dev: 默认为假,是否跳过开发分支
absolute-directory 可选的,存放dist文件的本地绝对目录,而不是output-dir/directory
whitelist 可选的,如果设置为一些包名的列表,则只会下载这些包的文件
blacklist 可选的,如果设置为一些包名的列表,则不会下载这些包的文件
checksum 可选的,默认是true,设置为false时,satis不会检测dist文件的sha1 checksum值
3.生成 satis 仓库目录
#通过构建satis.json 生成statis仓库到 public/
php bin/satis build satis.json public/
步骤三、配置nginx文件,建立web站点
配置一个php运行环境,运行时目录指向到web目录下。
使用 apache/nginx 或 php -S 命令创建 WEB 站点,文档根目录指向 satis/public 目录。
我这里使用的是nginx
server
{
listen 8083;
server_name www.private-repository.kw;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/private-repository/satis/pubilc;
}
然后访问一下 http://localhost:8083/ ,看这个这个页面就OK了
步骤四、使用自己配置的私人仓
在你自己的项目中的 composer.json 中 编辑:
"require": {
"kw/system-lib": "^1.0"
},
"config": {
"secure-http": false
},
"repositories": [{
"type": "composer",
"url": "http://localhost:8083"
}]
repositories是为了告诉composer 刚刚我们设置的私有镜像地址,它会优先从我们这里去获取对应的包
secure-http设置为false是因为satis默认为https
执行composer install 或者 composer update
在对应项目下面就会生成vendor目录,如:我的就是\vendor\kw\system-lib,这样就代表使用自己的私人仓成功。
# 删除 satis 仓库目录
php bin/satis purge satis.json public/