Template repository for a Go monorepo, complete with CI and automatic docker builds

CircleCI

Utility Warehouse template Go monorepo

This repo is an abbreviated copy of one used by one of the teams inside Utility Warehouse. It's been built for tight CI integration and developer productivity.

Making it your own

If you're creating a new repo from this template, you'll want to do a search-replace on github.com/uw-labs/go-mono and uwlabs (replacing yourorg, yourrepo and yourscm with your own):

$ find . -type d -name "uwlabs" -exec sh -c 'mv {} $(dirname {})/yourorg' \;
$ find . -type f -exec sed -i 's;github.com/uw-labs/go-mono;yourscm.com/yourorg/yourrepo;g' {} +
$ find . -type f -exec sed -i 's;uwlabs;yourorg;g' {} +

Configure DOCKER_USER and DOCKER_PASSWORD in your CircleCI settings for release builds to work. The registry path to use is configured in the release CI job.

CI Setup

The CI setup uses Circle CI, partly because of the powerful caching features, and partly because Circle CI machine users have access to a local docker socket, which allows us to run integration tests using go test which work both locally and in CI. The CI jobs rely on Go build and test caching to be efficient even with a larger number of services. The same CI setup is used to efficiently test and publish over 130 applications within UW.

Linters

Automatic publishing

The release CI job automatically figures out what needs building and publishes a docker image to the configured registry. It requires the setting of DOCKER_USER and DOCKER_PASSWORD in the Circle CI configuration environment variables.

The Dockerfile used to build the images is here. It can be edited as necessary, just make sure to run make generate after changing it.

For an example of this, the user-api is published automatically to the local GitHub docker registry whenever it requires rebuilding.

Repository Layout

  • cmd - Utilities and service applications.
  • pkg - Shared packages.
  • proto - Protobuf definitions & generated code.
  • vendor - Vendored third-party dependencies.

Makefile

A top level Makefile exists to help you perform common actions within the monorepo. Recipes include:

  • format - Formats your .go source code
  • install-generators - Installs all necessary generators for the generate step
  • generate - Runs all generators required within the monorepo
  • lint-imports - Runs the import linter.

How do I add a new application?

  1. Create a new folder in cmd for your service E.g. cmd/my-new-service.
  2. Create a main.go
  3. If you want to automatically build a docker container, add a deploy.yml file.

Adding protofiles

Add your own protofiles under proto/uwlabs/. Follow the folder structure laid out in the buf documentation.

The calculate-releases script

calculate-releases is the magic that calculates exactly what applications need to be rebuilt based on file changes to the application directly, or any of its transative dependencies. It is called in CI on every branch push, to calculate which applications to build docker images for.

It relies on go list -json ./... for dependency information.

The deploy script

deploy is responsible for building and publishing a docker image to the specified registry. It's usually run on the output of the calculate-releases script. It defines a custom format for build configuration and metadata. This can be extended to include things such as kubernetes deployment targets, extra application metadata and more. It is currently run automatically against every branch push in CI.

The deploy.yml file

Use a deploy.yml together with any main packages that you want to deploy to configure automatic docker container building and publishing. The deploy.yml file allows a single configuration parameter:

  • name

    Used to configure the name of the docker image pushed to the registry.

Why a vendor directory?

When evaluating solutions to two problems, the vendor directory became the primary candidate:

  1. How do we keep CI builds as fast as possible?

    We first implemented this using module caching, where the first job would download all the modules and cache them for future jobs. It meant a lot of extra boilerplate in the CircleCI configuration files, and it never worked well for the Docker builds. Vendoring means we have all the source code available at all time, and completely removes the need for caching. This sped up builds by roughly 50% in testing.

  2. How do we ensure we only release applications that have changed when we perform dependency updates?

    This could be done with some custom tooling that can discover file changes between module updates, but this is nontrivial, and we already had a solution that worked with the vendor directory.

The CI pipeline will fail on your pull request if you add a new dependency that is not within the /vendor directory. If you've added a new dependency, make sure you run go mod tidy and go mod vendor to ensure your dependencies are up-to-date and vendored.

Owner
UW Labs
Open source software from UW
UW Labs
Similar Resources

An example microservice demo using kubernetes concepts like deployment, services, persistent volume and claims, secrets and helm chart

Docker vs Kubernetes Docker Kubernetes container tech, isolated env for apps infra management, multiple containers automated builds and deploy apps -

Dec 13, 2021

Rpcx-framework - An RPC microservices framework based on rpcx, simple and easy to use, ultra fast and efficient, powerful, service discovery, service governance, service layering, version control, routing label registration.

RPCX Framework An RPC microservices framework based on rpcx. Features: simple and easy to use, ultra fast and efficient, powerful, service discovery,

Jan 5, 2022

GSOC-Mentorship - Scripts and Templates used to parse jsons and send mails to students of GSOC Mentorship

GSOC Mentorship The Club of Programmers, IIT(BHU) organizes it's flagship GSoC M

