Repository navigation
Expand file tree
/
Copy pathbuild-custom.sh
More file actions
executable file
·507 lines (477 loc) · 27.2 KB
/
Copy pathbuild-custom.sh
File metadata and controls
executable file
·507 lines (477 loc) · 27.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
#!/bin/bash
set -e
set -o pipefail
# Copyright 2025 Amazon Web Services, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
if [ $# -ne 2 ]; then
echo 1>&2 "Usage: $0 COMPONENT-NAME COMPONENT-VERSION"
exit 3
fi
COMPONENT_NAME=$1
VERSION=$2
ARCHITECTURE=`uname -m`
# Single source of truth for the tooling/edgemlsdk interpreter version (and,
# outside JP6, for the DDA backend as well). Threaded to the edgemlsdk build
# (`-y`) so the cp311-linked Triton Python-backend stub stays on 3.11 on every
# target. On JP6 the DDA backend interpreter is split off into
# BACKEND_PYTHON_VERSION (derived below, 3.10) because the Jetson AI Lab vLLM
# wheels are cp310-only; JP5/x86 backends keep using this value unchanged.
# Override via the PYTHON_VERSION env var.
PYTHON_VERSION="${PYTHON_VERSION:-3.11}"
export PYTHON_VERSION
# ── Repo-audit guard (spec: python-3-11-security-upgrade) ───────────────────
# This repo has no separate CI pipeline; build-custom.sh IS the build gate, so
# the audit is wired in here to fail fast. test/python_version_audit.py scans
# the scoped build/runtime/provisioning/doc artifacts and exits non-zero
# (printing the offending lines) if a disallowed end-of-life interpreter (the
# unsupported 3.9 series) reference is reintroduced. Running it before the
# (slow) docker builds means a regression aborts the build immediately with a
# clear message. The preserved distro-python references (g-ir-scanner system
# python, host model-conversion python3) are intentionally NOT matched by the
# audit. Set SKIP_PY_AUDIT=1 to bypass (not recommended).
if [ "${SKIP_PY_AUDIT:-0}" = "1" ]; then
echo "SKIP_PY_AUDIT=1 set — skipping interpreter-version audit guard."
elif command -v python3 >/dev/null 2>&1 && [ -f test/python_version_audit.py ]; then
echo "Running interpreter-version audit guard (no disallowed 3.9 references)..."
python3 test/python_version_audit.py \
|| { echo "ERROR: interpreter-version audit failed — a disallowed end-of-life 3.9 interpreter reference reappeared (see hits above). Aborting build."; exit 1; }
echo "Interpreter-version audit passed (no disallowed 3.9 references)."
else
echo "WARNING: skipping interpreter-version audit guard (python3 or test/python_version_audit.py not found)."
fi
BUILDKIT_PROGRESS=plain
export BUILDKIT_PROGRESS
# Base-image Ubuntu release (edgemlsdk -u and the generic Dockerfile's OS
# build arg): the build host's own release.
IMAGE_VER=$(grep "DISTRIB_RELEASE" /etc/lsb-release | cut -d'=' -f2)
# Export as environment variable
export IMAGE_VER
# Determine the build target from the component name (JP5/JP6/JP7/Nvidia
# tokens). The derivation lives in the sourceable helper
# scripts/build-target-derivation.sh (spec: jetpack7-support) — the single
# source of truth, property-testable without running a build.
# derive_build_target sets IS_JP5/IS_JP6/IS_JP7/IS_X86_NVIDIA and JETPACK_ARG,
# and exports BACKEND_DOCKERFILE per the derivation table (JP5 -> an L4T r35.x
# base, JP6 -> r36.x, JP7 -> a CUDA 13.0 Ubuntu 24.04 arm64 base, Nvidia ->
# Dockerfile.x86_64_nvidia, no token -> the default CPU-only Dockerfile).
# resolve_onnxruntime_gpu (called below, after the derivation) sets
# ONNXRUNTIME_GPU with the existing ONNXRUNTIME_GPU=0 opt-out semantics.
. "$(dirname "$0")/scripts/build-target-derivation.sh"
derive_build_target "$COMPONENT_NAME"
# The generic arm64 CPU component (an aarch64 build with no JetPack token)
# is an Ubuntu 22.04 image whatever the build host runs: only the JetPack 5
# target stays on 20.04, and its plugin build image
# (dda-plugin-build:arm64_cpu) and platform record are 22.04 / GStreamer
# 1.20.
#
# The x86 NVIDIA target (IS_X86_NVIDIA=1) is pinned to 22.04 for the SAME
# reason: its backend base (src/backend/Dockerfile.x86_64_nvidia) is
# hard-pinned to nvidia/cuda:...-ubuntu22.04 whatever the build host, so the
# edgemlsdk/panorama GStreamer plugins MUST be compiled on 22.04 too — then
# they link the base's OpenSSL 3 (libcrypto.so.3 / libssl.so.3), which the
# base ships. Building them on a <22.04 host (such as an Ubuntu 20.04 host)
# instead links them to libcrypto.so.1.1 / libssl.so.1.1, which the 22.04
# base lacks (jammy has no libssl1.1), so every /usr/lib/panoramagst plugin
# (emexifextract, emlfilesrc, emlcapture, genicamsrc, ...) fails to load with
# "libcrypto.so.1.1: cannot open shared object file" and no jpeg/camera
# GStreamer pipeline can be constructed. Pinning here keeps the invariant
# "edgemlsdk build OS == backend base OS" host-independently — the same
# mechanism the generic aarch64 target above uses, and for the same
# base-is-always-22.04 reason.
if { [ "$ARCHITECTURE" = "aarch64" ] && [ "$IS_JP5$IS_JP6$IS_JP7" = "000" ]; } || [ "$IS_X86_NVIDIA" = "1" ]; then
IMAGE_VER=22.04
export IMAGE_VER
fi
# DDA backend interpreter: 3.10 on JP6 (the Jetson AI Lab vLLM wheels are
# cp310-only), 3.11 elsewhere ($PYTHON_VERSION — JP5/x86 behavior unchanged).
# Threaded to the docker-compose backend build (`PYTHON_VERSION` build arg) and
# to the in-image backend test/security-gate run below. The edgemlsdk build
# stays on $PYTHON_VERSION regardless (the Triton stub is cp311-linked).
if [ "$IS_JP6" = "1" ]; then
BACKEND_PYTHON_VERSION="${BACKEND_PYTHON_VERSION:-3.10}"
else
BACKEND_PYTHON_VERSION="$PYTHON_VERSION"
fi
export BACKEND_PYTHON_VERSION
echo "Ubuntu version: $IMAGE_VER"
echo "Architecture: $ARCHITECTURE"
echo "JetPack 5: $IS_JP5"
echo "JetPack 6: $IS_JP6"
echo "JetPack 7: $IS_JP7"
echo "x86 NVIDIA: $IS_X86_NVIDIA"
echo "Backend python: $BACKEND_PYTHON_VERSION (edgemlsdk/tooling python: $PYTHON_VERSION)"
# copy recipe to greengrass-build
cp recipe.yaml ./greengrass-build/recipes
# create custom build directory
rm -rf ./custom-build
mkdir -p ./custom-build/$COMPONENT_NAME
# build Docker images
#
# Docker layer cache policy (DDA_BUILD_NO_CACHE). Historically both
# docker-compose build invocations below hard-coded --no-cache, so every
# build recompiled everything from source — on JP7 that is the ~1-2 h GPU
# onnxruntime build PLUS the multi-hour from-source vLLM wheel compile, even
# when the change under test was a single late layer. The cache is now reused
# by default so iteration builds reuse those layers, and --no-cache is
# opt-in for the cases that genuinely need a provably clean image:
#
# DDA_BUILD_NO_CACHE=1 ./gdk-component-build-and-publish.sh ...
#
# Set it for release/publish builds where reproducibility from scratch
# matters, or when a base image or apt pin changed in a way Docker cannot
# see. Note the cache is only reused when the earlier Dockerfile layers are
# byte-identical: editing a line invalidates that layer and everything after
# it, which is why the expensive compiles sit early in Dockerfile.jp7.
DOCKER_BUILD_CACHE_ARGS=""
if [ "${DDA_BUILD_NO_CACHE:-0}" = "1" ]; then
DOCKER_BUILD_CACHE_ARGS="--no-cache"
echo "Docker layer cache: DISABLED (DDA_BUILD_NO_CACHE=1) — full rebuild"
else
echo "Docker layer cache: ENABLED (set DDA_BUILD_NO_CACHE=1 for a clean rebuild)"
fi
cd src
#edgemlsdk
cd edgemlsdk/
if [ -n "$JETPACK_ARG" ]; then
./build.sh -p $(uname -m) -u $IMAGE_VER -y "$PYTHON_VERSION" -j "$JETPACK_ARG"
else
./build.sh -p $(uname -m) -u $IMAGE_VER -y "$PYTHON_VERSION"
fi
cd ..
echo "Current directory: $(pwd)"
echo "Checking for edgemlsdk directory: $(ls -ld edgemlsdk 2>&1)"
# Start from a clean staging dir. build-custom.sh is run repeatedly on the same
# build server; a leftover backend/edgemlsdk from a previous run makes the
# `cp -r edgemlsdk backend/edgemlsdk` below merge into a stale nested tree and
# fail (cannot stat .../extracted-debs/debs/*.deb). Removing it first makes every
# run behave like a clean checkout.
rm -rf backend/edgemlsdk
mkdir -p backend/edgemlsdk
if [ ! -d "edgemlsdk" ]; then
echo "ERROR: edgemlsdk directory not found at $(pwd)/edgemlsdk"
exit 1
fi
cp -r edgemlsdk backend/edgemlsdk || { echo "ERROR: Failed to copy edgemlsdk from $(pwd)/edgemlsdk to $(pwd)/backend/edgemlsdk"; exit 1; }
echo copying $id
id=$(docker create edgemlsdk)
docker cp $id:/debs/PanoramaSDK.deb $(pwd)/backend/edgemlsdk/
docker cp $id:/debs/aws-c-iot.deb $(pwd)/backend/edgemlsdk/
docker cp $id:/debs/aws-crt-cpp.deb $(pwd)/backend/edgemlsdk/
docker cp $id:/debs/aws-iot-device-sdk-cpp-v2.deb $(pwd)/backend/edgemlsdk/
docker cp $id:/debs/aws-sdk-cpp.deb $(pwd)/backend/edgemlsdk/
docker cp $id:/debs/libgstreamer-plugins-base1.0-dev.deb $(pwd)/backend/edgemlsdk/
docker cp $id:/debs/libgstreamer1.0-dev.deb $(pwd)/backend/edgemlsdk/
docker cp $id:/debs/libgstreamer1.0.deb $(pwd)/backend/edgemlsdk/
docker cp $id:/debs/liborc-0.4-0.deb $(pwd)/backend/edgemlsdk/
docker cp $id:/debs/libstdc++6.deb $(pwd)/backend/edgemlsdk/
docker cp $id:/debs/openssl.deb $(pwd)/backend/edgemlsdk/
docker cp $id:/debs/panorama.whl $(pwd)/backend/edgemlsdk/panorama-1.0-py3-none-any.whl
docker cp $id:/debs/triton-core.deb $(pwd)/backend/edgemlsdk/
docker cp $id:/debs/triton-python-backend.deb $(pwd)/backend/edgemlsdk/
docker cp $id:/tars/triton_installation_files.tar.gz $(pwd)/backend/edgemlsdk/
docker rm -v $id
echo done copying binaries
# rest of the application
# The backend Dockerfile was selected by derive_build_target above (helper
# scripts/build-target-derivation.sh): JP5 uses an L4T r35.x base, JP6 an L4T
# r36.x base, JP7 a CUDA 13.0 Ubuntu 24.04 arm64 base, x86 NVIDIA a CUDA x86
# base (Dockerfile.x86_64_nvidia), everything else the default CPU-only
# Dockerfile.
echo "Backend Dockerfile: $BACKEND_DOCKERFILE"
# ── GPU ONNX Runtime (JP5/JP6/JP7/x86 NVIDIA) ───────────────────────────────
# The OnnxRunner uses a GPU (CUDA/TensorRT) onnxruntime in the backend image.
# GPU is enabled by default on JetPack 5, 6 and 7 (built from source, ~1-2h,
# can be turned off for a fast CPU-only build with ONNXRUNTIME_GPU=0) and on
# the x86 NVIDIA target (prebuilt x86_64 onnxruntime-gpu wheel). The default
# and the ONNXRUNTIME_GPU=0 opt-out live in resolve_onnxruntime_gpu (helper
# sourced above); non-GPU targets are forced to 0 exactly as before.
resolve_onnxruntime_gpu
echo "ONNXRUNTIME_GPU=$ONNXRUNTIME_GPU (1=GPU onnxruntime: source build on JP5/JP6/JP7, prebuilt wheel on x86 NVIDIA. Set 0 for fast CPU-only build)"
echo "Building docker-compose images from $(pwd)/docker-compose.yaml"
# Select profiles by architecture. The `tegra` service targets Jetson
# (platform linux/arm64/v8) and must NOT be built on x86_64 hosts — doing so
# forces an emulated arm64 build that fails compiling Python from source
# ("cannot compute sizeof (long double)"). x86_64 uses only `generic`.
if [ "$ARCHITECTURE" = "x86_64" ]; then
# ONNXRUNTIME_GPU is passed explicitly (as on arm) so the x86 NVIDIA target's
# Dockerfile.x86_64_nvidia installs the GPU onnxruntime wheel; plain x86
# builds keep ONNXRUNTIME_GPU=0 (CPU wheel).
docker-compose --profile generic -f docker-compose.yaml build --build-arg OS=$IMAGE_VER --build-arg PYTHON_VERSION="$BACKEND_PYTHON_VERSION" --build-arg ONNXRUNTIME_GPU=$ONNXRUNTIME_GPU $DOCKER_BUILD_CACHE_ARGS \
|| { echo "ERROR: docker-compose build failed"; exit 1; }
else
docker-compose --profile tegra --profile generic -f docker-compose.yaml build \
--build-arg OS=$IMAGE_VER --build-arg PYTHON_VERSION="$BACKEND_PYTHON_VERSION" \
--build-arg ONNXRUNTIME_GPU=$ONNXRUNTIME_GPU $DOCKER_BUILD_CACHE_ARGS \
|| { echo "ERROR: docker-compose build failed"; exit 1; }
fi
cd ..
# ── Run backend unit tests inside the freshly built flask-app image ─────────
# These tests import the full backend (edgemlsdk bindings, native libs, the
# FastAPI app), so they can only run where those deps already exist — i.e.
# inside the flask-app image we just built. Mount the repo so the tests run
# against the source tree, install the test-only packages on the fly, and run
# pytest. A failure fails the build here, before packaging. Set
# SKIP_BACKEND_TESTS=1 to bypass (e.g. for a quick local rebuild).
if [ "${SKIP_BACKEND_TESTS:-0}" = "1" ]; then
echo "SKIP_BACKEND_TESTS=1 set — skipping backend unit tests."
else
echo "Running backend unit tests inside the flask-app image..."
REPO_ROOT="$(pwd)"
# PYTHON_VERSION is passed into the container via `-e` so the single-quoted
# bash -c body stays intact (no fragile quote-breaking in the outer shell);
# `python${PYTHON_VERSION}` is then expanded by the container's shell at run
# time, resolving to the image's DDA backend interpreter
# (BACKEND_PYTHON_VERSION: 3.10 on JP6, 3.11 on JP5/x86) so the tests and
# security gates execute under the interpreter the backend actually runs on.
docker run --rm \
-v "$REPO_ROOT":/repo -w /repo \
-e PYTHON_VERSION="$BACKEND_PYTHON_VERSION" \
--entrypoint bash flask-app -c '
set -e
python${PYTHON_VERSION} -m pip install --no-cache-dir --quiet pytest pytest-cov sarge testfixtures hypothesis
export PYTHONPATH=/repo/src/backend
# The backend imports the triton/panorama bindings at collection time
# (via conftest). docker-compose normally provides these loader paths at
# Run time; replicate them here so libtritonserver.so resolves.
export LD_LIBRARY_PATH=/opt/tritonserver/lib:/usr/local/cuda/lib64:${LD_LIBRARY_PATH:-}
python${PYTHON_VERSION} -m pytest \
test/backend-test/utils/test_auth.py \
test/backend-test/api-endpoints/test_auth_info_api.py \
test/backend-test/utils/test_user_group_management_utils.py \
test/backend-test/utils/test_dda_user_management_utils.py \
test/backend-test/host_scripts/test_docker_profile_selection.py \
test/backend-test/mcp_edge/test_proxy_route.py \
test/backend-test/mcp_edge/test_config.py \
test/backend-test/mcp_edge/test_shared_ipc_reader.py \
test/backend-test/mcp_edge/test_auth_decision.py \
test/backend-test/api-endpoints/test_authorize_request.py -v
# ── Stream camera components gate ─────────────────────────────────────
# (spec: rtsp-rtmp-stream-cameras, Requirements 17.2, 17.3). Fails the
# build when this image lacks a GStreamer element of the RTSP or RTMP
# ingest heads or of the decode tail, PyAV with FFmpeg 6.1 or later and
# its flv demuxer and rtmp protocol, or H.264/H.265 software decoding,
# RTMP H.265 over Enhanced FLV included. --noconftest: the suite
# conftest mocks gi, and this gate needs the real GStreamer.
echo "Running stream camera components gate..."
DDA_STREAM_COMPONENT_GATE=1 python${PYTHON_VERSION} -m pytest --noconftest \
test/backend-test/stream_ingest/test_image_stream_components.py -v
echo "Stream camera components gate passed."
# ── Security injection / deserialization gate ─────────────────────────
# (spec: security-injection-deserialization-fixes). A single green gate:
# 1. repo_audit.py — pattern gate; exits non-zero if a disallowed
# subprocess-interpolation / unsafe-deserializer pattern reappears in
# in-scope application code (minus documented # nosem exceptions).
# 2. Fix-checking suite — every injection/deserialization vector stays
# neutralized.
# 3. Preservation suite — F(X) == F'\''(X) for legitimate inputs
# (--noconftest is required: this suite is self-contained and must
# not load the backend conftest).
# set -e above makes any failure here fail the build.
echo "Running security injection/deserialization audit gate..."
python${PYTHON_VERSION} test/backend-test/security/repo_audit.py
python${PYTHON_VERSION} -m pytest \
test/backend-test/security/test_bug_condition_exploration.py -v
python${PYTHON_VERSION} -m pytest \
test/backend-test/security/preservation \
-p no:cacheprovider --noconftest -v
echo "Security audit gate passed."
# ── Security secrets/credentials/JWT audit gate ───────────────────────
# (spec: security-secrets-credentials-jwt-fixes). A second gate covering
# the secrets/credentials/JWT batch:
# 1. secrets_audit.py — pattern gate; exits non-zero if a disallowed
# json.dumps(event) log / access_key|secret_key interpolation /
# un-annotated verify_signature=False reappears in in-scope source.
# 2. Fix-checking suite — every secrets/credentials/JWT vector stays
# neutralized.
# Preservation suite is already run by the Group-1 gate above (it covers
# both specs'\'' baselines).
echo "Running security secrets/credentials/JWT audit gate..."
python${PYTHON_VERSION} test/backend-test/security/secrets_audit.py
python${PYTHON_VERSION} -m pytest \
test/backend-test/security/test_secrets_bug_condition_exploration.py -v
echo "Security secrets/credentials/JWT audit gate passed."
# ── Security IAM / authorization audit gate ───────────────────────────
# (spec: security-iam-authorization-fixes). A gate covering the IAM
# least-privilege batch:
# 1. iam_audit.py — pattern gate; exits non-zero if a disallowed
# wildcard-resource-on-scopable-action / service:* action wildcard /
# wildcard-account sts:AssumeRole / unenforced-tag PolicyStatement
# reappears in in-scope infrastructure code (minus documented
# # nosec exceptions).
# 2. Fix-checking suite — every IAM/authorization vector stays
# neutralized (scoped ARNs / tag Conditions / bounded accounts).
# The security/preservation suite (run by the Group-1 gate above) already
# covers the IAM preservation baselines (test_preservation_iam_*).
echo "Running security IAM/authorization audit gate..."
python${PYTHON_VERSION} test/backend-test/security/iam_audit.py
python${PYTHON_VERSION} -m pytest \
test/backend-test/security/test_iam_bug_condition_exploration.py -v
echo "Security IAM/authorization audit gate passed."
# ── Security S3 bucket-squatting audit gate ───────────────────────────
# (spec: security-s3-bucket-squatting-fixes). A gate covering the S3
# bucket-squatting batch (B1-B6):
# 1. s3_squat_audit.py — pattern gate; exits non-zero if a predictable
# S3 bucket access (aws s3 cp/sync against a hardcoded literal, an
# s3:// download URI, or a "bucket" config value) reappears in
# in-scope source without an adjacent head-bucket
# --expected-bucket-owner preflight, env-var parameterization, or
# placeholder / ownership note (per-bucket preflight association).
# 2. Fix-checking + negative-fixture suite — every S3 access stays
# squatting-resistant and the gate cannot be satisfied by a
# file-global preflight presence check.
# The security/preservation suite (run by the Group-1 gate above) already
# covers the S3 preservation baselines (test_preservation_s3_*).
echo "Running security S3 bucket-squatting audit gate..."
python${PYTHON_VERSION} test/backend-test/security/s3_squat_audit.py
python${PYTHON_VERSION} -m pytest \
test/backend-test/security/test_s3_squat_bug_condition_exploration.py \
test/backend-test/security/test_s3_squat_gate_negative_fixture.py -v
echo "Security S3 bucket-squatting audit gate passed."
# ── Security Docker non-ECR base image audit gate ─────────────────────
# (spec: security-docker-non-ecr-base-image-fixes). A gate covering the
# Docker non-ECR base-image batch (D1-D6):
# 1. docker_base_image_audit.py — pattern gate; exits non-zero if an
# in-scope Jetson Dockerfile FROM (src/backend/Dockerfile.jp5|jp6,
# src/edgemlsdk/Dockerfile.jp5|jp6) pulls from a non-ECR registry
# (nvcr.io) without being both ${BASE_REGISTRY}-parameterized and
# @sha256-digest-pinned (per-FROM, not file-global).
# 2. Fix-checking + negative-fixture suite — every in-scope base image
# stays registry-parameterized + digest-pinned and the gate cannot be
# satisfied by a file-global ${BASE_REGISTRY}/nvcr.io presence check.
# The security/preservation suite (run by the Group-1 gate above) already
# covers the Docker preservation baselines (test_preservation_docker_*).
echo "Running security Docker non-ECR base image audit gate..."
python${PYTHON_VERSION} test/backend-test/security/docker_base_image_audit.py
python${PYTHON_VERSION} -m pytest \
test/backend-test/security/test_docker_base_image_bug_condition_exploration.py \
test/backend-test/security/test_docker_audit_gate_negative_fixture.py -v
echo "Security Docker non-ECR base image audit gate passed."
# ── Security dependency / supply-chain CVE audit gate ─────────────────
# (spec: security-dependency-cve-fixes). A gate covering the dependency /
# supply-chain CVE + weak-hash batch (F1-F4):
# 1. dependency_audit.py — pattern gate; exits non-zero if an in-scope
# pinned requests version < 2.32.4 (CVE-2024-47081) reappears at
# station_install/setup_station.sh or src/backend/requirements.txt
# (the two Python-3.11 pin sites), or if the documented B324
# RFC-2617 digest-auth allowlist drifts. Unpinned system-python3
# installs and out-of-scope pins are never flagged.
# 2. Fix-checking + negative-fixture suite — the in-scope pins stay
# >= 2.32.4, the B324 accepted false positive stays documented, and a
# bare unpinned requests / out-of-scope pin is never flagged.
# The security/preservation suite (run by the Group-1 gate above) already
# covers the dependency preservation baselines (test_preservation_dependency_*).
echo "Running security dependency/supply-chain CVE audit gate..."
python${PYTHON_VERSION} test/backend-test/security/dependency_audit.py
python${PYTHON_VERSION} -m pytest \
test/backend-test/security/test_dependency_bug_condition_exploration.py \
test/backend-test/security/test_dependency_audit_gate_negative_fixture.py -v
echo "Security dependency/supply-chain CVE audit gate passed."
' || { echo "ERROR: backend unit tests / security audit gate failed"; exit 1; }
echo "Backend unit tests passed."
fi
# save Docker images as tar
echo "save docker images as tarvballs"
# Save via `docker save --output` to a .partial name, then atomically mv
# into place. NEITHER historical form works bare under snap Docker:
# - `docker save <img> > <file>` fails under the SSM RunShellScript
# context with "write /dev/stdout: bad file descriptor" (EBADF),
# leaving a 0-byte tar (portal job d844a5fb, 2026-08-09).
# - bare `--output <final-name>` writes a transient `.tmp-<name><rand>`
# in the destination dir and renames it, which raced the old recursive
# packaging zip (exit 18).
# The .partial suffix + atomic same-dir mv means the final tar name only
# ever exists complete; transient `.tmp-*`/`.partial` names are policed by
# the pre-zip `rm -f .tmp-*` cleanup and the explicit ZIP_MEMBERS list
# with its `-x '*/.tmp-*'` exclusion below. The integrity guard makes any
# residual save failure loud — a 0-byte or truncated tar can never reach
# the zip silently.
save_image_tar() {
local image=$1 dest=$2
rm -f "$dest" "$dest.partial"
if ! docker save --output "$dest.partial" "$image"; then
echo "ERROR: docker save $image failed."
echo " docker: $(docker --version 2>/dev/null || echo 'version unavailable')"
echo " Staging dir:"
ls -lh "$(dirname "$dest")" || true
echo " Disk free:"
df -h "$(dirname "$dest")" || true
exit 1
fi
mv "$dest.partial" "$dest"
local size
size=$(stat -c%s "$dest")
if [ "$size" -lt 1048576 ] || ! tar -tf "$dest" > /dev/null; then
echo "ERROR: saved image tar $dest failed integrity check (size ${size} bytes)."
exit 1
fi
echo "Saved $image -> $dest ($size bytes, tar structure OK)"
}
save_image_tar flask-app ./custom-build/$COMPONENT_NAME/flask-app.tar
save_image_tar react-webapp ./custom-build/$COMPONENT_NAME/react-webapp.tar
# include docker-compose.yaml in archive
cp src/docker-compose.yaml ./custom-build/$COMPONENT_NAME/
# include empty directories for each image build context
mkdir -p ./custom-build/$COMPONENT_NAME/backend
mkdir -p ./custom-build/$COMPONENT_NAME/frontend
mkdir -p ./custom-build/$COMPONENT_NAME/host_scripts
mkdir -p ./greengrass-build/artifacts/$COMPONENT_NAME/$VERSION/
# include dio script that triggers output
cp src/backend/triggers/outputs/dio.py ./custom-build/$COMPONENT_NAME/
cp -r src/host_scripts ./custom-build/$COMPONENT_NAME/
# zip up archive
ARCHIVE="./custom-build/$COMPONENT_NAME-$ARCHITECTURE.zip"
rm -f "$ARCHIVE"
# Remove any transient docker-save temp files (e.g. .tmp-react-webapp.tar<rand>)
# that snap Docker may leave briefly in the build dir.
rm -f ./custom-build/$COMPONENT_NAME/.tmp-* 2>/dev/null || true
# Diagnostics: make the next failure conclusive (zip version, what we're about
# to package, and free space on the build volume).
echo "Packaging artifact: $ARCHIVE"
echo "zip version: $(zip --version 2>/dev/null | head -1)"
echo "Staging dir contents:"
ls -lh ./custom-build/$COMPONENT_NAME/ || true
echo "Disk free on build volume:"
df -h ./custom-build/ | tail -n +1 || true
# Package an EXPLICIT member list rather than `zip -r <dir>`. A recursive scan
# of the staging dir can enumerate a transient file (e.g. a snap Docker save
# temp) and then fail with exit 18 / "could not open for reading" /
# "Could not create output file" when that file is renamed away mid-zip.
# Listing only the files we staged removes that race entirely.
ZIP_MEMBERS=(
"custom-build/$COMPONENT_NAME/docker-compose.yaml"
"custom-build/$COMPONENT_NAME/flask-app.tar"
"custom-build/$COMPONENT_NAME/react-webapp.tar"
"custom-build/$COMPONENT_NAME/dio.py"
"custom-build/$COMPONENT_NAME/host_scripts"
"custom-build/$COMPONENT_NAME/backend"
"custom-build/$COMPONENT_NAME/frontend"
)
zip -r -X "$ARCHIVE" "${ZIP_MEMBERS[@]}" -x '*/.tmp-*' || {
rc=$?
echo "ERROR: packaging zip failed (exit $rc)."
echo " Staging dir:"
ls -lh ./custom-build/$COMPONENT_NAME/ || true
echo " Disk free:"
df -h ./custom-build/ || true
exit $rc
}
# Verify the archive is complete/readable before handing it to GDK. `zip -T`
# is part of zip itself (no unzip dependency required).
if ! zip -T "$ARCHIVE" >/dev/null 2>&1; then
echo "ERROR: packaged archive $ARCHIVE failed integrity check (zip -T)."
exit 1
fi
echo "Archive created: $(ls -lh "$ARCHIVE" | awk '{print $5, $9}')"
# copy archive to greengrass-build
cp "$ARCHIVE" ./greengrass-build/artifacts/$COMPONENT_NAME/$VERSION/