• This repository has been archived on 17/Aug/2021
  • Stars
    star
    115
  • Rank 304,478 (Top 7 %)
  • Language
    Shell
  • Created almost 7 years ago
  • Updated over 5 years ago

Reviews

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

Repository Details

Scripts helping towards monorepos with GitLab CI.

monorepo.gitlab

GitPitch

Scripts helping towards Monorepo with GitLab CI.

Mostly adapted from workarounds given in gitlab-ce/issues/19232. Hopefully soon to be integrated into GitLab CI!

How to use

Add as a submodule

git submodule add https://github.com/awesome-inc/monorepo.gitlab.git .monorepo.gitlab

and update your .gitlab-ci.yml.

  • Add some variables and a before_script to get the last green commit in Gitlab CI
# needs `curl`, `jq` 1.5
variables:
  GIT_SUBMODULE_STRATEGY: recursive
before_script:
    - .monorepo.gitlab/last_green_commit.sh
  • Build your sub-component foo only when there are diffs in ./foo since the last green commit
build-foo:
  # before
  script: build foo
  # after
  script: .monorepo.gitlab/build_if_changed.sh foo build foo

Tips

DRY Jobs conventions/blueprints

Use YAML anchors to keep your jobs DRY.

Say your using docker-compose to orchestrate & build your services.

Your docker-compose.yml may look something like this

version: '3'
services:
  webapp:
    image: "${DOCKER_REGISTRY}/${REPO}/${PRODUCT}_webapp:${TAG}"
    build:
      context: ./webapp
  ...

And you build and push each service through a script build.sh which goes something like this

#!/bin/bash -ex
component=$1
docker-compose build ${component}
if [ "$CI_BUILD_REF_NAME" -ne "master" ]; then exit; fi
docker-compose push ${component}

This uses docker-compose to build the service specified on the command line as a tagged docker image. If you are on master it pushes the built image right away to the specified registry.

Then, your jobs in .gitlab-ci.yml could look something like this

# Use yml anchors, to keep jobs DRY, cf.: https://docs.gitlab.com/ee/ci/yaml/#anchors
.build_template: &build_definition
  tags:
    - linux
    - docker
  stage: build
  script: .monorepo.gitlab/build_if_changed.sh ${CI_JOB_NAME} ./build.sh ${CI_JOB_NAME}

webapp:
  <<: *build_definition

Docker-in-Docker executor

With awesomeinc/docker.gitlab.monorepo it is easy to use GitLab's docker-in-docker executor. Just add this to your .gitlab-ci.yml

variables:
  # cf.: https://docs.gitlab.com/ee/ci/docker/using_docker_build.html
  DOCKER_HOST: tcp://docker:2375/
  DOCKER_DRIVER: overlay2
services:
  - docker:dind
image:
  name: awesomeinc/docker.gitlab.monorepo:0.1.0
  entrypoint: [""] # force an empty entrypoint, cf.: https://gitlab.com/gitlab-org/gitlab-runner/issues/2692#workaround  

Examples

Some example usages are given in

More Repositories

1

FontAwesome.Sharp

A library for using Font Awesome in WPF & Windows Forms applications
C#
385
star
2

hello.gitlab.monorepo

A simple script helping towards using GitLab CI with Monorepos
30
star
3

OneClickBuild

Simplify your .NET build, run tests, get coverage and automate NuGet packaging
C#
21
star
4

NuPlug

Plugin management powered by NuGet
C#
19
star
5

docker-selks

Docker based Suricata, Elasticsearch, Logstash, Kibana, Scirius aka SELKS.
Dockerfile
10
star
6

docker-elk-cyber

A cybersecurity use case example for the ELK-stack
Python
9
star
7

puppeteer-mocha

Starter kit for automated browser testing of external sites using mocha and puppeteer.
JavaScript
8
star
8

docker-deploy-offline

How to use docker for (almost) continuous delivery to an offline environment
HTML
8
star
9

NWaveform

Audio waveform library for .NET
C#
8
star
10

NZazu

NZazu, a wpf templating engine to create a dynamic form for user input.
C#
4
star
11

docker-diy-ci

Poor man's Continuous Integration platform using Docker.
3
star
12

neo4j-decorator

A decorator for the Neo4j REST Api
JavaScript
3
star
13

docker-deploy

Example for docker image build automation (DIY)
Shell
2
star
14

MimeTypeDetective

inspect file to gather the mime type
C#
2
star
15

NEdifis

Framework for enhanced testing using NUnit and NSubstitute.
C#
2
star
16

NSuggest.WPF

C#
1
star
17

logstash-filter-base64

Simple Base64 filter for logstash
Ruby
1
star
18

AspNetCoreModules

Autofac Module extensions for ASP.NET Core
C#
1
star
19

jruby-yarn

Build image for applications using jruby and yarn/node.js
Ruby
1
star
20

WpfMultiKeyBindings

A WPF implementation for MultiKeyBindings like in Visual Studio.
C#
1
star
21

docker.gitlab.monorepo

Build image for Gitlab CI monorepo docker executor builders
Dockerfile
1
star