Skip to content

Commit 3c59844

Browse files
committed
Issue #148 add helper script for restricted volume mount environments, clean up README
1 parent 603f2c1 commit 3c59844

2 files changed

Lines changed: 42 additions & 25 deletions

File tree

jdt2jar/README.md

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ A minimal distroless container image is available for offline schema compilation
3535
### Pre-built Image (GitHub Container Registry)
3636

3737
```bash
38-
# Pull the latest image
3938
docker pull ghcr.io/simbo1905/java.util.json.java21/jdt2jar:latest
40-
41-
# Pull a specific release version
4239
docker pull ghcr.io/simbo1905/java.util.json.java21/jdt2jar:2026.05.20
4340
```
4441

@@ -52,39 +49,34 @@ docker build -t jdt2jar -f jdt2jar/Dockerfile .
5249

5350
### Usage
5451

55-
The container's working directory is `/work`. Mount your local directory there, or use `docker cp` for environments where volume mounts are restricted (e.g., Colima on macOS).
52+
The container's working directory is `/work`. Mount your project directory there:
53+
54+
```bash
55+
docker run --rm -v "$(pwd):/work" jdt2jar:latest schema.jtd.json --output schema-validator.jar --main
56+
```
5657

57-
#### Option 1: Volume mount (Linux, Docker Desktop with file sharing enabled)
58+
Validate a payload with the generated JAR:
5859

5960
```bash
60-
# bash / zsh
61-
docker run --rm -v "$(pwd):/work" ghcr.io/simbo1905/java.util.json.java21/jdt2jar:latest schema.jtd.json --output schema-validator.jar --main
61+
java -jar schema-validator.jar --validate payload.json
62+
```
6263

63-
# PowerShell
64-
docker run --rm -v "${PWD}:/work" ghcr.io/simbo1905/java.util.json.java21/jdt2jar:latest schema.jtd.json --output schema-validator.jar --main
64+
Or validate inside a container:
6565

66-
# cmd.exe
67-
docker run --rm -v "%CD%:/work" ghcr.io/simbo1905/java.util.json.java21/jdt2jar:latest schema.jtd.json --output schema-validator.jar --main
66+
```bash
67+
docker run --rm -v "$(pwd):/work" --entrypoint /jre/bin/java jdt2jar:latest -jar /work/schema-validator.jar --validate /work/payload.json
6868
```
6969

70-
#### Option 2: docker cp (works everywhere, including Colima on macOS)
70+
### Helper Script
71+
72+
For environments where volume mounts are restricted (e.g., Colima on macOS with projects outside `~/`), use the helper script:
7173

7274
```bash
73-
# Compile a schema
74-
cid=$(docker create --name jdt2jar-build ghcr.io/simbo1905/java.util.json.java21/jdt2jar:latest /work/schema.jtd.json --output /work/schema-validator.jar --main)
75-
docker cp schema.jtd.json jdt2jar-build:/work/schema.jtd.json
76-
docker start -a jdt2jar-build
77-
docker cp jdt2jar-build:/work/schema-validator.jar .
78-
docker rm jdt2jar-build
79-
80-
# Validate a payload
81-
cid=$(docker create --name jdt2jar-validate --entrypoint /jre/bin/java ghcr.io/simbo1905/java.util.json.java21/jdt2jar:latest -jar /work/schema-validator.jar --validate /work/payload.json)
82-
docker cp schema-validator.jar jdt2jar-validate:/work/schema-validator.jar
83-
docker cp payload.json jdt2jar-validate:/work/payload.json
84-
docker start -a jdt2jar-validate
85-
docker rm jdt2jar-validate
75+
./scripts/jdt2jar.sh schema.jtd.json --output schema-validator.jar --main
8676
```
8777

78+
The script syncs source to `~/tmp/jdt2jar-work`, runs the container, and syncs output back.
79+
8880
### Image Properties
8981

9082
- **Base**: `gcr.io/distroless/base-debian13:nonroot`

scripts/jdt2jar.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
# jdt2jar helper script for environments where volume mounts are restricted
3+
# (e.g., Colima on macOS with projects outside ~/).
4+
#
5+
# Usage:
6+
# ./scripts/jdt2jar.sh <schema.jtd.json> [options...]
7+
#
8+
# Example:
9+
# ./scripts/jdt2jar.sh .tmp/test.jtd.json --output .tmp/test.jar --main
10+
11+
set -euo pipefail
12+
13+
WORK_DIR="$HOME/tmp/jdt2jar-work"
14+
IMAGE="${JDT2JAR_IMAGE:-jdt2jar:latest}"
15+
16+
mkdir -p "$WORK_DIR"
17+
18+
# Sync source (respecting .gitignore)
19+
rsync -a --filter=':- .gitignore' --exclude='.git/' . "$WORK_DIR/"
20+
21+
# Run jdt2jar in container
22+
docker run --rm -v "$WORK_DIR:/work" "$IMAGE" "$@"
23+
24+
# Sync output back (any new .jar or .java files in the work dir)
25+
rsync -a --include='*.jar' --include='*.java' --exclude='*' "$WORK_DIR/" ./

0 commit comments

Comments
 (0)