Skip to content

Commit 36f1962

Browse files
committed
fix: scope the SPARQL endpoint to the stack's own triplestore
- bare service name "graphdb" also resolves on a shared external network, so multiple stacks on one host round-robin into each other's stores - add project-scoped graphdb/fuseki aliases on the project network - build $smwgSparqlEndpoint from MW_SPARQL_HOST, falling back to "graphdb"
1 parent 5f16c56 commit 36f1962

3 files changed

Lines changed: 26 additions & 3 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Set the config parameters in .env
5353

5454
Example:
5555
```env
56-
COMPOSE_PROJECT_NAME=osl-1 # unique project name (change when running multiple instances)
56+
COMPOSE_PROJECT_NAME=osl-1 # unique project name (must differ per instance: it scopes the triplestore alias)
5757
MW_IMAGE_TAG=main # Docker image tag, see table below
5858
MW_HOST_PORT=8081 # the port mediawiki exposes on the host (localhost only)
5959
MW_SITE_SERVER=http://localhost:8081 # the public URL of your wiki

‎docker-compose.yml‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ services:
2929
# is a region growing on demand, not a limit.
3030
JAVA_XMS: ${MW_GRAPHDB_HEAP_MIN:-512m}
3131
JAVA_XMX: ${MW_GRAPHDB_HEAP:-1g}
32+
networks:
33+
default:
34+
# Every stack's graphdb also answers to the bare name "graphdb"
35+
# on a shared external network, which the resolver prefers over
36+
# the project network first, so "graphdb" can hit another stack's
37+
# store. This alias is project-scoped and cannot be shadowed.
38+
aliases:
39+
- ${COMPOSE_PROJECT_NAME:-osl}-graphdb
3240
volumes:
3341
- ./blazegraph/data:/var/lib/blazegraph
3442
- ./blazegraph/config:/docker-entrypoint-initdb.d
@@ -41,6 +49,11 @@ services:
4149
image: secoresearch/fuseki
4250
profiles: [fuseki]
4351
restart: unless-stopped
52+
networks:
53+
default:
54+
# Same shadowing hazard as graphdb above.
55+
aliases:
56+
- ${COMPOSE_PROJECT_NAME:-osl}-fuseki
4457
volumes:
4558
- './fuseki/data:/fuseki-base/databases'
4659
- './fuseki/config/shiro.ini:/jena-fuseki/shiro.ini' # override config before docker-init
@@ -82,6 +95,8 @@ services:
8295
- ./mediawiki/data:/var/www/html/w/images
8396
environment:
8497
- TZ=${MW_TIME_ZONE}
98+
# Must match the graphdb alias above.
99+
- MW_SPARQL_HOST=${COMPOSE_PROJECT_NAME:-osl}-graphdb
85100
- MW_SITE_SERVER=${MW_SITE_SERVER}
86101
- MW_SITE_NAME=${MW_SITE_NAME}
87102
- MW_SITE_LANG=${MW_SITE_LANG}

‎mediawiki/build/DockerSettings.php‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,16 @@
469469

470470
$smwgDefaultStore = 'SMW\SPARQLStore\SPARQLStore';
471471
$smwgSparqlRepositoryConnector = 'blazegraph';
472-
$smwgSparqlEndpoint["query"] = 'http://graphdb:9999/blazegraph/namespace/kb/sparql';
473-
$smwgSparqlEndpoint["update"] = 'http://graphdb:9999/blazegraph/namespace/kb/sparql';
472+
# Not the bare "graphdb": on a host running several stacks that name also exists
473+
# on the shared external network and resolves there first, round-robin, so SMW
474+
# reads and writes land in another wiki's store. docker-compose.yml sets this to
475+
# a project-scoped alias. Fallback keeps hand-rolled deployments working.
476+
$mwSparqlHost = getenv( 'MW_SPARQL_HOST', true ) ?: getenv( 'MW_SPARQL_HOST' );
477+
if ( !$mwSparqlHost ) {
478+
$mwSparqlHost = 'graphdb';
479+
}
480+
$smwgSparqlEndpoint["query"] = "http://$mwSparqlHost:9999/blazegraph/namespace/kb/sparql";
481+
$smwgSparqlEndpoint["update"] = "http://$mwSparqlHost:9999/blazegraph/namespace/kb/sparql";
474482
$smwgSparqlEndpoint["data"] = '';
475483

476484
# Optional name of default graph

0 commit comments

Comments
 (0)