Skip to content

Commit 37395fe

Browse files
authored
Merge pull request #6 from internetofwater/addOntologyLoaderContainer
Add Loader Container for Ontologies
2 parents aea3314 + 7a8f649 commit 37395fe

8 files changed

Lines changed: 151 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2025 Lincoln Institute of Land Policy
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
name: Push Loader Image To GHCR
5+
6+
on:
7+
push:
8+
branches: [main]
9+
workflow_dispatch:
10+
11+
concurrency:
12+
group:
13+
${{ github.workflow }}-${{ github.ref_name }}-${{
14+
github.event.pull_request.number || github.sha }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
build_and_push:
19+
name: "build and push geoconnex ontology loader image"
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v3
26+
27+
- name: Login to GitHub Container Registry
28+
uses: docker/login-action@v3
29+
with:
30+
registry: ghcr.io
31+
username: ${{ github.actor }}
32+
password: ${{ secrets.GITHUB_TOKEN }}
33+
34+
- name: Build and export
35+
uses: docker/build-push-action@v6
36+
with:
37+
context: .
38+
file: Dockerfile
39+
push: true
40+
tags: ghcr.io/internetofwater/geoconnex_ontology_loader:latest
41+
cache-from: type=gha,scope=geoconnex_ontology_loader
42+
platforms: linux/amd64
43+
cache-to: type=gha,mode=max,scope=geoconnex_ontology_loader

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.venv

Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2026 Lincoln Institute of Land Policy
2+
# SPDX-License-Identifier: MIT
3+
4+
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
5+
6+
WORKDIR /app
7+
8+
ENV UV_COMPILE_BYTECODE=1
9+
ENV UV_LINK_MODE=copy
10+
ENV UV_NO_DEV=1
11+
12+
COPY ./loader/pyproject.toml ./loader/uv.lock ./
13+
14+
RUN --mount=type=cache,target=/root/.cache/uv \
15+
uv sync --locked --no-install-project
16+
17+
COPY ./loader/ ./
18+
COPY ./*.ttl ./
19+
20+
RUN --mount=type=cache,target=/root/.cache/uv \
21+
uv sync --locked
22+
23+
ENV PATH="/app/.venv/bin:$PATH"
24+
25+
ENTRYPOINT []
26+
27+
CMD ["python", "/app/main.py"]

loader/.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12

loader/README.md

Whitespace-only changes.

loader/main.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import json
2+
from pathlib import Path
3+
4+
from rdflib import Graph
5+
6+
# trivial script to convert ttl to json-ld and write it to stdout
7+
# so that the geoconnex pipeline can consume it like a normal integration
8+
9+
def main():
10+
current_dir = Path(__file__).parent
11+
12+
ttl_files = list(current_dir.glob("*.ttl"))
13+
if not ttl_files:
14+
raise Exception(f"No ttl files found in {current_dir}")
15+
16+
for ttl_file in ttl_files:
17+
graph = Graph()
18+
graph.parse(ttl_file, format="turtle")
19+
20+
# Serialize to JSON-LD
21+
jsonld = graph.serialize(format="json-ld")
22+
23+
# Re-encode as compact one-line JSON
24+
# this is since rdflib doesn't support writing compact JSON
25+
# as far as I can tell
26+
compact = json.dumps(
27+
json.loads(jsonld),
28+
separators=(",", ":"),
29+
)
30+
31+
print(compact)
32+
33+
34+
if __name__ == "__main__":
35+
main()

loader/pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[project]
2+
name = "loader"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.12"
7+
dependencies = [
8+
"rdflib>=7.6.0",
9+
]

loader/uv.lock

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)