引自百科
服务器自己使用开源git服务器搭建
gitlab-ce: 内存至少4G,否则特别卡顿, CI/CD使用gitlab-runnergogs: Gogs 是一款极易搭建的自助 Git 服务,其目标是打造一个最简单、最快速和最轻松的方式搭建自助 Git 服务。使用 Go 语言开发使得 Gogs 能够通过独立的二进制分发,并且支持 Go 语言支持的 所有平台,包括 Linux、Mac OS X、Windows 以及 ARM 平台gitea: Gitea的首要目标是创建一个极易安装,运行非常快速,安装和使用体验良好的自建 Git 服务,该服务采用golang编写,适合在树莓派等低内存设备上运行,支持跨平台例如:x86,arm,arm64v8等多个平台,CI/CD使用act runner。查看帮助文档: https://docs.gitea.com/ (推荐使用,目前笔者树莓派4B 8G版正在运行该软件)其他: Gitosis, Gitolite,Gidder这些笔者没测试过,生产环境也没用过,暂时不做介绍公共代码托管服务器

CI/CD:
jenkins: 企业级推荐,支持多种插件,实现自动化构建、测试与部署,功能完善、如果遇到问题百度、谷歌搜索基本可以解决,同时也吃内存,毕竟是用java写的, 目前笔者在树莓派4B上正在运行gitlab-runner: gitlab推荐的, 笔者很久以前的一个公司一直在使用github actions: github.com自带的action,需要了解使用语法CircleCI:它主要以容器化技术为基础,提供快捷且高效的构建环境。CircleCI的特点是很容易与GitHub、Bitbucket等代码托管平台集成, 并且提供灵活的配置选项以适应各种工作流Travis CI: (笔者没用过) 是一个广为人知的CI服务,特别是对于开源项目。它能够与GitHub紧密集成,当代码推送到GitHub后,Travis CI会自动运行预设的构建和测试任务其他:Bamboo(Atlassian 出品的CI/CD工具),TeamCity(由 JetBrAIns 开发)环境搭建介绍一下笔者树莓派上运行的服务
gitea:代码仓库托管jenkins:自动化编译与部署docker-compose: docker编排工具docker-compose-restful: 用于接受jenkins编译后的触发项目部署,在树莓派上运行的一个服务(内部主要是对docker-compose功能的cmd封装),这样可以在切换不同的CI/CD后,减少各个平台对后置事件的学习和测试docker运行gitea创建网络docker network create traefikdocker network create spider-cluster
docker-compose.yaml, 注意端口22容易被占用, 在终端启动 docker-compose up -d
version: '3.9'services: gitea: image: gitea/gitea:1.22.1 container_name: gitea restart: always volumes: - ./data:/data - /etc/localtime:/etc/localtime ports: - "3000:3000" - "322:22" labels: # https://soulteary.com/2020/02/04/gitea-git-server-with-docker-and-traefik-v2.html - "traefik.enable=true" - "traefik.http.routers.giteaweb.middlewares=https-redirect@file" - "traefik.http.routers.giteaweb.entrypoints=http" - "traefik.http.routers.giteaweb.rule=Host(`git.linuxcrypt.cn`)" - "traefik.http.routers.giteassl.middlewares=content-compress@file" - "traefik.http.routers.giteassl.entrypoints=https" - "traefik.http.routers.giteassl.tls=true" - "traefik.http.routers.giteassl.rule=Host(`git.linuxcrypt.cn`)" - "traefik.http.services.giteabackend.loadbalancer.server.scheme=http" - "traefik.http.services.giteabackend.loadbalancer.server.port=3000" - "traefik.tcp.routers.giteassh.rule=HostSNI(``)" - "traefik.tcp.routers.giteassh.tls=true" - "traefik.tcp.routers.giteassh.entrypoints=git" - "traefik.tcp.routers.giteassh.service=gitea" networks: - traefik - spider-clusternetworks: traefik: external: true spider-cluster: external: true
启动容器后,在项目根目录下查看目录结构如下
.├── data│ ├── git 仓库目录│ ├── gitea│ │ ├── conf│ │ │ └── app.ini 核心配置文件,可以配置邮箱、数据库配置,主机域名、白名单等等配置。│ │ └── log│ └── ssh ssh相关配置│ ├── ssh_host_ecdsa_key│ ├── ssh_host_ecdsa_key.pub│ ├── ssh_host_ed25519_key│ ├── ssh_host_ed25519_key.pub│ ├── ssh_host_rsa_key│ └── ssh_host_rsa_key.pub└── docker-compose.yml docker编排文件
注意以上docker-compose.yaml文件中的labels标签,主要用于内网直接连接gitea服务, 不会再外网绕一圈,减少vps服务的流量(因为笔者的树莓派4B通过frp与vps打通的)
打开http://localhost:3000进行安装和配置选择数据库, 根据自己的环境选择使用,笔者使用过MySQL、SQLite3
基础配置,注意挂载的目录/data,以及基础URL用于克隆
配置邮箱,通过第三方开启配置,增加管理员
登陆登陆
个人中心用户中心,个人信息
个人中心,菜单
个人中心,应用,后期对接jenkins需要启用token
管理后台admin后台管理界面
上传代码demo项目
上传后gitea服务端的文件树结构.├── data│ ├── git│ │ ├── lfs│ │ └── repositories│ │ └── clibing│ │ └── demo.git│ │ ├── HEAD│ │ ├── branches│ │ ├── config│ │ ├── description│ │ ├── git-daemon-export-ok│ │ ├── hooks│ │ │ ├── applypatch-msg.sample│ │ │ ├── commit-msg.sample│ │ │ ├── post-receive│ │ │ ├── post-receive.d│ │ │ │ └── gitea│ │ │ ├── post-update.sample│ │ │ ├── pre-applypatch.sample│ │ │ ├── pre-commit.sample│ │ │ ├── pre-merge-commit.sample│ │ │ ├── pre-push.sample│ │ │ ├── pre-rebase.sample│ │ │ ├── pre-receive│ │ │ ├── pre-receive.d│ │ │ │ └── gitea│ │ │ ├── pre-receive.sample│ │ │ ├── prepare-commit-msg.sample│ │ │ ├── proc-receive│ │ │ ├── proc-receive.d│ │ │ │ └── gitea│ │ │ ├── push-to-checkout.sample│ │ │ ├── sendemail-validate.sample│ │ │ ├── update│ │ │ ├── update.d│ │ │ │ └── gitea│ │ │ └── update.sample│ │ ├── info│ │ │ ├── exclude│ │ │ └── refs│ │ ├── logs│ │ │ ├── HEAD│ │ │ └── refs│ │ │ └── heads│ │ │ └── main│ │ ├── objects│ │ │ ├── 8e│ │ │ │ └── 2372258763bcef1dddd67d4ba4aa129d9dfb06│ │ │ ├── e6│ │ │ │ └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391│ │ │ ├── f9│ │ │ │ └── 3e3a1a1525fb5b91020da86e44810c87a2d7bc│ │ │ ├── info│ │ │ │ └── packs│ │ │ └── pack│ │ └── refs│ │ ├── heads│ │ │ └── main│ │ └── tags│ ├── gitea│ │ ├── actions_artifacts│ │ ├── actions_log│ │ ├── attachments│ │ ├── avatars│ │ │ ├── d4fcdeb1937686868f5633d23fc4caad│ │ │ └── tmp│ │ ├── conf│ │ │ └── app.ini│ │ ├── gitea.db│ │ ├── home│ │ ├── indexers│ │ │ └── issues.bleve│ │ │ ├── index_meta.json│ │ │ ├── rupture_meta.json│ │ │ └── store│ │ │ └── root.bolt│ │ ├── jwt│ │ │ └── private.pem│ │ ├── log│ │ ├── packages│ │ ├── queues│ │ │ └── common│ │ │ ├── 000001.log│ │ │ ├── CURRENT│ │ │ ├── LOCK│ │ │ ├── LOG│ │ │ └── MANIFEST-000000│ │ ├── repo-archive│ │ ├── repo-avatars│ │ ├── sessions│ │ │ ├── 0│ │ │ │ └── 4│ │ │ ├── 8│ │ │ │ └── 9│ │ │ │ └── 89ee589f8c7985d9│ │ │ ├── b│ │ │ │ └── 2│ │ │ │ └── b20631975fa94021│ │ │ └── f│ │ │ └── 0│ │ └── tmp│ │ └── package-upload│ └── ssh│ ├── ssh_host_ecdsa_key│ ├── ssh_host_ecdsa_key.pub│ ├── ssh_host_ed25519_key│ ├── ssh_host_ed25519_key.pub│ ├── ssh_host_rsa_key│ └── ssh_host_rsa_key.pub└── docker-compose.yml