• 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

  • 相关阅读:
    mina中的发送延时
    微服务理论之五:微服务架构 vs. SOA架构
    同步
    JAVA中线程同步的方法(7种)汇总
    http连接管理
    MySQL存储引擎比较
    ZAB与Paxos算法的联系与区别
    syslog之二:syslog协议及rsyslog服务全解析
    微服务理论之六:ESB与SOA的关系
    DBCP连接池原理分析及配置用法
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/15387932.html
Copyright © 2020-2023  润新知