forked from mtusi2026/mtusi2026lab7
This commit is contained in:
Executable
+51
@@ -0,0 +1,51 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
[ "${DOCKER_WORKSPACE_MIRROR:-0}" = "1" ] || exit 0
|
||||
|
||||
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
repo_dir=$(CDPATH= cd -- "$script_dir/.." && pwd)
|
||||
mode=${1:-sync}
|
||||
|
||||
case "$mode" in
|
||||
sync|--pull-scan) ;;
|
||||
--clean)
|
||||
case "$repo_dir" in
|
||||
/tmp/mtusi2026lab7-*) ;;
|
||||
*) echo "cleanup is restricted to temporary CI workspaces" >&2; exit 2 ;;
|
||||
esac
|
||||
run_id=${repo_dir#/tmp/mtusi2026lab7-}
|
||||
case "$run_id" in
|
||||
''|*[!0-9]*) echo "invalid CI workspace name" >&2; exit 2 ;;
|
||||
esac
|
||||
docker run --rm --network none -v "$repo_dir:/workspace" alpine:3.24.2 \
|
||||
find /workspace -mindepth 1 -delete
|
||||
exit 0
|
||||
;;
|
||||
*) echo "usage: $0 [--pull-scan|--clean]" >&2; exit 2 ;;
|
||||
esac
|
||||
|
||||
[ -f "$repo_dir/compose.yaml" ] || {
|
||||
echo "repository checkout is incomplete" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
container=$(docker create --network none \
|
||||
-v "$repo_dir:/workspace" \
|
||||
alpine:3.24.2 /bin/true)
|
||||
|
||||
cleanup() {
|
||||
docker rm -f "$container" >/dev/null 2>&1 || true
|
||||
}
|
||||
|
||||
trap cleanup EXIT HUP INT TERM
|
||||
|
||||
if [ "$mode" = "--pull-scan" ]; then
|
||||
destination=$repo_dir/evidence/runtime/security-scan
|
||||
mkdir -p "$destination"
|
||||
docker cp "$container:/workspace/evidence/runtime/security-scan/." "$destination"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
docker cp "$repo_dir/." "$container:/workspace"
|
||||
Reference in New Issue
Block a user