|
Optimierung von CI-Builds
Oftmals benötigen die Builds bei CI-Plattformen wie Travis CI, AppVeyor und CircleCI in vielen Fällen recht lange.
Die folgenden Tipps werden regelmßig erweitert und können die benötigte Zeit pro Build drastisch senken.
Caches
AppVeyor
composer
cache:
- %LOCALAPPDATA%\Composer\files
node_modules
cache:
- node_modules
npm
cache:
- C:\Users\appveyor\AppData\Roaming\npm-cache
yarn
cache:
- %LOCALAPPDATA%\Yarn
CircleCI
composer
steps:
- checkout
- restore_cache:
keys:
- composer-v1-{{ checksum "composer.lock" }}
- composer-v1-
- run: composer install -n --prefer-dist
- save_cache:
key: composer-v1-{{ checksum "composer.lock" }}
paths:
- vendor
node_modules
steps:
- checkout
- restore_cache:
name: Restore npm Cache
keys:
- npm-{{ .Branch }}-{{ checksum "package-lock.json" }}
- npm-{{ .Branch }}
- npm-master
- npm-
- run:
name: Install Dependencies
command: npm install
- save_cache:
name: Save npm Cache
key: npm-{{ .Branch }}-{{ checksum "package-lock.json" }}
paths:
- node_modules/
yarn
steps:
- checkout
- restore_cache:
name: Restore Yarn Package Cache
keys:
- yarn-packages-{{ .Branch }}-{{ checksum "yarn.lock" }}
- yarn-packages-{{ .Branch }}
- yarn-packages-master
- yarn-packages-
- run:
name: Install Dependencies
command: yarn install
- save_cache:
name: Save Yarn Package Cache
key: yarn-packages-{{ .Branch }}-{{ checksum "yarn.lock" }}
paths:
- node_modules/
GitLab CI
composer
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- vendor/
node_modules / yarn
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- node_modules/
distributed
[runners.cache]
Type = "s3"
ServerAddress = "s3.amazonaws.com"
AccessKey = "AMAZON_S3_ACCESS_KEY"
SecretKey = "AMAZON_S3_SECRET_KEY"
BucketName = "runners"
BucketLocation = "eu-west-1"
Insecure = false
Path = "path/to/prefix"
Shared = false
local caches
[[runners]]
cache_dir = ""
Docker
[runners.docker]
disable_cache = false
cache_dir = ""
Travis CI
composer
cache:
directories:
- "$HOME/.composer/cache/files"
node_modules
cache:
directories:
- node_modules
npm
cache:
directories:
- "$HOME/.npm"
yarn
cache:
yarn: true
shallow Clones
AppVeyor
clone_depth: 5
GitLab CI
variables:
GIT_DEPTH: "5"
Travis CI
git:
checkout: 5
Build Matrix / Stages
CircleCI
version: 2
jobs:
test:
parallelism: 4
steps:
- run:
- run:
- run:
- run:
GitLab CI
stages:
- build
- test
- deploy
parallel 1-1:
stage: build
script: make build dependencies
parallel 1-2:
stage: build
script: make build artifacts
parallel 2:
stage: test
script: make test
parallel 3:
stage: deploy
script: make deploy
Travis CI
env:
- TEST_SUITE=units
- TEST_SUITE=integration
matrix:
include:
- node_js: 8
- node_js: 10
script: "npm run test:$TEST_SUITE"
npm ci
Und natürlich alternativ npm ci
statt npm i
, aber dann kann der Cache für node_modules
nicht mehr genutzt werden.