diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..5359d26 --- /dev/null +++ b/.env.example @@ -0,0 +1,11 @@ +# Copy to .env and adjust. + +# DSpace backend REST API base (…/server). The backend must have +# handle.remote-resolver.enabled = true. +# - backend on the same host: http://host.docker.internal:8082/server +# - backend reachable by hostname: http://dspace.example.org/server +DSPACE_HANDLE_ENDPOINT=http://host.docker.internal:8082/server + +# Host ports to publish (change if they clash with something else). +HANDLE_HTTP_PORT=8000 +HANDLE_NATIVE_PORT=2641 diff --git a/.gitattributes b/.gitattributes index 8218efd..be1ecf2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,5 @@ -*.sh eol=lf \ No newline at end of file +*.sh eol=lf +# Handle.Net launcher scripts have NO extension, so `*.sh eol=lf` misses them. +# Force LF or the shebang breaks when the image is built from a Windows clone. +assets/handle-9.3.1/bin/hdl text eol=lf +assets/handle-9.3.1/bin/hdl-* text eol=lf diff --git a/Readme.md b/Readme.md index f046e7e..d855dfd 100644 --- a/Readme.md +++ b/Readme.md @@ -5,6 +5,37 @@ Dockerized https://github.com/DSpace/Remote-Handle-Resolver. +The Handle server runs as a **standalone service** and resolves handles through +the DSpace backend REST API — it does not connect to the database itself: + +``` +client -> handle-server(:8000) --HTTP /server/resolve--> DSpace backend --> database +``` + +## Quick start (docker compose) + +Clone & run — the container points the resolver plugin at your backend, waits +for it, and starts the Handle server: + +``` +git clone --recurse-submodules https://github.com/dataquest-dev/docker-handle-server.git +cd docker-handle-server +cp .env.example .env # set DSPACE_HANDLE_ENDPOINT to your backend (…/server) +docker compose up -d +``` + +Requirements on the backend side: + +``` +handle.remote-resolver.enabled = true +``` + +Test a resolve once it is up (use a handle that exists in your repository): + +``` +curl http://localhost:8000/api/handles/123456789/0 +``` + ## Installation 1. Generate your own configuration by running: diff --git a/assets/config/config.dct b/assets/config/config.dct index 077db58..9ad6227 100644 --- a/assets/config/config.dct +++ b/assets/config/config.dct @@ -34,6 +34,9 @@ ) "server_config" = { + "storage_type" = "CUSTOM" + "storage_class" = "org.dspace.handle.MultiRemoteDSpaceRepositoryHandlePlugin" + "server_admins" = ( "300:0.NA/YOUR_PREFIX" ) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a68f71e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,47 @@ +# Clone & run: a SEPARATE DSpace Handle server. +# +# git clone --recurse-submodules +# cp .env.example .env # set DSPACE_HANDLE_ENDPOINT to your backend +# docker compose up -d +# +# The Handle server resolves via the DSpace backend's remote-resolver +# endpoints (the backend must have `handle.remote-resolver.enabled = true`). +# It does NOT connect to the database itself. +# +# client -> handle-server(:8000) --HTTP--> DSpace backend --> database +# +services: + handle-server: + build: + context: . + dockerfile: Dockerfile + image: docker-handle-server:local + container_name: handle-server + restart: unless-stopped + environment: + # Where the DSpace backend REST API lives (…/server). + # Default assumes a backend published on the host at :8082. + DSPACE_HANDLE_ENDPOINT: ${DSPACE_HANDLE_ENDPOINT:-http://host.docker.internal:8082/server} + extra_hosts: + # lets the container reach a backend running on the host + - "host.docker.internal:host-gateway" + ports: + - "${HANDLE_HTTP_PORT:-8000}:8000" # HTTP resolver + - "${HANDLE_NATIVE_PORT:-2641}:2641/tcp" # native Handle protocol + - "${HANDLE_NATIVE_PORT:-2641}:2641/udp" + entrypoint: + - /bin/sh + - -c + - | + # 1) point the resolver plugin at the backend + echo "dspace.handle.endpoint1 = $$DSPACE_HANDLE_ENDPOINT" > /app/config/handle-dspace-plugin.cfg + echo "Backend endpoint: $$DSPACE_HANDLE_ENDPOINT" + # 2) wait for the backend (the plugin loads the prefix list on startup + # and aborts if the backend is unreachable) + until wget -q -O- "$$DSPACE_HANDLE_ENDPOINT/listprefixes" >/dev/null 2>&1; do + echo " waiting for backend $$DSPACE_HANDLE_ENDPOINT ..."; + sleep 5; + done + echo "Backend is up. Starting Handle server." + # 3) run the Handle server + exec /app/hs/bin/hdl-server /app/config/