Skalieren des CI / CD-Mono-Repositorys

Lerna



Gegeben



  1. Monorepository basierend auf Lerna und Yarn Workspaces .
  2. Ein Dutzend Anwendungen und Dutzende gängiger Pakete für TypeScript, Angular, NodeJS.
  3. Hohe Abdeckung mit Tests verschiedener Streifen (modular, Integration, e2e).
  4. und Atlassian Bamboo CI / CD .


Aufgabe



Beschleunigen Sie vorhandene Pipelines um das Zweifache (bis zu mindestens einer halben Stunde). Unterwegs erhöht sich die Stabilität auf 90%.



Mit Blick auf die Zukunft werde ich sagen, dass die erforderlichen Indikatoren erreicht wurden.



Es war





Für inkrementelle Build- Herna-Filteroptionen :



lerna run build:packages --since --include-merged-tags --include-dependencies


lerna publish (JFrog):



# Master
lerna publish patch --yes
# Feature
lerna publish prepatch --yes --no-push --preid "${PREID}"


pipeline, elastic .



. (~1).



, (), JFrog , , pipeline (~70%).





.



— production image .



.

— production image ( , )

— .



, .



node_modules ~1.5Gb ( ). image, AWS ECR, .





"" ("") , , workspaces package.json CI.



#!/usr/bin/env node

const { spawnSync } = require('child_process');
const { existsSync, promises: { readFile, writeFile } } = require('fs');
const { join, dirname, relative, normalize } = require('path');

const PACK_JSON_PATH = './package.json';

(async (apps) => {
    const packJSON = JSON.parse((await readFile(PACK_JSON_PATH)).toString());

    spawnSync('yarn', ['global', 'add', 'lerna'], { shell: true });

    const locations = listPackages(apps);

    const [someLocation] = locations;
    const basePath = findBasePath(someLocation);

    // All paths should be relative to monorepo root
    const workspaces = locations.map((loc) => normalize(relative(basePath, loc)));

    packJSON.workspaces.packages = workspaces;

    const packJSONStr = JSON.stringify(packJSON, undefined, 2);
    await writeFile(PACK_JSON_PATH, `${packJSONStr}\n`);
})(
    process.argv.slice(2),
);

function listPackages(apps = []) {
    const filterOptions = apps.flatMap((app) => ['--scope', app]);
    const { stdout } = spawnSync(
        'lerna',
        ['ls', '-pa', '--include-dependencies', ...filterOptions],
        { shell: true },
    );
    return String(stdout).split(/[\r\n]+/).filter(Boolean);
}

function findBasePath(packageLocation) {
    return existsSync(join(packageLocation, 'lerna.json'))
        ? packageLocation
        : findBasePath(dirname(packageLocation));
}


"" ( changed) .



node_modules 3 .



Fixed mode



Lerna fixed mode, lerna publish pipeline.



?





lerna changed



lerna changed -a --include-merged-tags


, latest image :



#!/usr/bin/env bash

APP=$1

lerna-focus.js "${APP}"

function nothing_changed() {
    [[ -z "$(lerna changed -a --include-merged-tags || true)" ]]
}

function pull_latest_image() {...}
function push_latest_image() {...}
function tag_latest_with_version() {...}

pull_latest_image

if nothing_changed; then
    tag_latest_with_version
    exit
fi

build-app.sh "${APP}"

if is-master.sh; then
    push_latest_image
fi






?



Nx: Extensible Dev Tools for Monorepos. .



, " " (Angular, Jest, ElasticSearch, Bamboo CI).




All Articles