• Stars
    star
    364
  • Rank 113,416 (Top 3 %)
  • Language
    Shell
  • License
    MIT License
  • Created over 6 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An example of a golang-based monorepo.
GitHub Actions CircleCI
Main CircleCI

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

More Repositories

1

spindle

A distributed locking library built on top of Cloud Spanner and TrueTime.
Go
54
star
2

windows-camera-class-filter-driver

An example of a camera class (upper) filter driver for Windows.
C
40
star
3

kubepfm

A simple wrapper to kubectl port-forward for multiple pods/deployments/services.
Go
30
star
4

windows-camera-tools

A generic command line tool to control camera properties in Windows. Useful camera related functions (DirectShow, Media Foundation) are included in a dll as well for easy reuse in other projects.
C++
28
star
5

hedge

A distributed systems library for Kubernetes deployments built on top of spindle and Cloud Spanner.
Go
22
star
6

kettle

A simple library to share workloads to a group of workers with one leader at any time. Built on top of Redis.
Go
14
star
7

pretty

A simple JSON log prettifier tool.
Go
12
star
8

lsdy

Tool to query/inspect DynamoDB tables.
Go
8
star
9

dlock

Package for distributed locks.
Go
6
star
10

go-windows-service-etw

A simple Windows service with ETW support using external DLL.
Roff
6
star
11

holly

Simple cron-like service with http interface.
Go
6
star
12

win32-base-service

Skeleton service for Windows.
C
5
star
13

rusttrace

A simple manifest-based ETW wrapper library for Rust in Windows.
C
5
star
14

klf

Simple 'kubectl logs -f' wrapper for multiple pods.
Go
5
star
15

ffmpeg-encode-h264mp4

Encode .NET bitmaps to h264 in mp4 container using ffmpeg.
HTML
5
star
16

athena2csv

Query AWS Athena and download the result as CSV.
Go
5
star
17

rmq

Wrapper for RabbitMQ using streadway/amqp package.
Go
4
star
18

win-restclientserver-console

A simple REST server/client console app for Windows.
C#
3
star
19

flowerinthenight.github.io

Personal website and blog.
SCSS
3
star
20

psscript-exec-http

A simple client/server tool for executing powershell script over http.
C#
2
star
21

win32-etw-manifest

Generic ETW manifest file with a "key: value" format for events.
C
2
star
22

gcp-pubsub-lengthy-consume

An example of lengthy pubsub consumption in golang.
Go
2
star
23

.files

Personal dot files.
Emacs Lisp
1
star
24

homebrew-tap

Personal homebrew tap for custom formulas.
Ruby
1
star
25

base-atlcom-svc

Skeleton ATL COM Windows service.
C
1
star
26

dynamodbstreams-lambda-sns-sqs

Sample code for dynamodbstreams to Lambda to SNS to SQS.
Go
1
star
27

go-gitlab-trigger-build

A tool to do a trigger build in GitLab with status updates.
Go
1
star
28

sqs-lengthy-consume

An example of lengthy SQS consumption in AWS.
Go
1
star
29

win-cpplib

Collection of personally used cpp functions in Windows.
C++
1
star
30

win32-camera-rotate-x-opengl

A Win32 application that provides a 640x480 YUY2 camera preview. The preview can be rotated along the x-axis using the up/down arrow keys.
C++
1
star