Skip to content

Commit b4ea8d2

Browse files
committed
Serve script bundle from cloud proxy image for air gapped installs
Signed-off-by: Dom Del Nano <ddelnano@gmail.com> (cherry picked from commit 77ff5c5)
1 parent 261d7ed commit b4ea8d2

5 files changed

Lines changed: 87 additions & 13 deletions

File tree

k8s/cloud/base/proxy_nginx_config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ data:
267267
try_files "/install.sh" =404;
268268
}
269269
270+
location /bundle-oss.json {
271+
root /bundle;
272+
try_files "/bundle-oss.json" =404;
273+
}
274+
270275
location / {
271276
return 307 https://work.$domain_name$request_uri;
272277
}
@@ -334,6 +339,11 @@ data:
334339
try_files "/install.sh" =404;
335340
}
336341
342+
location /bundle-oss.json {
343+
root /bundle;
344+
try_files "/bundle-oss.json" =404;
345+
}
346+
337347
location / {
338348
gzip_static off;
339349
root /assets;

src/cloud/proxy/BUILD.bazel

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ container_layer(
3333
],
3434
)
3535

36+
container_layer(
37+
name = "script_bundle",
38+
directory = "/bundle",
39+
files = [
40+
"//src/pxl_scripts:script_bundle",
41+
],
42+
)
43+
3644
container_layer(
3745
name = "entrypoint",
3846
directory = "/scripts",
@@ -48,6 +56,7 @@ container_image(
4856
layers = [
4957
":ui_assets",
5058
":installer",
59+
":script_bundle",
5160
":entrypoint",
5261
],
5362
visibility = [

src/pxl_scripts/BUILD.bazel

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,48 @@
1414
#
1515
# SPDX-License-Identifier: Apache-2.0
1616

17+
load("@rules_foreign_cc//foreign_cc:make.bzl", "make")
18+
1719
package(default_visibility = ["//src:__subpackages__"])
1820

1921
filegroup(
2022
name = "preset_queries",
2123
srcs = glob([
2224
"**/*.pxl",
2325
"**/*.json",
24-
]),
26+
"**/*.yaml",
27+
], exclude = ["bundle-oss.json"]),
28+
visibility = ["//src:__subpackages__"],
29+
)
30+
31+
filegroup(
32+
name = "makefile",
33+
srcs = [
34+
"Makefile",
35+
],
2536
visibility = ["//src:__subpackages__"],
2637
)
38+
39+
genrule(
40+
name = "script_bundle",
41+
srcs = [
42+
":makefile",
43+
":preset_queries",
44+
],
45+
outs = ["bundle-oss.json"],
46+
cmd = "export PATH_PREFIX=$$(dirname $(location //src/pxl_scripts:makefile))/; make -C $$PATH_PREFIX bundle-oss.json; cp bundle-oss.json $(@D)/bundle-oss.json",
47+
visibility = ["//src:__subpackages__"],
48+
)
49+
50+
sh_test(
51+
name = "script_bundle_test",
52+
srcs = ["test_script_bundle.sh"],
53+
args = [
54+
"$(location :script_bundle)",
55+
"$(location @com_github_mikefarah_yq_v4//:v4)",
56+
],
57+
data = [
58+
":script_bundle",
59+
"@com_github_mikefarah_yq_v4//:v4",
60+
],
61+
)

src/pxl_scripts/Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,22 @@ EXECUTABLES = px
2222
K := $(foreach exec,$(EXECUTABLES),\
2323
$(if $(shell which $(exec)),some string,$(error "No $(exec) in PATH")))
2424

25+
# Optional path prefix to use for the script_files path. Used by bazel
26+
# to ensure the scripts are in the correct location.
27+
PATH_PREFIX ?= ""
28+
2529
all: bundle-oss.json.gz
2630

2731
bundle-oss.json: $(script_files)
28-
px create-bundle --search_path $(PWD) $(foreach dir,$(dirs),--base $(dir)) -o $(PWD)/bundle-oss.json
32+
33+
@# When run in CI, $HOME may not be set. This ensures that the
34+
@# px create-bundle command can run successfully.
35+
@if [ -z "$$HOME" ]; then \
36+
TMPDIR=$$(mktemp -d); \
37+
export HOME=$$TMPDIR; \
38+
trap "rm -rf $$TMPDIR" EXIT; \
39+
fi; \
40+
px create-bundle --search_path $(PWD) $(foreach dir,$(dirs),--base $(PATH_PREFIX)$(dir)) -o $(PWD)/bundle-oss.json
2941

3042
bundle-oss.json.gz: bundle-oss.json
3143
gzip -c $< > $@
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/bin/bash
12
# Copyright 2018- The Pixie Authors.
23
#
34
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,15 +15,22 @@
1415
#
1516
# SPDX-License-Identifier: Apache-2.0
1617

17-
import px
18+
set -e
1819

19-
df = px.GetAgentStatus()
20-
df.ip_address = px.pluck_array(px.split(df.ip_address, ":"), 0)
21-
df.hostname_by_ip = px.pod_id_to_node_name(px.ip_to_pod_id(df.ip_address))
22-
df.hostname = px.select(df.hostname_by_ip == "", df.hostname, df.hostname_by_ip)
23-
df = df[['asid', 'hostname']]
24-
heap_stats = px._HeapGrowthStacks()
25-
df = df.merge(heap_stats, how='inner', left_on='asid', right_on='asid')
26-
df.asid = df.asid_x
27-
df = df[['asid', 'hostname', 'heap']]
28-
px.display(df)
20+
BUNDLE_FILE="$1"
21+
YQ_BIN="$2"
22+
23+
if [ ! -f "$BUNDLE_FILE" ]; then
24+
echo "Error: Bundle file not found: $BUNDLE_FILE"
25+
exit 1
26+
fi
27+
28+
# Check that scripts object has keys
29+
NUM_SCRIPTS=$("$YQ_BIN" eval '.scripts | keys | length' "$BUNDLE_FILE")
30+
31+
if [ "$NUM_SCRIPTS" -eq 0 ]; then
32+
echo "Error: No scripts found in bundle"
33+
exit 1
34+
fi
35+
36+
echo "Success: Found $NUM_SCRIPTS scripts in bundle"

0 commit comments

Comments
 (0)