|
| 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 |
0 commit comments