使用juicefs 解决基于s3做为git 存储的问题

开发一个自定义的git server 实际上是比较有意思的,而且很多时候也能解决我们好多问题

一些场景

  • 基于git 的配置管理
  • 基于git 的数据同步
  • 基于git 的数据备份

存储的问题

对于git的数据存储,我们有几种方法,本地,共享存储(nas,nfs)
本地的问题很明显,不能共享,使用有点费事,共享存储的好处比较好,实现一个简单的ha,但是问题也很明显共享存储管理比较费事(nfs)
基于s3 是一个不错的选择,但是s3 也有一个问题,就是lock 的问题(原生git 是需要使用文件锁的)

解决方法

我们可以基于s3进行存储,使用juicefs,juicefs 实现了完备的posix 协议,可以很好的解决此问题

参考代码

  • 环境
 
version: "3"
services:
    s3:
      image: minio/minio
      environment:
      - "MINIO_ACCESS_KEY=minio"
      - "MINIO_SECRET_KEY=minio123"
      command: server /data --console-address ":9001"
      ports:
      - "9000:9000"
      - "9001:9001"
  • juicefs 格式化以及挂载

    元数据使用本地,没有使用共享的

juicefs format --storage minio \
    --bucket http://127.0.0.1:9000/jfs2 \
    --access-key minio \
    --secret-key minio123 \
    sqlite3://myjfs.db myjfs
 
juicefs mount sqlite3://myjfs.db mydemoapp
  • git 代码
    基于node-git-server模块
 
const  { Git } = require('node-git-server');
const { join } = require('path');
const port =
  !process.env.PORT || isNaN(process.env.PORT)
    ? 7005
    : parseInt(process.env.PORT);
 
const repos = new Git(join(__dirname, './mydemoapp'), {
  autoCreate: true,
});
 
 
repos.on('push', (push) => {
  console.log(`push ${push.repo}/${push.commit} ( ${push.branch} )`);
  push.accept();
});
 
repos.on('fetch', (fetch) => {
  console.log(`fetch ${fetch.commit}`);
  fetch.accept();
});
 
repos.listen(port,{type:'http'},()=>{
  console.log(`node-git-server running at http://localhost:${port}`);
})

使用

  • 启动服务
docker-compose up -d 
node app.js
  • 创建git 项目
git init 
touch demo.txt
git add .
git commit -m "demo"
git remote add http://localhost:7005/demo.git
git push -u origin master
  • 效果

 

 

 

 

说明

基于juicefs + s3 可以很方便的解决我们基于s3 存储git 应用的问题,而且管理也比较方便,当然也可以直接使用csi 和容器集成起来

参考资料

https://gabrielcsapo.github.io/node-git-server/docs/intro
https://juicefs.com/docs/zh/community/quick_start_guide
https://github.com/gabrielcsapo/node-git-server
https://github.com/rongfengliang/juicefs-gitserver-storage

posted on   荣锋亮  阅读(236)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2021-02-02 cube.js playground暴露的几个不错的功能
2021-02-02 cube.js 生产集成使用的几点说明
2021-02-02 cube.js 上线文 filter 处理的原理
2020-02-02 golang 条件编译
2019-02-02 cget cmake 包管理工具
2019-02-02 buckaroo 试用
2019-02-02 buckaroo 去中心化的c++包管理工具

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示