-
Notifications
You must be signed in to change notification settings - Fork 0
Add offline jdt2jar CLI and distroless packaging #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d431813
Initial plan
Copilot dfc8f52
Issue #0 add jdt2jar CLI and container
Copilot bca1b6e
Issue #0 refine jdt2jar packaging
Copilot 150b958
Issue #0 address jdt2jar review feedback
Copilot cc652d4
Issue #148 scope jdt2jar Dockerfile to submodule, add GHCR publish an…
simbo1905 3a96296
Issue #148 fix expected test count from 1354 to 1356 for jdt2jar modu…
simbo1905 6532a59
Issue #148 clarify two JTD validation paths in READMEs
simbo1905 04984c4
Issue #148 separate interpreter and codegen JtdValidator interfaces
simbo1905 99ce4b3
Issue #148 fix expected test count from 1356 to 1355 (removed compile…
simbo1905 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Build outputs | ||
| **/target/ | ||
|
|
||
| # IDE | ||
| .idea/ | ||
| *.iml | ||
| .vscode/ | ||
| .eclipse/ | ||
|
|
||
| # OS | ||
| .DS_Store | ||
|
|
||
| # Git | ||
| .git/ | ||
| .gitignore | ||
|
|
||
| # Env | ||
| .env | ||
|
|
||
| # Local test artifacts | ||
| /tmp/jdt2jar-*/ | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # syntax=docker/dockerfile:1 | ||
|
|
||
| FROM eclipse-temurin:24-jdk AS build | ||
| WORKDIR /build | ||
| COPY . . | ||
| RUN ["./mvnw", "-pl", "jdt2jar", "-am", "package", "-DskipTests", "-Dsurefire.failIfNoSpecifiedTests=false"] | ||
| RUN ["java", "-cp", "/build/jdt2jar/target/jdt2jar.jar", "json.java21.jdt2jar.build.DockerImageBuilder", "/build/jdt2jar/target/jdt2jar.jar", "/opt/jre"] | ||
| RUN ["mkdir", "-p", "/empty-work/tmp", "/empty-app"] | ||
|
|
||
| FROM gcr.io/distroless/base-debian13:nonroot | ||
| COPY --from=build --chown=65532:65532 /empty-work /work | ||
| COPY --from=build --chown=65532:65532 /empty-app /app | ||
| ENV JAVA_TOOL_OPTIONS="-XX:+UseContainerSupport -XX:MaxRAMPercentage=75.0 -Djava.io.tmpdir=/work/tmp -XX:+ExitOnOutOfMemoryError" | ||
| COPY --from=build /opt/jre /jre | ||
| COPY --from=build /build/jdt2jar/target/jdt2jar.jar /app/jdt2jar.jar | ||
| ENTRYPOINT ["/jre/bin/java","-jar","/app/jdt2jar.jar"] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| # jdt2jar | ||
|
|
||
| `jdt2jar` compiles a JTD schema into a standalone validator JAR at build time. The generated JAR runs on JDK 21+ with no JDK 24+ runtime dependency. | ||
|
|
||
| ## Use Case | ||
|
|
||
| This tool bridges the gap between the interpreter and codegen paths: | ||
|
|
||
| - **Interpreter** ([`json-java21-jtd`](../json-java21-jtd/README.md)): ideal for infrequent config parsing — simple, no build step, runs on JDK 21+. | ||
| - **Codegen** ([`json-java21-jtd-codegen`](../json-java21-jtd-codegen/README.md)): ideal for repeated hot-path validation — ~9x faster, but requires JDK 24+ at runtime. | ||
| - **jdt2jar**: pre-compiles schemas into validator JARs at build time (using JDK 24+), then deploys them to any JDK 21+ runtime. Best for CI/CD pipelines, distroless containers, or environments where you want JIT-optimised validators without shipping a JDK 24+ runtime. | ||
|
|
||
| > **Future note**: `java.util.json` has entered the JDK incubator (`jdk.incubator.json`). Once the API stabilises in the JDK itself, generated bytecode validators can depend directly on future JDK classes rather than this backport, making them even more efficient with zero library overhead. | ||
|
|
||
| ## CLI | ||
|
|
||
| ```bash | ||
| jdt2jar <schema.json> [options] | ||
| ``` | ||
|
|
||
| Options: | ||
|
|
||
| - `--output <path>`: output JAR path (default: `<schema-name>-validator.jar`) | ||
| - `--package <name>`: generated package name (default: `jtd.generated`) | ||
| - `--class <name>`: validator class name (default: `SchemaValidator`) | ||
| - `--main`: include a standalone `java -jar` entry point | ||
| - `--runtime <version>`: target bytecode version (default: 21) | ||
| - `--include-sources`: write a companion `.java` file next to the JAR | ||
| - `--help`: show usage | ||
|
|
||
| ## Container Image | ||
|
|
||
| A minimal distroless container image is available for offline schema compilation without a full JDK. | ||
|
|
||
| ### Pre-built Image (GitHub Container Registry) | ||
|
|
||
| ```bash | ||
| # Pull the latest image | ||
| docker pull ghcr.io/simbo1905/java.util.json.java21/jdt2jar:latest | ||
|
|
||
| # Pull a specific release version | ||
| docker pull ghcr.io/simbo1905/java.util.json.java21/jdt2jar:2026.02.05 | ||
| ``` | ||
|
|
||
| ### Build Locally | ||
|
|
||
| Requires Docker and JDK 24+ (for the build stage). Build from the repository root: | ||
|
|
||
| ```bash | ||
| docker build -t jdt2jar -f jdt2jar/Dockerfile . | ||
| ``` | ||
|
|
||
| ### Usage | ||
|
|
||
| ```bash | ||
| # Show help | ||
| docker run --rm ghcr.io/simbo1905/java.util.json.java21/jdt2jar:latest --help | ||
|
|
||
| # Compile a schema to a validator JAR (using docker cp for file I/O) | ||
| cid=$(docker create --name jdt2jar-build ghcr.io/simbo1905/java.util.json.java21/jdt2jar:latest /work/person.jtd.json --output /work/person-validator.jar --main) | ||
| docker cp person.jtd.json jdt2jar-build:/work/person.jtd.json | ||
| docker start -a jdt2jar-build | ||
| docker cp jdt2jar-build:/work/person-validator.jar . | ||
| docker rm jdt2jar-build | ||
|
|
||
| # Validate a payload with the generated JAR | ||
| java -jar person-validator.jar --validate payload.json | ||
| # Or validate inside a container | ||
| cid=$(docker create --name jdt2jar-validate --entrypoint /jre/bin/java ghcr.io/simbo1905/java.util.json.java21/jdt2jar:latest -jar /work/person-validator.jar --validate /work/payload.json) | ||
| docker cp person-validator.jar jdt2jar-validate:/work/person-validator.jar | ||
| docker cp payload.json jdt2jar-validate:/work/payload.json | ||
| docker start -a jdt2jar-validate | ||
| docker rm jdt2jar-validate | ||
| ``` | ||
|
|
||
| ### Image Properties | ||
|
|
||
| - **Base**: `gcr.io/distroless/base-debian13:nonroot` | ||
| - **Runtime**: jlink-minimized JDK 24 (~40 MB) | ||
| - **Total size**: ~111 MB disk / ~31 MB content | ||
| - **User**: `nonroot` (uid 65532) | ||
| - **Shell**: none (distroless) | ||
| - **Writable directories**: `/work` (for schema input and JAR output) | ||
|
|
||
| ### Security Scanning | ||
|
|
||
| ```bash | ||
| syft packages image:ghcr.io/simbo1905/java.util.json.java21/jdt2jar:latest | ||
| grype ghcr.io/simbo1905/java.util.json.java21/jdt2jar:latest | ||
| ``` |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ignore file is never applied by the current CI/release Docker builds because they invoke
docker buildwithcontext: .(repository root), and Docker only reads.dockerignorefrom the context root (or aDockerfile.dockerignorecompanion). As a result, large/sensitive files (for example.git/,.env, and local artifacts) are still sent in build context despite being listed here, which increases build time and can leak unintended content into remote builders.Useful? React with 👍 / 👎.