Skip to content

Commit cc2b8a2

Browse files
committed
🐑 Significantly reduce cluster startup time
This change implements NativeLink's new worker-init system. This lets us skip building nativelink from source, reducing the startup time for the LRE workflow from ~10-15 minutes to ~1 minute. Fixes #9
1 parent f755350 commit cc2b8a2

File tree

11 files changed

+270
-2349
lines changed

11 files changed

+270
-2349
lines changed

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.0.0-pre.20240422.4
1+
8.0.0-pre.20240607.2

MODULE.bazel

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@ module(
44
compatibility_level = 0,
55
)
66

7-
bazel_dep(name = "bazel_skylib", version = "1.6.1", dev_dependency = True)
7+
bazel_dep(name = "bazel_skylib", version = "1.7.1", dev_dependency = True)
88

99
git_override(
1010
module_name = "rules_ll",
1111
# Note: Keep this commit in sync with the one in flake.nix.
12-
commit = "5ac0546db310da08d44f14271066e0b159611c25",
12+
commit = "a8a26cc78c43896b179caaa263857bd6c88a1da9",
1313
remote = "https://github.com/eomii/rules_ll",
1414
)
1515

16-
rules_ll_dependencies = use_extension(
17-
"@rules_ll//ll:init.bzl",
18-
"rules_ll_dependencies",
19-
)
20-
use_repo(
21-
rules_ll_dependencies,
22-
"local-remote-execution",
16+
bazel_dep(name = "local-remote-execution", version = "0")
17+
archive_override(
18+
module_name = "local-remote-execution",
19+
integrity = "sha256-nWJ6XlV9YT1MSbLur6ygZ7IDaqHInm9mtwUmjRYqLQo=",
20+
strip_prefix = "nativelink-2adda2475eed578d610a66b98f965922656061af/local-remote-execution",
21+
urls = [
22+
"https://github.com/TraceMachina/nativelink/archive/2adda2475eed578d610a66b98f965922656061af.zip",
23+
],
2324
)
2425

2526
# Note: The pipe-through mechanism from rules_ll makes this actually LLVM~19.
@@ -51,4 +52,4 @@ use_repo(
5152
)
5253

5354
# Documentation.
54-
bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True)
55+
bazel_dep(name = "stardoc", version = "0.7.0", dev_dependency = True)

MODULE.bazel.lock

Lines changed: 189 additions & 2278 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,7 @@ setup.
146146

147147
The setup may take a minute to boot up. When running the command the first time
148148
it might take some time to build NativeLink from source inside the cluster
149-
pipelines. Once the command finishes you can invoke the following command to run
150-
a local dashboard:
151-
152-
```bash
153-
kubectl -n kube-system port-forward svc/hubble-ui 8080:80
154-
```
149+
pipelines.
155150

156151
Visit <http://localhost:8080/?namespace=default> to view the cluster topology.
157152

flake.lock

Lines changed: 32 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
};
2727
nativelink = {
2828
# Note: Keep this commit in sync with the LRE commit in `MODULE.bazel`.
29-
url = "github:TraceMachina/nativelink/v0.4.0";
29+
url = "github:TraceMachina/nativelink/2adda2475eed578d610a66b98f965922656061af";
3030

3131
# This repository provides the autogenerated LRE toolchains which are
3232
# dependent on the nixpkgs version in the nativelink repository. To keep
@@ -37,16 +37,16 @@
3737
inputs = {
3838
flake-utils.follows = "flake-utils";
3939
flake-parts.follows = "flake-parts";
40-
pre-commit-hooks.follows = "pre-commit-hooks";
40+
git-hooks.follows = "pre-commit-hooks";
4141
};
4242
};
4343
rules_ll = {
44-
url = "github:eomii/rules_ll/5ac0546db310da08d44f14271066e0b159611c25";
44+
url = "github:eomii/rules_ll/a8a26cc78c43896b179caaa263857bd6c88a1da9";
4545
inputs = {
4646
nixpkgs.follows = "nixpkgs";
4747
flake-utils.follows = "flake-utils";
4848
flake-parts.follows = "flake-parts";
49-
pre-commit-hooks.follows = "pre-commit-hooks";
49+
git-hooks.follows = "pre-commit-hooks";
5050
nativelink.follows = "nativelink";
5151
};
5252
};

