22#
33# One-command local-dev BACKEND for working on the native frontend.
44#
5- # Brings up a DSpace 7.6.5 backend (matching this FE's version) in Docker , loaded with the
6- # official demo entities dataset, reachable at http://127.0.0.1:8087/server, then indexes Solr
7- # so browse/search/"What's New" are populated. After it prints "Backend ready", start the FE:
5+ # Brings up a DSpace backend in Docker (matching this FE) , loaded with a sample dataset, reachable at
6+ # http://127.0.0.1:8087/server, then indexes Solr so browse/search/"What's New" populate. After it
7+ # prints "Backend ready", start the FE:
88#
99# yarn start:dev:local # ng serve, live-reload, http://localhost:4000 (needs Node 18 — see .nvmrc)
1010#
11+ # The backend IMAGE is recognised AUTOMATICALLY rather than hardcoded here:
12+ # * image tags are read from the repo's own compose files (the source of truth, so they can't go
13+ # stale against a copy in this script), and
14+ # * after boot the script recognises the running backend's version + flavor and warns if it does
15+ # not match this FE (the DSpace-7.5 "browse definitions" trap).
16+ #
17+ # FLAVOR selects WHICH backend (override: FLAVOR=clarin ...):
18+ # upstream (default) public DSpace demo — DSpace 7.6.x + the official demo dataset (db.entities.yml).
19+ # Right VERSION for this FE and zero dataquest pull, but UPSTREAM flavor: CLARIN-specific
20+ # endpoints/config/content are absent (some FE calls 404 — harmless to render).
21+ # clarin the version-correct CLARIN/dataquest backend — the image DSpace CI validates
22+ # (dataquest/dspace:dspace-7_x-test, read from docker/docker-compose-ci.yml) + the CLARIN
23+ # test dataset (docker/db.clarin.yml). This is the "correct backend" for CLARIN feature
24+ # work. NOTE: first run pulls ~1-2 GB of dataquest images.
25+ #
1126# Usage:
12- # build-scripts/run/dev.backend.sh # up (reuses existing containers/data)
13- # build-scripts/run/dev.backend.sh fresh # wipe DB/Solr volumes first, then up (clean slate)
27+ # build-scripts/run/dev.backend.sh # up (reuses existing containers/data)
28+ # build-scripts/run/dev.backend.sh fresh # wipe DB/Solr volumes first (REQUIRED to switch FLAVOR)
29+ # FLAVOR=clarin build-scripts/run/dev.backend.sh fresh
1430#
1531# Notes:
1632# - 127.0.0.1 (not localhost): Node resolves localhost to IPv6 ::1, but the BE binds IPv4 only.
17- # - Demo data is UPSTREAM DSpace (not CLARIN), so some CLARIN-specific FE calls 404 — harmless.
18- # For CLARIN content, point DSPACE_REST_IMAGE at dataquest/dspace:dspace-7_x and restore a
19- # dataquest/LINDAT DB dump instead of using db.entities.yml.
33+ # - -loadsql images import only into an EMPTY pgdata volume, so always `fresh` when switching FLAVOR.
2034#
2135set -uo pipefail
2236cd " $( dirname " $0 " ) /../.." || exit 1
@@ -26,25 +40,77 @@ export COMPOSE_PROJECT_NAME="dspace-${INSTANCE}"
2640export DSPACE_HOST=127.0.0.1
2741export DSPACE_REST_NAMESPACE=/server
2842export REST_URL=" http://127.0.0.1:808${INSTANCE} /server"
29- export UI_URL=" http://localhost:4000"
43+ # FE dev-server port; CORS is derived from it so the two can never drift (set UI_PORT to change both).
44+ export UI_PORT=" ${UI_PORT:- 4000} "
45+ export UI_URL=" http://localhost:${UI_PORT} "
3046export HOST_IP=127.0.0.1
3147export DSPACE_SUBNET_PREFIX=" 10.10${INSTANCE} "
32- export REST_CORS_ALLOWED_ORIGINS=" http://localhost:4000,http://127.0.0.1:4000"
33- # DSpace 7.6.5 to match the FE; upstream images + the demo entities dataset (db.entities.yml).
34- export DSPACE_REST_IMAGE=dspace/dspace:dspace-7_x
35- export DSPACE_DB_IMAGE=dspace/dspace-postgres-pgcrypto:dspace-7_x
36- export DSPACE_SOLR_IMAGE=dspace/dspace-solr:dspace-7_x
37- export DOCKER_REGISTRY=docker.io DOCKER_OWNER=dspace DSPACE_VER=dspace-7_x
48+ export REST_CORS_ALLOWED_ORIGINS=" http://localhost:${UI_PORT} ,http://127.0.0.1:${UI_PORT} "
49+ export DSPACE_VER=" ${DSPACE_VER:- dspace-7_x} "
50+ export DOCKER_REGISTRY=" ${DOCKER_REGISTRY:- docker.io} "
3851
39- COMPOSE=(docker compose -f docker/docker-compose-rest.yml -f docker/db.entities.yml)
52+ REST_YML=docker/docker-compose-rest.yml
53+ CI_YML=docker/docker-compose-ci.yml
4054REST=" http://127.0.0.1:808${INSTANCE} /server/api"
4155
56+ # Read the default value of a compose `${VAR:-default}` straight from the file (source of truth).
57+ compose_default () { grep -oE " \\\$\\ {$1 :-[^}]+\\ }" " $2 " | head -1 | sed -E ' s/^.*:-//; s/}$//' ; }
58+
59+ # --- recognise WHICH backend image to use (by FLAVOR); tags come FROM THE REPO, not hardcoded here ---
60+ FLAVOR=" ${FLAVOR:- upstream} "
61+ if [ " $FLAVOR " = " clarin" ]; then
62+ # Version-correct CLARIN REST image = the default DSpace CI runs against (docker-compose-ci.yml).
63+ # Deliberately NOT the rest.yml default (dataquest/dspace:dtq-dev-7.5 is DSpace 7.5, which breaks
64+ # browse-definitions against this 7.6.x FE — see the recognise step below and AGENTS.md Gotcha #6).
65+ export DSPACE_REST_IMAGE=" ${DSPACE_REST_IMAGE:- $(compose_default DSPACE_CI_IMAGE " $CI_YML " )} "
66+ export DSPACE_SOLR_IMAGE=" ${DSPACE_SOLR_IMAGE:- $(compose_default DSPACE_SOLR_IMAGE " $REST_YML " )} "
67+ export DOCKER_OWNER=" ${DOCKER_OWNER:- dataquest} "
68+ COMPOSE=(docker compose -f " $REST_YML " -f docker/db.clarin.yml)
69+ else
70+ # Upstream public demo: right version family (7.6.x) + the official demo dataset (db.entities.yml).
71+ export DSPACE_REST_IMAGE=" ${DSPACE_REST_IMAGE:- dspace/ dspace: dspace-7_x} "
72+ export DSPACE_SOLR_IMAGE=" ${DSPACE_SOLR_IMAGE:- dspace/ dspace-solr: dspace-7_x} "
73+ export DOCKER_OWNER=" ${DOCKER_OWNER:- dspace} "
74+ COMPOSE=(docker compose -f " $REST_YML " -f docker/db.entities.yml)
75+ fi
76+ echo " >> FLAVOR=${FLAVOR} DSPACE_REST_IMAGE=${DSPACE_REST_IMAGE} "
77+
78+ # Recognise the RUNNING backend (whoever/whatever started it) and warn if it won't match this FE.
79+ recognise_backend () {
80+ local img ver fe browse flavor compat
81+ img=" $( docker inspect " dspace${INSTANCE} " --format ' {{.Config.Image}}' 2> /dev/null || true) "
82+ ver=" $( curl -s " $REST " | sed -nE ' s/.*"dspaceVersion" *: *"([^"]+)".*/\1/p' | head -1) "
83+ fe=" $( sed -nE ' s/.*"version": *"([0-9][^"]*)".*/\1/p' package.json | head -1) "
84+ browse=" $( curl -s -o /dev/null -w ' %{http_code}' " $REST /discover/browses" 2> /dev/null) "
85+ case " $img " in
86+ dataquest/* ) flavor=" CLARIN (dataquest)" ;;
87+ dspace/* ) flavor=" upstream demo (CLARIN endpoints/content ABSENT)" ;;
88+ * ) flavor=" unknown (${img:- ?} )" ;;
89+ esac
90+ [ " $browse " = " 200" ] && compat=" OK" || compat=" MISMATCH — looks like a DSpace 7.5 backend"
91+ echo " ------------------------------------------------------------------"
92+ echo " Backend recognised:"
93+ echo " image : ${img:- ?} "
94+ echo " version : ${ver:- ?} (this FE is ${fe:- 7.6.x} )"
95+ echo " flavor : ${flavor} "
96+ echo " browse-definitions canary : HTTP ${browse} (${compat} )"
97+ case " $ver " in
98+ ' DSpace 7.6' * |' DSpace 7.7' * |' DSpace 8' * ) ;;
99+ * ) echo " !! BE version may not match the FE; if the canary is not 200, use a 7.6.x image." >&2 ;;
100+ esac
101+ if [ " $FLAVOR " != " clarin" ] && [ " ${img# dspace/ } " != " $img " ]; then
102+ echo " note: for the CORRECT CLARIN backend (CLARIN endpoints + content) run:"
103+ echo " FLAVOR=clarin $0 fresh"
104+ fi
105+ echo " ------------------------------------------------------------------"
106+ }
107+
42108if [ " ${1:- } " = " fresh" ]; then
43109 echo " >> wiping previous dev backend (down -v)"
44110 " ${COMPOSE[@]} " down -v --remove-orphans || true
45111fi
46112
47- echo " >> starting backend: DSpace 7.6.5 + demo entities (project ${COMPOSE_PROJECT_NAME} )"
113+ echo " >> starting backend (project ${COMPOSE_PROJECT_NAME} , flavor ${FLAVOR } )"
48114if ! " ${COMPOSE[@]} " up -d; then
49115 echo " !! 'up' failed. If it's a Postgres version/volume mismatch, run: $0 fresh" >&2
50116 exit 1
@@ -65,12 +131,14 @@ echo ">> indexing Solr discovery (so browse/search/What's New populate)"
65131MSYS_NO_PATHCONV=1 docker exec " dspace${INSTANCE} " /dspace/bin/dspace index-discovery -b \
66132 || echo " (reindex failed — rerun: MSYS_NO_PATHCONV=1 docker exec dspace${INSTANCE} /dspace/bin/dspace index-discovery -b)"
67133
134+ recognise_backend
135+
68136cat << MSG
69137
70138==================================================================
71- Backend ready: ${REST%/ api} (DSpace 7.6.5, demo content )
139+ Backend ready: ${REST%/ api} (flavor: ${FLAVOR} )
72140 Start the FE : yarn start:dev:local (Node 18 — see .nvmrc)
73- Then open : http://localhost:4000 /
141+ Then open : ${UI_URL} /
74142 Stop / wipe : ${COMPOSE[*]} down -v
75143==================================================================
76144MSG
0 commit comments