Skip to content

Commit b3fca1e

Browse files
jmclaude
andcommitted
feat(dev): one-command native-FE local dev (dev.backend.sh + start:dev:local + .nvmrc)
Makes "debuggable/changeable FE against a real backend" two commands: build-scripts/run/dev.backend.sh # DSpace 7.6.5 + demo content at 127.0.0.1:8087, reindexed yarn start:dev:local # ng serve, live-reload on :4000, REST_* env baked in Removes the traps that made this painful: the script pins the 7.6.5 images (FE-matched), uses 127.0.0.1 (Node sends localhost->IPv6; BE is IPv4-only), sets CORS, layers db.entities.yml for sample data, and runs index-discovery with MSYS_NO_PATHCONV. .nvmrc pins Node 18 (the Angular 15 toolchain breaks on newer Node; pairs with the copy-webpack-plugin fix). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> (cherry picked from commit c686c3ce0545387763a02b85212892cbaa2c6b16)
1 parent 4f9034c commit b3fca1e

4 files changed

Lines changed: 93 additions & 16 deletions

File tree

.nvmrc

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

AGENTS.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,27 @@ Builds on PR #1289, which makes `docker/docker-compose-rest.yml` drivable from o
3434

3535
---
3636

37-
## TL;DR
37+
## TL;DR — two commands
3838

3939
```bash
40-
# 1) BACKEND in Docker, WITH demo content (7.6.5 to match the FE) — ~2-4 min first boot
41-
cp docker/.env.local.example docker/.env.local # then edit per "Backend"
42-
docker compose --env-file docker/.env.local \
43-
-f docker/docker-compose-rest.yml -f docker/db.entities.yml up -d
44-
# wait: curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8087/server/api => 200
45-
MSYS_NO_PATHCONV=1 docker exec dspace7 /dspace/bin/dspace index-discovery -b # populate Solr
40+
# 0) one-time: use Node 18 (see .nvmrc) and install deps
41+
nvm use # or: see Prerequisites for a portable Node 18
42+
yarn install
4643

47-
# 2) FRONTEND natively (Node 18 on PATH, copy-webpack-plugin already ^11 + installed)
48-
DSPACE_REST_SSL=false DSPACE_REST_HOST=127.0.0.1 DSPACE_REST_PORT=8087 \
49-
DSPACE_UI_HOST=localhost DSPACE_UI_PORT=4000 \
50-
yarn start:dev # live-reload on http://localhost:4000
44+
# 1) BACKEND: DSpace 7.6.5 + demo content at http://127.0.0.1:8087/server (~2-4 min first run)
45+
build-scripts/run/dev.backend.sh # add 'fresh' to wipe volumes + reload from scratch
5146

52-
# 3) teardown (-v wipes DB/Solr volumes — see Gotcha #4)
53-
docker compose --env-file docker/.env.local \
54-
-f docker/docker-compose-rest.yml -f docker/db.entities.yml down -v --remove-orphans
47+
# 2) FRONTEND: live-reload dev server on http://localhost:4000
48+
yarn start:dev:local
5549
```
5650

57-
The FE maps env vars onto `config/config.yml` (`rest.host``DSPACE_REST_HOST`, … ; env wins
58-
last — see `src/config/config.server.ts`), so no file edits are needed to point it at the BE.
51+
`dev.backend.sh` brings the backend up (correct 7.6.5 images, IPv4 host, CORS, demo dataset)
52+
and reindexes Solr; `start:dev:local` is `ng serve` with the right `DSPACE_REST_*` env baked in.
53+
Stop/wipe the backend with `docker compose -f docker/docker-compose-rest.yml -f docker/db.entities.yml down -v`.
54+
55+
Everything below is the manual/explained version of those two commands (for customizing the
56+
instance, image set, or running the FE in Docker). The FE maps env vars onto `config/config.yml`
57+
(`rest.host``DSPACE_REST_HOST`, … ; env wins last — see `src/config/config.server.ts`).
5958

6059
---
6160

