|
1 | 1 | #!/bin/bash |
2 | | -# This script builds the Node.js Lambda layer for OpenTelemetry instrumentation |
| 2 | +# Builds the Node.js Lambda layer for local dev. |
3 | 3 | # |
4 | | -# The script expects the dependencies to be cloned in specific locations |
5 | | -# relative to this repository's root directory. |
| 4 | +# Auto-clones the pinned coralogix/opentelemetry-js-contrib fork to .build-cache/ |
| 5 | +# on first run. Keep CX_CONTRIB_SHA in sync with: |
| 6 | +# - scripts/publish-sandbox.sh |
| 7 | +# - .github/workflows/publish-extend-otel-layer.yml |
| 8 | +# - UPSTREAM.md fork-points table |
6 | 9 | # |
7 | | -# If you encounter build issues, try cleaning first: |
8 | | -# git clean -xdf nodejs |
| 10 | +# Override the clone path with OPENTELEMETRY_JS_CONTRIB_PATH (e.g. to point at |
| 11 | +# a local checkout you are hacking on). |
| 12 | +# |
| 13 | +# If you hit build issues, try: git clean -xdf nodejs |
9 | 14 |
|
10 | 15 | set -euo pipefail |
11 | 16 |
|
12 | 17 | ROOT_DIR=$(git rev-parse --show-toplevel) |
13 | 18 |
|
14 | | -# Expected by build_nodejs_layer.sh |
15 | | -if [ -z "${OPENTELEMETRY_JS_CONTRIB_PATH:-}" ]; then |
16 | | - export OPENTELEMETRY_JS_CONTRIB_PATH="$ROOT_DIR/opentelemetry-js-contrib-cx" |
17 | | -fi |
18 | | - |
19 | | -if [ -z "${OPENTELEMETRY_JS_PATH:-}" ]; then |
20 | | - export OPENTELEMETRY_JS_PATH="$ROOT_DIR/opentelemetry-js" |
21 | | -fi |
22 | | - |
| 19 | +CX_CONTRIB_REPO="https://github.com/coralogix/opentelemetry-js-contrib.git" |
| 20 | +CX_CONTRIB_SHA="3a9691a699ddd06c3644eec70bf4b50cc4217ba3" |
| 21 | +CX_CONTRIB_CACHE="${OPENTELEMETRY_JS_CONTRIB_PATH:-$ROOT_DIR/.build-cache/opentelemetry-js-contrib}" |
23 | 22 |
|
24 | | -if [ ! -d "$OPENTELEMETRY_JS_CONTRIB_PATH" ]; then |
25 | | - git clone git@github.com:coralogix/opentelemetry-js-contrib.git "$OPENTELEMETRY_JS_CONTRIB_PATH" -b coralogix-autoinstrumentation |
| 23 | +echo "==> resolving cx-contrib fork at $CX_CONTRIB_SHA" |
| 24 | +if [ ! -d "$CX_CONTRIB_CACHE/.git" ]; then |
| 25 | + mkdir -p "$(dirname "$CX_CONTRIB_CACHE")" |
| 26 | + git clone --filter=blob:none "$CX_CONTRIB_REPO" "$CX_CONTRIB_CACHE" |
26 | 27 | fi |
| 28 | +git -C "$CX_CONTRIB_CACHE" fetch --quiet origin "$CX_CONTRIB_SHA" 2>/dev/null || git -C "$CX_CONTRIB_CACHE" fetch --quiet origin |
| 29 | +git -C "$CX_CONTRIB_CACHE" checkout --quiet "$CX_CONTRIB_SHA" |
27 | 30 |
|
28 | | -if [ ! -d "$OPENTELEMETRY_JS_PATH" ]; then |
29 | | - git clone git@github.com:coralogix/opentelemetry-js.git "$OPENTELEMETRY_JS_PATH" -b coralogix-autoinstrumentation |
30 | | -fi |
| 31 | +export OPENTELEMETRY_JS_CONTRIB_PATH |
| 32 | +OPENTELEMETRY_JS_CONTRIB_PATH="$(cd "$CX_CONTRIB_CACHE" && pwd)" |
31 | 33 |
|
32 | 34 | "$ROOT_DIR/scripts/build_nodejs_layer.sh" |
33 | 35 |
|
34 | | -# Useful for using the layer locally |
| 36 | +# Unzip layer next to the zip for local Lambda-layer poking |
35 | 37 | pushd "$ROOT_DIR/nodejs/packages/layer" >/dev/null |
36 | 38 | rm -rf ./build/layer && unzip -q ./build/layer.zip -d ./build/layer |
37 | 39 | popd >/dev/null |
0 commit comments