Sep 18, 2022

Connect, secure, control, and observe services.

Istio An open platform to connect, manage, and secure microservices. For in-depth information about how to use Istio, visit istio.io To ask questions

Jan 9, 2023

Design-based APIs and microservices in Go

Design-based APIs and microservices in Go

Goa is a framework for building micro-services and APIs in Go using a unique design-first approach. Overview Goa takes a different approach to buildin

Jan 5, 2023

Netflix's Hystrix latency and fault tolerance library, for Go

hystrix-go Hystrix is a great project from Netflix. Hystrix is a latency and fault tolerance library designed to isolate points of access to remote sy

Dec 28, 2022

Cloud-native and easy-to-use application management platform | 云原生且易用的应用管理平台

Cloud-native and easy-to-use application management platform | 云原生且易用的应用管理平台

Website • Documentation What is NEW! August 24, 2020 ,Rainbond 5.2 Stable version is officially released View Release Rainbond Introduction Cloud nati

Dec 29, 2022

Generates Golang client and server based on OpenAPI2 (swagger) definitions

Generates Golang client and server based on OpenAPI2 (swagger) definitions

ExperienceOne Golang APIKit ExperienceOne Golang APIKit Overview Requirements Installation Usage Generate standard project structure Define the API wi

Aug 9, 2022

Concourse is a container-based continuous thing-doer written in Go and Elm.

Concourse is a container-based continuous thing-doer written in Go and Elm.

Concourse: the continuous thing-doer. Concourse is an automation system written in Go. It is most commonly used for CI/CD, and is built to scale to an

Dec 30, 2022
Elastic Stack Docker + Sample Go AppElastic Stack Docker + Sample Go App
Elastic Stack Docker + Sample Go AppElastic Stack Docker + Sample Go App

?? Elastic Stack Docker + Sample Go App Test Elastic Stack which includes Elasticsearch, Kibana, Filebeat and Metricbeat. It comes with a very simple

Jan 14, 2022
Automatic Service Mesh and RPC generation for Go micro services, it's a humble alternative to gRPC with Istio.
Automatic Service Mesh and RPC generation for Go micro services, it's a humble alternative to gRPC with Istio.

Mesh RPC MeshRPC provides automatic Service Mesh and RPC generation for Go micro services, it's a humble alternative to gRPC with Istio. In a nutshell

Aug 22, 2022
CRUD API server of Clean Architecture with Go(Echo), Gorm, MySQL, Docker and Swagger
CRUD API server of Clean Architecture with Go(Echo), Gorm, MySQL, Docker and Swagger

CRUD API Server of Clean Architecture Go(echo) gorm mysql docker swagger build docker-compose up -d --build API Postman and Fiddler is recommended to

May 30, 2021
Repository that mantains utilitary libs for Golang projects.

Go Kit Go Kit is a repository of utilitary packages written in Go, designed to improve development experience of Trivela's squads. Internal structure

Sep 6, 2022
This is a template service for development first with go monolithic architecture

This is a template service for development first with go monolithic architecture

Nov 27, 2022
Go-rifa-microservice - Clean Architecture template for Golang services
Go-rifa-microservice - Clean Architecture template for Golang services

Test CI Go Clean template Clean Architecture template for Golang services Overvi

Sep 22, 2022
Microservices using Go, RabbitMQ, Docker, WebSocket, PostgreSQL, React
Microservices using Go, RabbitMQ, Docker, WebSocket, PostgreSQL, React

Microservices A basic example of microservice architecture which demonstrates communication between a few loosely coupled services. Written in Go Uses

Jan 1, 2023
A microservice gateway developed based on golang.With a variety of plug-ins which can be expanded by itself, plug and play. what's more,it can quickly help enterprises manage API services and improve the stability and security of API services.
A microservice gateway developed based on golang.With a variety of plug-ins which can be expanded by itself, plug and play. what's more,it can quickly help enterprises manage API services and improve the stability and security of API services.

Goku API gateway is a microservice gateway developed based on golang. It can achieve the purposes of high-performance HTTP API forwarding, multi tenant management, API access control, etc. it has a powerful custom plug-in system, which can be expanded by itself, and can quickly help enterprises manage API services and improve the stability and security of API services.

Dec 29, 2022
Microservice Boilerplate for Golang with gRPC and RESTful API. Multiple database and client supported
Microservice Boilerplate for Golang with gRPC and RESTful API. Multiple database and client supported

Go Microservice Starter A boilerplate for flexible Go microservice. Table of contents Features Installation Todo List Folder Structures Features: Mult

Jul 28, 2022
Fast, intuitive, and powerful configuration-driven engine for faster and easier REST development
Fast, intuitive, and powerful configuration-driven engine for faster and easier REST development

aicra is a lightweight and idiomatic configuration-driven engine for building REST services. It's especially good at helping you write large APIs that remain maintainable as your project grows.

Oct 19, 2022