build-scripts/run/dev.backend.sh

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env bash
2+
#
3+
# One-command local-dev BACKEND for working on the native frontend.
4+
#
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:
8+
#
9+
# yarn start:dev:local # ng serve, live-reload, http://localhost:4000 (needs Node 18 — see .nvmrc)
10+
#
11+
# 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)
14+
#
15+
# Notes:
16+
# - 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.
20+
#
21+
set -uo pipefail
22+
cd "$(dirname "$0")/../.." || exit 1
23+
24+
export INSTANCE="${INSTANCE:-7}"
25+
export COMPOSE_PROJECT_NAME="dspace-${INSTANCE}"
26+
export DSPACE_HOST=127.0.0.1
27+
export DSPACE_REST_NAMESPACE=/server
28+
export REST_URL="http://127.0.0.1:808${INSTANCE}/server"
29+
export UI_URL="http://localhost:4000"
30+
export HOST_IP=127.0.0.1
31+
export 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
38+
39+
COMPOSE=(docker compose -f docker/docker-compose-rest.yml -f docker/db.entities.yml)
40+
REST="http://127.0.0.1:808${INSTANCE}/server/api"
41+
42+
if [ "${1:-}" = "fresh" ]; then
43+
echo ">> wiping previous dev backend (down -v)"
44+
"${COMPOSE[@]}" down -v --remove-orphans || true
45+
fi
46+
47+
echo ">> starting backend: DSpace 7.6.5 + demo entities (project ${COMPOSE_PROJECT_NAME})"
48+
if ! "${COMPOSE[@]}" up -d; then
49+
echo "!! 'up' failed. If it's a Postgres version/volume mismatch, run: $0 fresh" >&2
50+
exit 1
51+
fi
52+
53+
echo -n ">> waiting for REST API (${REST}) "
54+
for _ in $(seq 1 90); do
55+
[ "$(curl -s -o /dev/null -w '%{http_code}' "$REST" 2>/dev/null)" = "200" ] && { echo " ready"; break; }
56+
printf '.'; sleep 5
57+
done
58+
if [ "$(curl -s -o /dev/null -w '%{http_code}' "$REST" 2>/dev/null)" != "200" ]; then
59+
echo " timed out. Check: ${COMPOSE[*]} logs dspace${INSTANCE}" >&2
60+
exit 1
61+
fi
62+
63+
echo ">> indexing Solr discovery (so browse/search/What's New populate)"
64+
# MSYS_NO_PATHCONV stops Git Bash from rewriting /dspace/... into a Windows path.
65+
MSYS_NO_PATHCONV=1 docker exec "dspace${INSTANCE}" /dspace/bin/dspace index-discovery -b \
66+
|| echo " (reindex failed — rerun: MSYS_NO_PATHCONV=1 docker exec dspace${INSTANCE} /dspace/bin/dspace index-discovery -b)"
67+
68+
cat <<MSG
69+
70+
==================================================================
71+
Backend ready: ${REST%/api} (DSpace 7.6.5, demo content)
72+
Start the FE : yarn start:dev:local (Node 18 — see .nvmrc)
73+
Then open : http://localhost:4000/
74+
Stop / wipe : ${COMPOSE[*]} down -v
75+
==================================================================
76+
MSG

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"test:rest": "ts-node --project ./tsconfig.ts-node.json scripts/test-rest.ts",
88
"start": "yarn run start:prod",
99
"start:dev": "nodemon --exec \"cross-env NODE_ENV=development yarn run serve\"",
10+
"start:dev:local": "cross-env DSPACE_REST_SSL=false DSPACE_REST_HOST=127.0.0.1 DSPACE_REST_PORT=8087 DSPACE_UI_HOST=localhost DSPACE_UI_PORT=4000 yarn run start:dev",
1011
"start:prod": "yarn run build:prod && cross-env NODE_ENV=production yarn run serve:ssr",
1112
"start:mirador:prod": "yarn run build:mirador && yarn run start:prod",
1213
"preserve": "yarn base-href",

0 commit comments

Comments
 (0)