build: support dd-trace package override and filter publish layer check#777
Open
joeyzhao2018 wants to merge 2 commits intomainfrom
Open
build: support dd-trace package override and filter publish layer check#777joeyzhao2018 wants to merge 2 commits intomainfrom
joeyzhao2018 wants to merge 2 commits intomainfrom
Conversation
- build_layers.sh: add DD_TRACE_PACKAGE, DD_TRACE_COMMIT, and DD_TRACE_COMMIT_BRANCH env vars to override the dd-trace dependency used inside the layer (useful for git-bisect / branch testing). The resolved spec is forwarded to docker as a build-arg. - Dockerfile: accept an optional `dd_trace_package` build-arg. When set, rewrite package.json's dd-trace dep to the override spec before yarn install. The rewrite is gated on the build-arg being non-empty, so default builds are unchanged. - publish_layers.sh: only require layer zips for the layers in LAYERS, rather than unconditionally requiring all 4 entries in LAYER_PATHS. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two improvements to the layer build/publish flow, mirroring the recent changes to
datadog-lambda-python:scripts/build_layers.sh+Dockerfile— add the ability to build a layer with an arbitrarydd-tracepackage, useful for git-bisect or testing a feature branch ofdd-trace-jsend-to-end inside the layer. Three new (mutually exclusive, opt-in) env vars on the build script:DD_TRACE_PACKAGE— exact package spec passed straight to npm/yarn (e.g.npm:dd-trace@5.0.0,file:./local-tarball.tgz).DD_TRACE_COMMIT— dd-trace-js commit SHA, expanded togit+https://github.com/DataDog/dd-trace-js.git#<sha>.DD_TRACE_COMMIT_BRANCH— dd-trace-js branch name, expanded the same way.The resolved spec is forwarded to docker via
--build-arg dd_trace_package=.... When none of those env vars are set, the build-arg is empty and the Dockerfile takes its existing path.scripts/publish_layers.sh— pre-flight check now only requires the zips for layers inLAYERS, not all four entries inLAYER_PATHS. WhenLAYERSis unset, it still resolves to all available layers, so default invocations behave identically.About the Dockerfile change (it's a bit ugly — here's why)
The new step in the Dockerfile is a one-line
node -e '...'that rewritespackage.jsonto swap thedd-traceentry over to the override spec, gated on the new build-arg:It's not pretty, but the alternatives were worse:
yarn add dd-trace@<spec>instead of editingpackage.json:yarn addtriggers a resolve+install during the rewrite step, thenyarn installruns again on the next layer — duplicate work and a worse-cached image.sed/jq-based JSON edit:sedon JSON is fragile (formatting, quoting, key ordering);jqisn't preinstalled in the node base image.Since
nodeis guaranteed to exist (it's the layer's whole point), an inlinenode -erewrite is the most hermetic option even if the one-liner reads rough. Theifguard means the entire branch is dead code in default builds.The script also handles a quirk of the current
package.json:dd-tracelives indevDependencies(becauseyarnpacks it into the layer build, not at runtime) — so we update it in place if it's already there, and only fall back to writing intodependenciesif it isn't. That preserves the existing dev-vs-prod placement.Backwards compatibility
DD_TRACE_PACKAGE_SPECis empty → build-arg is empty → Dockerfileifis false → identical to today.LAYERSunset on publish → still requires all 4 zips.Dockerfilechange is a no-op unless the new build-arg is non-empty.Test plan
DD_TRACE_COMMIT_BRANCH=<branch> NODE_VERSION=20.19 ./scripts/build_layers.shproduces a layer that uses the override.VERSION=N REGIONS=us-east-2 LAYERS=Datadog-Node20-x ./scripts/publish_layers.shproceeds with only the matching zip built../scripts/build_layers.sh(no override env vars) builds layers byte-identical to current behavior.