golang-monorepo

An example of a golang-based monorepo.
授权协议 MIT License
开发语言 SHELL
所属分类 应用工具、 终端/远程登录
软件类型 开源软件
地区 不详
投 递 者 帅雅逸
操作系统 跨平台
开源组织
适用人群 未知
 软件概览
GitHub Actions CircleCI
Main

Overview

This is an example of a golang-based monorepo. It has the following features:

  • Only build the services or cmds that are modified in a commit;
  • Build all services and/or cmds that are affected by changes in common codes (i.e. pkg);
  • Build all services and/or cmds that are affected by changes in vendor codes.

For now, CircleCI 2.1 and GitHub Actions are supported. But since it uses bash scripts and Makefiles, it should be fairly straightforward to port to TravisCI or AppVeyor, etc.

At the moment, CI is setup with GO111MODULE=on and GOFLAGS=-mod=vendor environment variables enabled during build. See sample dockerfile for more details.

How does it work

During CI builds, build.sh iterates the updated files within the commit range (CIRCLE_COMPARE_URL environment variable in CircleCI) or the modified files within a single commit (when the value is not a valid range), excluding hidden files, pkg, and vendor folders. It will then try to walk up the directory path until it can find a Makefile (excluding root Makefile). Once found, the root Makefile will include that Makefile and call the custom rule as target, thus, initiating the build.

When the changes belong to either pkg or vendor, the script will then try to determine the services (and cmds) that have dependencies using the go list command. All dependent services will then be built using the same process described above.

You can override the COMMIT_RANGE environment variable for your own CI. If this is set, build.sh will use its value. You also want to set CIRCLE_SHA1 to your commit SHA (CIRCLE_SHA1 is CircleCI-specific). Example for GitHub Actions is here. Something like:

# If your commit range is correct:
COMMIT_RANGE: aaaaa..bbbbb
CIRCLE_SHA1: aaaaa

# If no valid commit range:
COMMIT_RANGE: <your_commit_sha>
CIRCLE_SHA1: <your_commit_sha>

Directory structure

  • services/ - Basically, long running services.
  • cmd/ - CLI-based tools that are not long running.
  • pkg/ - Shared codes, or libraries common across the repo.
  • vendor/ - Third party codes from different vendors.

Although we have this structure, there is no limitation into where should you put your services/cmds. Any subdirectory structure is fine as long as a Makefile is provided.

How to add a service/cmd

A reference template named samplesvc is provided. Basically, these are the things that you need to do:

  • Create a new directory for your service under services/ or tool under cmd/. You may copy the samplesvc contents to your new directory.
  • Update the dockerfile inside your new service directory. Note that during build, this dockerfile is copied to the root directory (to be able to access pkg and vendor directories).
  • Update the Makefile with your own values. You need to at least update the MODULE variable with your service name. The only required rule is the custom part so you may need to change that as well (i.e. name of the dockerfile used in docker build).
  • [Optional] Update the deploy.sh script for your deployment needs.

Need help

PR's are welcome!

  • Support for GitHub Actions
  • Support for GitLab
  • Run go test ... for pkg/ when Makefile is root
  • Make it work without the vendor folder as well

Misc

https://tech.mobingi.com/2018/09/25/ouchan-monorepo.html

 相关资料
  • golang golang 格式的 chaincode。

  • gosql 是一款 golang style 语法的 golang orm 库。 优雅的语法,支持批量插入; 轻松嵌套条件,处理各种复杂的查询 sql,诸如:and 和 or 组合; 全语法支持:for update 锁、is null、exists 子查询等基本上所有 sql 语法 特xing Golang-style SQL builder go语言风格sql生成 Unlimited nest

  • html2article — 基于文本密度的html2article实现[golang] Install go get -u -v github.com/sundy-li/html2article Performance avg 3.2ms per article, accuracy >= 98% (对比其他开源实现,可能是目前最快的html2article实现,我们测试的数据集约3kw来自于微信

  • Libretto 是一个 Golang 库,可在任何云和虚拟机托管平台(如 AWS,Azure,OpenStack,vSphere 或VirtualBox)上创建虚拟机(VM)。 可在下列平台部署 AWS Azure DigitalOcean Exoscale Google Cloud Platform Openstack (Mirantis) Virtualbox >= 4.3.30 VMwar

  • Gos 自称为 “Armed Golang(加强版的 Go)”,定位是原生 go 命令的一个“加强版”解决方案。 据官方介绍可以使用 gos 代替 go: go get => gos getgo build => gos buildgo run => gos rungo ... => gos ... 因为 gos 兼容所有的 go 命令,并且还额外增加了搭载智能 GOPROXY 的 go mod/

  • Go 语言实现 API 网关基础功能。(主要看重 Go 并发处理能力) 获取代码 go get -u github.com/wisrc/gateway 日志框架使用了 golang.org/x/sys 中的包,如果出现下载这个包超时的情况,请到 github.com/golang/sys 中下载,然后将 github.com/golang/sys 重命名为 golang.org/x/sys 配置介

  • 一个golang并行编程库,用于业务聚合或重构。可以用最少的代码,将串行的函数调用并行化,无需改变函数的声明。 实现原理和demo参考github地址:https://github.com/buptmiao/parallel 使用: 以下有三种方法:testjoba,testjobb,testjobc执行并行: import (    "github.com/buptmiao/parallel")

  • Leaps 是一个用go语言实现的、用来协作开发的命令行工具。使用它可以通过http来编辑你本地的文件。