Skip to content

Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.

fix(docker): ship libz and all transitive libs to distroless runtime (closes #59) (#60)

Fabio Rovai59bf5b6b4f3f
diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml
index 067ba580..61799a86 100644
--- a/.github/workflows/docker.yml
+++ b/.github/workflows/docker.yml
@@ -2,14 +2,22 @@ name: Docker
on:
push:
+ branches: [main]
tags: ['v*']
+ pull_request:
+ paths:
+ - 'Dockerfile'
+ - 'Cargo.toml'
+ - 'Cargo.lock'
+ - 'src/**'
+ - '.github/workflows/docker.yml'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
- build-and-push:
+ build:
runs-on: ubuntu-latest
permissions:
contents: read
@@ -26,7 +34,28 @@ jobs:
sudo apt-get clean
df -h
+ - name: Set up Buildx
+ uses: docker/setup-buildx-action@v3
+
+ # Build into the local daemon first so the image can be smoke-tested
+ # before anything is pushed. A plain build only proves the layers
+ # assemble; running the binary proves the dynamic linker can resolve
+ # every shared library, which is exactly what was missing in issue #59
+ # (libz.so.1). Nothing validated the published image before this.
+ - name: Build image
+ uses: docker/build-push-action@v6
+ with:
+ context: .
+ load: true
+ tags: open-ontologies:ci
+ cache-from: type=gha
+ cache-to: type=gha,mode=max
+
+ - name: Smoke test (binary starts, all shared libs resolve)
+ run: docker run --rm open-ontologies:ci --help
+
- name: Log in to GHCR
+ if: startsWith(github.ref, 'refs/tags/v')
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
@@ -34,6 +63,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
+ if: startsWith(github.ref, 'refs/tags/v')
id: meta
uses: docker/metadata-action@v5
with:
@@ -43,10 +73,12 @@ jobs:
type=semver,pattern={{major}}.{{minor}}
type=sha
- - name: Build and push
+ - name: Push image
+ if: startsWith(github.ref, 'refs/tags/v')
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
+ cache-from: type=gha
diff --git a/Dockerfile b/Dockerfile
index 561e77d7..20ad1ecc 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,4 +1,7 @@
-FROM rust:1-slim AS builder
+# Pin the builder to the same Debian release as the distroless runtime
+# (bookworm / Debian 12) so the shared libraries copied across stages share
+# the runtime's glibc ABI and never skew against it.
+FROM rust:1-slim-bookworm AS builder
RUN apt-get update && apt-get install -y --no-install-recommends \
pkg-config libssl-dev libpq-dev build-essential clang && rm -rf /var/lib/apt/lists/*
@@ -9,22 +12,25 @@ WORKDIR /build
COPY . .
RUN cargo build --release && strip target/release/open-ontologies
+# Collect every shared library the binary transitively needs (direct plus
+# recursive NEEDED deps) into /deps, preserving absolute paths. This replaces a
+# hand-maintained COPY list that was easy to leave incomplete (libz.so.1, pulled
+# in via libpq, was missing and broke `serve` at runtime, issue #59). The glibc
+# family, the loader, and libgcc/libstdc++ are excluded because the distroless
+# cc-debian12 base already provides them; we only ship the libs it lacks.
+RUN mkdir -p /deps && \
+ ldd target/release/open-ontologies \
+ | awk '/=> \// {print $3} /^\t\// {print $1}' \
+ | grep -Ev '/(ld-linux[^/]*|libc|libm|libdl|libpthread|librt|libresolv|libgcc_s|libstdc\+\+)\.so' \
+ | sort -u \
+ | xargs -I{} cp -v --parents -L {} /deps/
+
FROM gcr.io/distroless/cc-debian12
LABEL io.modelcontextprotocol.server.name="io.github.fabio-rovai/open-ontologies"
COPY --from=builder /build/target/release/open-ontologies /usr/local/bin/open-ontologies
-COPY --from=builder /usr/lib/x86_64-linux-gnu/libpq.so* /usr/lib/x86_64-linux-gnu/
-COPY --from=builder /usr/lib/x86_64-linux-gnu/libssl.so* /usr/lib/x86_64-linux-gnu/
-COPY --from=builder /usr/lib/x86_64-linux-gnu/libcrypto.so* /usr/lib/x86_64-linux-gnu/
-COPY --from=builder /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so* /usr/lib/x86_64-linux-gnu/
-COPY --from=builder /usr/lib/x86_64-linux-gnu/libldap.so* /usr/lib/x86_64-linux-gnu/
-COPY --from=builder /usr/lib/x86_64-linux-gnu/libkrb5.so* /usr/lib/x86_64-linux-gnu/
-COPY --from=builder /usr/lib/x86_64-linux-gnu/libk5crypto.so* /usr/lib/x86_64-linux-gnu/
-COPY --from=builder /usr/lib/x86_64-linux-gnu/libcom_err.so* /usr/lib/x86_64-linux-gnu/
-COPY --from=builder /usr/lib/x86_64-linux-gnu/libkrb5support.so* /usr/lib/x86_64-linux-gnu/
-COPY --from=builder /usr/lib/x86_64-linux-gnu/liblber.so* /usr/lib/x86_64-linux-gnu/
-COPY --from=builder /usr/lib/x86_64-linux-gnu/libsasl2.so* /usr/lib/x86_64-linux-gnu/
+COPY --from=builder /deps/ /
ENTRYPOINT ["open-ontologies"]
CMD ["serve"]
diff --git a/examples/medicine-sample-after.json b/examples/medicine-sample-after.json
new file mode 100644
index 00000000..6255ca5e
--- /dev/null
+++ b/examples/medicine-sample-after.json
@@ -0,0 +1,96 @@
+[
+ {
+ "@context": {
+ "clinical": "http://example.org/clinical-records-standard#",
+ "dcterms": "http://purl.org/dc/terms/",
+ "skos": "http://www.w3.org/2004/02/skos/core#",
+ "prov": "http://www.w3.org/ns/prov#",
+ "xsd": "http://www.w3.org/2001/XMLSchema#"
+ },
+ "@type": "clinical:DiagnosisRecord",
+ "@id": "https://example.org/records/diag/0001",
+ "dcterms:title": "Essential hypertension",
+ "dcterms:date": {"@type": "xsd:date", "@value": "2025-09-14"},
+ "dcterms:description": "Primary hypertension, no secondary cause identified",
+ "dcterms:relation": "https://example.org/records/diag/0002",
+ "clinical:hasCoding": {
+ "@type": "clinical:Code",
+ "clinical:primaryCode": "I10",
+ "clinical:primarySystem": "ICD-10",
+ "skos:exactMatch": [
+ {"@id": "http://snomed.info/id/38341003", "rdfs:label": "Essential hypertension (SNOMED CT)"},
+ {"@id": "http://id.nlm.nih.gov/mesh/D006973", "rdfs:label": "Hypertension (MeSH)"}
+ ]
+ },
+ "clinical:hasMedication": {
+ "@type": "clinical:Medication",
+ "dcterms:title": "Warfarin",
+ "clinical:dose": "5 mg",
+ "clinical:frequency": "once daily",
+ "skos:exactMatch": [
+ {"@id": "http://purl.bioontology.org/ontology/RXNORM/11289", "rdfs:label": "Warfarin (RxNorm)"},
+ {"@id": "http://fdasis.nlm.nih.gov/srs/unii/5Q7ZVV76EI", "rdfs:label": "Warfarin substance (UNII)"},
+ {"@id": "http://id.nlm.nih.gov/mesh/D014859", "rdfs:label": "Warfarin (MeSH)"}
+ ]
+ },
+ "clinical:hasProvenance": {
+ "@type": "prov:Entity",
+ "prov:wasDerivedFrom": "ICD-10 single-system diagnosis record",
+ "prov:wasGeneratedBy": "open-ontologies onto_enrich + onto_crosswalk",
+ "prov:generatedAtTime": {"@type": "xsd:dateTime", "@value": "2026-05-07T10:00:00"}
+ },
+ "clinical:hasQA": {
+ "@type": "clinical:QARecord",
+ "clinical:validationStatus": "pass",
+ "clinical:codingCompleteness": 1.0,
+ "clinical:terminologySources": ["ICD-10", "SNOMED CT", "MeSH", "RxNorm", "UNII"]
+ }
+ },
+ {
+ "@context": {
+ "clinical": "http://example.org/clinical-records-standard#",
+ "dcterms": "http://purl.org/dc/terms/",
+ "skos": "http://www.w3.org/2004/02/skos/core#",
+ "prov": "http://www.w3.org/ns/prov#",
+ "xsd": "http://www.w3.org/2001/XMLSchema#"
+ },
+ "@type": "clinical:DiagnosisRecord",
+ "@id": "https://example.org/records/diag/0002",
+ "dcterms:title": "Type 2 diabetes mellitus, without complications",
+ "dcterms:date": {"@type": "xsd:date", "@value": "2025-09-14"},
+ "dcterms:description": "T2DM, glycaemic control on oral therapy",
+ "dcterms:relation": "https://example.org/records/diag/0001",
+ "clinical:hasCoding": {
+ "@type": "clinical:Code",
+ "clinical:primaryCode": "E11.9",
+ "clinical:primarySystem": "ICD-10",
+ "skos:exactMatch": [
+ {"@id": "http://snomed.info/id/44054006", "rdfs:label": "Diabetes mellitus type 2 (SNOMED CT)"},
+ {"@id": "http://id.nlm.nih.gov/mesh/D003924", "rdfs:label": "Diabetes Mellitus, Type 2 (MeSH)"}
+ ]
+ },
+ "clinical:hasMedication": {
+ "@type": "clinical:Medication",
+ "dcterms:title": "Metformin hydrochloride",
+ "clinical:dose": "500 mg",
+ "clinical:frequency": "twice daily",
+ "skos:exactMatch": [
+ {"@id": "http://purl.bioontology.org/ontology/RXNORM/6809", "rdfs:label": "Metformin (RxNorm)"},
+ {"@id": "http://fdasis.nlm.nih.gov/srs/unii/9100L32L2N", "rdfs:label": "Metformin substance (UNII)"},
+ {"@id": "http://id.nlm.nih.gov/mesh/D008687", "rdfs:label": "Metformin (MeSH)"}
+ ]
+ },
+ "clinical:hasProvenance": {
+ "@type": "prov:Entity",
+ "prov:wasDerivedFrom": "ICD-10 single-system diagnosis record",
+ "prov:wasGeneratedBy": "open-ontologies onto_enrich + onto_crosswalk",
+ "prov:generatedAtTime": {"@type": "xsd:dateTime", "@value": "2026-05-07T10:00:00"}
+ },
+ "clinical:hasQA": {
+ "@type": "clinical:QARecord",
+ "clinical:validationStatus": "pass",
+ "clinical:codingCompleteness": 1.0,
+ "clinical:terminologySources": ["ICD-10", "SNOMED CT", "MeSH", "RxNorm", "UNII"]
+ }
+ }
+]
diff --git a/examples/medicine-sample-before.json b/examples/medicine-sample-before.json
new file mode 100644
index 00000000..1051aa0a
--- /dev/null
+++ b/examples/medicine-sample-before.json
@@ -0,0 +1,41 @@
+[
+ {
+ "@context": {
+ "clinical": "http://example.org/clinical-records-standard#",
+ "dcterms": "http://purl.org/dc/terms/",
+ "xsd": "http://www.w3.org/2001/XMLSchema#"
+ },
+ "@type": "clinical:DiagnosisRecord",
+ "@id": "I10",
+ "dcterms:title": "Essential hypertension",
+ "dcterms:date": "2025-09-14",
+ "dcterms:description": "Primary hypertension, no secondary cause identified",
+ "clinical:hasCoding": {
+ "@type": "clinical:Code",
+ "clinical:codeValue": "I10",
+ "clinical:codeSystem": "ICD-10"
+ },
+ "clinical:linkedMedication": "warfarin 5mg daily",
+ "_source_note": "Illustrative — modelled on common primary-care diagnosis patterns; not a real patient record."
+ },
+ {
+ "@context": {
+ "clinical": "http://example.org/clinical-records-standard#",
+ "dcterms": "http://purl.org/dc/terms/",
+ "xsd": "http://www.w3.org/2001/XMLSchema#"
+ },
+ "@type": "clinical:DiagnosisRecord",
+ "@id": "E11.9",
+ "dcterms:title": "Type 2 diabetes mellitus, without complications",
+ "dcterms:date": "2025-09-14",
+ "dcterms:description": "T2DM, glycaemic control on oral therapy",
+ "clinical:hasCoding": {
+ "@type": "clinical:Code",
+ "clinical:codeValue": "E11.9",
+ "clinical:codeSystem": "ICD-10"
+ },
+ "clinical:linkedMedication": "metformin 500mg twice daily",
+ "clinical:relatedDiagnosis": "I10",
+ "_source_note": "Illustrative — common comorbidity pattern; not a real patient record."
+ }
+]