local-remote-execution/create-worker.nix

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
{
2-
# pkgs,
3-
nativelink
4-
, buildImage
1+
{ buildImage
52
, self
63
, runCommand
74
, runtimeShell
@@ -89,7 +86,7 @@ buildImage {
8986
mkEnvSymlink
9087
(buildEnv {
9188
name = "${image.imageName}-buildEnv";
92-
paths = [ nativelink coreutils bash ];
89+
paths = [ coreutils bash ];
9390
pathsToLink = [ "/bin" ];
9491
})
9592
];

local-remote-execution/lre-kill-the-mojo.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ writeShellScriptBin "lre-kill-the-mojo" ''
1212
1313
${docker}/bin/docker container stop kind-registry \
1414
| ${findutils}/bin/xargs docker rm
15+
16+
${docker}/bin/docker container stop kind-loadbalancer \
17+
| ${findutils}/bin/xargs docker rm
1518
''

local-remote-execution/lre-mojo-cluster.nix

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
let
1212
# The specific commit to use
13-
nativelinkCommit = "75105df746c626da76f74e412764e6755296a8ab";
13+
nativelinkCommit = "9ba43236cf61737cd9561a1657ee50686b459966";
1414

1515
# Base URL for GitHub access
1616
githubBaseUrl = "github:TraceMachina/nativelink/";
@@ -24,26 +24,27 @@ writeShellScriptBin "lre-mojo-cluster" ''
2424
2525
# Wait for the gateway to be ready
2626
${kubectl}/bin/kubectl wait --for=condition=Programmed --timeout=60s \
27-
gateway eventlistener
27+
gateway el-gateway
2828
2929
# Allow an additional grace period for potential routes to set themselves up.
3030
# TODO(aaronmondal): Find a better solution.
3131
sleep 10
3232
33-
# Retrieve the event listener address
34-
EVENTLISTENER=''$(${kubectl}/bin/kubectl get gtw eventlistener \
35-
-o=jsonpath='{.status.addresses[0].value}')
36-
3733
# POST requests to the event listener
3834
${curl}/bin/curl -v \
3935
-H 'Content-Type: application/json' \
4036
-d '{"flakeOutput": "${githubBaseUrl}${nativelinkCommit}#image"}' \
41-
http://"''${EVENTLISTENER}":8080
37+
localhost:8082/eventlistener
38+
39+
${curl}/bin/curl -v \
40+
-H 'Content-Type: application/json' \
41+
-d '{"flakeOutput": "${githubBaseUrl}${nativelinkCommit}#nativelink-worker-init"}' \
42+
localhost:8082/eventlistener
4243
4344
${curl}/bin/curl -v \
4445
-H 'Content-Type: application/json' \
4546
-d '{"flakeOutput": "./src_root#nativelink-worker-lre-mojo"}' \
46-
http://"''${EVENTLISTENER}":8080
47+
localhost:8082/eventlistener
4748
4849
# Wait for PipelineRuns to start
4950
until ${kubectl}/bin/kubectl get pipelinerun \
@@ -75,6 +76,7 @@ writeShellScriptBin "lre-mojo-cluster" ''
7576
# Use kustomize to set images
7677
cd "''${KUSTOMIZE_DIR}" && ${kustomize}/bin/kustomize edit set image \
7778
nativelink=localhost:5001/nativelink:"''$(${nix}/bin/nix eval ${githubBaseUrl}${nativelinkCommit}#image.imageTag --raw)" \
79+
nativelink-worker-init=localhost:5001/nativelink-worker-init:"''$(${nix}/bin/nix eval ${githubBaseUrl}${nativelinkCommit}#nativelink-worker-init.imageTag --raw)" \
7880
nativelink-worker-lre-mojo=localhost:5001/nativelink-worker-lre-mojo:"''$(${nix}/bin/nix eval .#nativelink-worker-lre-mojo.imageTag --raw)"
7981
8082
# Apply the configuration

local-remote-execution/worker-lre-mojo.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ spec:
3232
# yamllint disable rule:line-length
3333
args:
3434
- |
35+
git config --global --add safe.directory "*"
3536
NATIVELINK_WORKER_PLATFORM=docker://lre-mojo:$(nix eval /mnt/src_root#lre-mojo.imageTag --raw) &&
3637
printf '#!/bin/sh\nexport NATIVELINK_WORKER_PLATFORM=%s\nexec "$@"' "$NATIVELINK_WORKER_PLATFORM" > /entrypoint/entrypoint.sh &&
3738
chmod +x /entrypoint/entrypoint.sh
@@ -41,6 +42,13 @@ spec:
4142
mountPath: /entrypoint
4243
- name: mnt
4344
mountPath: /mnt
45+
- name: nativelink-worker-init
46+
# This image will be edited by kustomize.
47+
image: nativelink-worker-init
48+
args: ["/shared/nativelink"]
49+
volumeMounts:
50+
- name: shared
51+
mountPath: /shared
4452
containers:
4553
- name: nativelink-worker-lre-mojo
4654
# This image will be edited by kustomize.
@@ -58,9 +66,13 @@ spec:
5866
subPath: worker.json
5967
- name: entrypoint
6068
mountPath: /entrypoint
69+
- name: shared
70+
mountPath: /shared
6171
command: ["/entrypoint/entrypoint.sh"]
62-
args: ["/bin/nativelink", "/worker.json"]
72+
args: ["/shared/nativelink", "/worker.json"]
6373
volumes:
74+
- name: shared
75+
emptyDir: {}
6476
- name: entrypoint
6577
emptyDir: {}
6678
- name: worker-config

lre-bazel.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
}:
66

77
writeShellScriptBin "lre-bazel" ''
8-
EXECUTOR=$(${kubectl}/bin/kubectl get gtw scheduler -o=jsonpath='{.status.addresses[0].value}')
9-
CACHE=$(${kubectl}/bin/kubectl get gtw cache -o=jsonpath='{.status.addresses[0].value}')
8+
EXECUTOR=$(${kubectl}/bin/kubectl get gtw scheduler-gateway -o=jsonpath='{.status.addresses[0].value}')
9+
CACHE=$(${kubectl}/bin/kubectl get gtw cache-gateway -o=jsonpath='{.status.addresses[0].value}')
1010
1111
if [[
1212
"$1" == "build" ||
@@ -18,8 +18,8 @@ writeShellScriptBin "lre-bazel" ''
1818
${bazel}/bin/bazel $1 \
1919
--remote_timeout=600 \
2020
--remote_instance_name=main \
21-
--remote_cache=grpc://''${CACHE}:50051 \
22-
--remote_executor=grpc://''${EXECUTOR}:50052 \
21+
--remote_cache=grpc://''${CACHE} \
22+
--remote_executor=grpc://''${EXECUTOR} \
2323
--strategy=TestRunner=local \
2424
''${@:2}
2525
else

0 commit comments

Comments
 (0)