[8.16] [ci] Reuse .yarn-local-mirror (#198613) (#198873)

# Backport

This will backport the following commits from `main` to `8.16`:
- [[ci] Reuse .yarn-local-mirror
(#198613)](https://github.com/elastic/kibana/pull/198613)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"Jon","email":"jon@elastic.co"},"sourceCommit":{"committedDate":"2024-11-04T22:24:15Z","message":"[ci]
Reuse .yarn-local-mirror (#198613)\n\nCurrently CI is configuring a yarn
local mirror that is ignored due to\r\nthe repository `.yarnrc` taking
precedence.\r\n\r\nInstead of configuring this setting, this moves the
cached mirror over\r\nto the Kibana directory in line with the
repository's
configuration.","sha":"586b24f3a80cd1d9edb8775f51e1b86849d2c1f2","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Operations","release_note:skip","v9.0.0","backport:prev-major"],"title":"[ci]
Reuse
.yarn-local-mirror","number":198613,"url":"https://github.com/elastic/kibana/pull/198613","mergeCommit":{"message":"[ci]
Reuse .yarn-local-mirror (#198613)\n\nCurrently CI is configuring a yarn
local mirror that is ignored due to\r\nthe repository `.yarnrc` taking
precedence.\r\n\r\nInstead of configuring this setting, this moves the
cached mirror over\r\nto the Kibana directory in line with the
repository's
configuration.","sha":"586b24f3a80cd1d9edb8775f51e1b86849d2c1f2"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/198613","number":198613,"mergeCommit":{"message":"[ci]
Reuse .yarn-local-mirror (#198613)\n\nCurrently CI is configuring a yarn
local mirror that is ignored due to\r\nthe repository `.yarnrc` taking
precedence.\r\n\r\nInstead of configuring this setting, this moves the
cached mirror over\r\nto the Kibana directory in line with the
repository's
configuration.","sha":"586b24f3a80cd1d9edb8775f51e1b86849d2c1f2"}}]}]
BACKPORT-->

Co-authored-by: Jon <jon@elastic.co>
This commit is contained in:
Kibana Machine 2024-11-05 11:24:42 +11:00 committed by GitHub
parent c450a850ec
commit 6571842556
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 7 deletions

View file

@ -12,12 +12,18 @@ if [[ "${BOOTSTRAP_ALWAYS_FORCE_INSTALL:-}" ]]; then
BOOTSTRAP_PARAMS+=(--force-install)
fi
# Use the node_modules that is baked into the agent image, if it exists, as a cache
# Use the packages that are baked into the agent image, if they exist, as a cache
# But only for agents not mounting the workspace on a local ssd or in memory
# It actually ends up being slower to move all of the tiny files between the disks vs extracting archives from the yarn cache
if [[ -d ~/.kibana/node_modules && "$(pwd)" != *"/local-ssd/"* && "$(pwd)" != "/dev/shm"* ]]; then
echo "Using ~/.kibana/node_modules as a starting point"
mv ~/.kibana/node_modules ./
if [[ "$(pwd)" != *"/local-ssd/"* && "$(pwd)" != "/dev/shm"* ]]; then
if [[ -d ~/.kibana/node_modules ]]; then
echo "Using ~/.kibana/node_modules as a starting point"
mv ~/.kibana/node_modules ./
fi
if [[ -d ~/.kibana/.yarn-local-mirror ]]; then
echo "Using ~/.kibana/.yarn-local-mirror as a starting point"
mv ~/.kibana/.yarn-local-mirror ./
fi
fi
if ! yarn kbn bootstrap "${BOOTSTRAP_PARAMS[@]}"; then

View file

@ -10,7 +10,6 @@ NODE_VERSION="$(cat "$KIBANA_DIR/.node-version")"
export NODE_VERSION
export NODE_DIR="$CACHE_DIR/node/$NODE_VERSION"
export NODE_BIN_DIR="$NODE_DIR/bin"
export YARN_OFFLINE_CACHE="$CACHE_DIR/yarn-offline-cache"
## Install node for whatever the current os/arch are
hostArch="$(command uname -m)"
@ -77,8 +76,6 @@ if [[ ! $(which yarn) || $(yarn --version) != "$YARN_VERSION" ]]; then
npm_install_global yarn "^$YARN_VERSION"
fi
yarn config set yarn-offline-mirror "$YARN_OFFLINE_CACHE"
YARN_GLOBAL_BIN=$(yarn global bin)
export YARN_GLOBAL_BIN
export PATH="$PATH:$YARN_GLOBAL_BIN"