cloud-git 扩展s3 存储支持说明
从原理上来说,实现还是比较简单的,主要是关于接口实现的问题,cloud-git 官方已经提供了相关的说明
核心接口说明
开发的扩展继承自GitRepository
- 接口实现说明
class GitRepository {
// Must be overriden
async getRefs(req) {}
async receivePack(req, commands, objects) {}
async getObject(req, hash) {}
// May be overriden
async getHeadRef(req) {}
async authorize(req, res, next) {}
async getReceivePackSuccessMessage(req, commands, objects) {}
async getUploadPackSuccessMessage(req, objects) {}
}
参考格式
async getRefs(req)
[
{ "ref": "{refName}", "sha": "{sha}" },
]
async receivePack(req, commands, objects)
注意destId 空值的问题,官方提供了帮助函数
[
{ "srcId": "{sha}", "destId": "{sha}", "ref": "{refName}" },
]
async getObject(req, sha)
{ "sha": "{sha}", "objectType": "blob|tree|commit|tag", "data": <Buffer> }
集成s3 说明
我们可以直接基于pixl-server-storage s3 存储扩展解决,具体代码可以参考github
核心使用到的就是pixl-server-storage 的hash 操作,以及callback 转promise,没多大的技术难度
- 参考使用
const Express = require("express");
const {S3GitRepository} = require("@dalongrong/cloud-git-s3");
const StandaloneStorage = require('pixl-server-storage/standalone');
const configS3 = {
"engine": "S3",
"AWS": {
"accessKeyId": "minio",
"secretAccessKey": "minio123",
"region": "us-west-1",
"sslEnabled": false,
"s3ForcePathStyle": true,
"endpoint": "localhost:9000",
"correctClockSkew": true,
"maxRetries": 5,
"httpOptions": {
"connectTimeout": 5000,
"timeout": 5000
}
},
"S3": {
"keyPrefix": "",
"fileExtensions": true,
"params": {
"Bucket": "s3app"
},
"cache": {
"enabled": true,
"maxItems": 1000,
"maxBytes": 10485760
}
}
};
const storage = new StandaloneStorage(configS3, function (err) {
if (err) {
console.log("not ok")
}
});
const app = Express();
app.use("/", new S3GitRepository(storage).createExpress(Express));
require("http").createServer(app).listen(3000);
参考资料
https://github.com/fusebit/cloud-git
https://github.com/jhuckaby/pixl-server-storage
https://github.com/rongfengliang/cloud-git-s3
https://www.npmjs.com/package/@dalongrong/cloud-git-s3