From 1b19d5443d08b5efedb4b612b78d539a2868aaed Mon Sep 17 00:00:00 2001 From: varch Date: Sun, 7 Jun 2026 01:06:21 +0700 Subject: [PATCH] refactor: remove vendored binaries and raw assets from repo --- .gitignore | 12 ++++++ README.md | 11 ++++++ docs/deployment-vm.md | 7 ++++ docs/repo-size-cleanup.md | 18 +++++++++ scripts/purge-git-history.sh | 14 +++++++ scripts/setup-dcmtk.sh | 76 ++++++++++++++++++++++++++++++++++++ scripts/setup-microdicom.sh | 58 +++++++++++++++++++++++++++ 7 files changed, 196 insertions(+) create mode 100644 docs/repo-size-cleanup.md create mode 100755 scripts/purge-git-history.sh create mode 100755 scripts/setup-dcmtk.sh create mode 100755 scripts/setup-microdicom.sh diff --git a/.gitignore b/.gitignore index 06368b1..ee81615 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,11 @@ config.yaml # ISO output files *.iso +# Vendored/runtime assets fetched outside git +dcmtk-bin/ +legacy/raw/ +.local/ + # Temp directories /tmp/dicomdir_* @@ -20,3 +25,10 @@ Thumbs.db # Local-only docs tell @VArtzy for request docs/phases + +# Keep placeholder docs for ignored asset directories +!dcmtk-bin/ +!dcmtk-bin/README.md +!legacy/ +!legacy/raw/ +!legacy/raw/README.md diff --git a/README.md b/README.md index 4558d70..20430a4 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,9 @@ The service needs: - MicroDicom files - writable temp storage +Large runtime assets are intentionally not stored in git. +Use the setup scripts in `scripts/` to stage local copies in ignored directories. + ## Setup Before running the service, make sure the VM has: - Go installed, if you are building on that machine @@ -33,6 +36,13 @@ Before running the service, make sure the VM has: - network access to PACS, the patient API, and the CD publisher - a writable temp directory +Stage local runtime assets if needed: + +```bash +scripts/setup-dcmtk.sh --source-dir /path/to/dcmtk/bin +scripts/setup-microdicom.sh --source-dir /path/to/microdicom +``` + Create a local config file from the template: ```bash @@ -40,6 +50,7 @@ cp config.example.yaml config.yaml ``` Then adjust the paths, hosts, ports, and tokens for your environment. +For local staging via the setup scripts, point config at `.local/dcmtk-bin/` and `.local/microdicom/`. ## Build A normal Go build is enough in a friendly environment: diff --git a/docs/deployment-vm.md b/docs/deployment-vm.md index 4178aef..607bb8f 100644 --- a/docs/deployment-vm.md +++ b/docs/deployment-vm.md @@ -29,6 +29,13 @@ The service needs: - a writable temp directory - a free port range for `storescp` +If you do not manage these assets globally on the VM, you can stage them locally first: + +```bash +scripts/setup-dcmtk.sh --source-dir /path/to/dcmtk/bin --install-dir /opt/dicom-iso/dcmtk-bin +scripts/setup-microdicom.sh --source-dir /path/to/microdicom --install-dir /opt/dicom-iso/microdicom +``` + ## Build note The build environment cannot depend on public internet access. That means the binary must be built through an approved offline-friendly path. diff --git a/docs/repo-size-cleanup.md b/docs/repo-size-cleanup.md new file mode 100644 index 0000000..504a429 --- /dev/null +++ b/docs/repo-size-cleanup.md @@ -0,0 +1,18 @@ +# Repo size cleanup + +Implemented in the working tree: +- removed tracked binaries from `dcmtk-bin/` +- removed tracked raw assets from `legacy/raw/` +- added `.gitignore` protections +- added setup scripts for DCMTK and MicroDicom + +## Finish the cleanup in git history +Rewriting history is still required to shrink the remote repository size. + +```bash +git filter-repo --path dcmtk-bin --path legacy/raw --invert-paths +git push --force --all +git push --force --tags +``` + +Coordinate this with any collaborators first. diff --git a/scripts/purge-git-history.sh b/scripts/purge-git-history.sh new file mode 100755 index 0000000..309e06f --- /dev/null +++ b/scripts/purge-git-history.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -euo pipefail + +cat <<'EOF' +This rewrites git history to remove large vendored assets. +Run only after committing the current tree cleanup and coordinating with collaborators. + +Commands: + git filter-repo --path dcmtk-bin --path legacy/raw --invert-paths + git push --force --all + git push --force --tags + +Afterward, collaborators should reclone or hard-reset to the rewritten history. +EOF diff --git a/scripts/setup-dcmtk.sh b/scripts/setup-dcmtk.sh new file mode 100755 index 0000000..27694ad --- /dev/null +++ b/scripts/setup-dcmtk.sh @@ -0,0 +1,76 @@ +#!/usr/bin/env bash +set -euo pipefail + +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +INSTALL_DIR="${INSTALL_DIR:-$ROOT_DIR/.local/dcmtk-bin}" +REQUIRED_BINS=(storescp movescu storescu findscu dcmdump dcmodify getscu echoscu dcmj2pnm) + +usage() { + cat <<'EOF' +Usage: + scripts/setup-dcmtk.sh [--source-dir DIR] [--install-dir DIR] + +Behavior: + - Copies required DCMTK binaries into a local ignored directory. + - If --source-dir is omitted, binaries are resolved from PATH. + +Examples: + scripts/setup-dcmtk.sh --source-dir /opt/dcmtk/bin + scripts/setup-dcmtk.sh --install-dir /data/dcmtk-bin +EOF +} + +SOURCE_DIR="" +while [[ $# -gt 0 ]]; do + case "$1" in + --source-dir) + SOURCE_DIR="${2:?missing value for --source-dir}" + shift 2 + ;; + --install-dir) + INSTALL_DIR="${2:?missing value for --install-dir}" + shift 2 + ;; + -h|--help) + usage + exit 0 + ;; + *) + echo "Unknown argument: $1" >&2 + usage >&2 + exit 1 + ;; + esac +done + +mkdir -p "$INSTALL_DIR" + +resolve_bin() { + local name="$1" + if [[ -n "$SOURCE_DIR" ]]; then + local candidate="$SOURCE_DIR/$name" + [[ -x "$candidate" ]] || { echo "missing executable: $candidate" >&2; return 1; } + printf '%s\n' "$candidate" + return 0 + fi + + command -v "$name" >/dev/null 2>&1 || { echo "binary not found in PATH: $name" >&2; return 1; } + command -v "$name" +} + +for bin in "${REQUIRED_BINS[@]}"; do + src="$(resolve_bin "$bin")" + install -m 0755 "$src" "$INSTALL_DIR/$bin" + echo "installed $bin -> $INSTALL_DIR/$bin" +done + +cat <&2 + usage >&2 + exit 1 + ;; + esac +done + +[[ -n "$SOURCE_DIR" ]] || { echo "--source-dir is required" >&2; exit 1; } +[[ -d "$SOURCE_DIR" ]] || { echo "source directory does not exist: $SOURCE_DIR" >&2; exit 1; } +[[ -f "$SOURCE_DIR/AUTORUN.INF" ]] || { echo "missing AUTORUN.INF in source directory" >&2; exit 1; } +[[ -d "$SOURCE_DIR/MICROD" ]] || { echo "missing MICROD/ in source directory" >&2; exit 1; } + +rm -rf "$INSTALL_DIR" +mkdir -p "$INSTALL_DIR" +cp -a "$SOURCE_DIR"/. "$INSTALL_DIR"/ + +echo "installed MicroDicom assets -> $INSTALL_DIR" +cat <