Skip to content
This repository has been archived by the owner on Aug 17, 2021. It is now read-only.

A simple script helping towards using GitLab CI with Monorepos

License

Notifications You must be signed in to change notification settings

awesome-inc/hello.gitlab.monorepo

Repository files navigation

hello.gitlab.monorepo

Build status GitPitch

A simple script helping towards using GitLab CI with Monorepo.

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 and `${PRIVATE_TOKEN}, cf.:
# - https://docs.gitlab.com/ee/api/#personal-access-tokens
# - https://docs.gitlab.com/ce/ci/variables/README.html#secret-variables
variables:
  GIT_SUBMODULE_STRATEGY: recursive
  CI_SERVER_URL: https://gitlab.com
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:
  script:
    # before
    - cd foo
    - <build foo>
    # after
    - .monorepo.gitlab/build_if_changed.sh foo <build foo>

Tips

DRY Jobs conventions/blueprints

Use YAML anchors to keep your jobs DRY, i.e.

# 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  

and you are good to go.

About

A simple script helping towards using GitLab CI with Monorepos

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published