Skip to content

Commit

Permalink
Use Apache Jena Fuseki docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
kinow committed Aug 1, 2023
1 parent 136f6ed commit 39f45d4
Show file tree
Hide file tree
Showing 8 changed files with 425 additions and 74 deletions.
26 changes: 17 additions & 9 deletions dockerfiles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,27 @@ without Docker Compose, you can try the following command before loading your
vocabulary data. It starts a container in the same way our other example with
the `docker-compose` command.

docker run --name fuseki -ti --rm \
--env "ADMIN_PASSWORD=admin" --env "JVM_ARGS=-Xmx2g" \
-p 3030:3030 \
--mount type=bind,src=$(pwd)/config/skosmos.ttl,dst=/fuseki/configuration/skosmos.ttl \
stain/jena-fuseki
export JENA_4_VERSION=4.8.0

docker build -t jena-fuseki:$JENA_4_VERSION \
--build-arg JENA_VERSION=$JENA_4_VERSION \
--no-cache dockerfiles/jena-fuseki2-docker

docker run --name fuseki --rm -ti \
-v $(pwd)/config/skosmos.ttl:/fuseki/skosmos.ttl \
-e "JAVA_OPTIONS=-Xmx2g -Xms1g" \
-p 3030:3030 \
jena-fuseki:$JENA_4_VERSION \
--config=/fuseki/skosmos.ttl

curl -XPOST http://localhost:3030/skosmos/query -d "query=SELECT ?a WHERE { ?a ?b ?c }"

## Running with docker-compose

The `docker-compose` provided configuration will prepare three containers.
The first one called `skosmos-fuseki`, which uses the `stain/jena-fuseki`
image for Jena, and starts a container with 2 GB of memory and `admin` as
the user and password. The `docker-compose` service name of this container
is `fuseki`.
The first one called `skosmos-fuseki`, which uses the Apache Jena
image for Fuseki, and starts a container with 2 GB of memory. The
`docker-compose` service name of this container is `fuseki`.

The second container is the `fuseki-cache`, a Varnish Cache container. It sits
between the `skosmos-fuseki` and the `skosmos-web` (more on this below). The
Expand Down
92 changes: 40 additions & 52 deletions dockerfiles/config/skosmos.ttl
Original file line number Diff line number Diff line change
@@ -1,85 +1,73 @@
@prefix : <http://base/#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix tdb2: <http://jena.apache.org/2016/tdb#> .
@prefix ja: <http://jena.hpl.hp.com/2005/11/Assembler#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix fuseki: <http://jena.apache.org/fuseki#> .
@prefix tdb2: <http://jena.apache.org/2016/tdb#> .
@prefix text: <http://jena.apache.org/text#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix fuseki: <http://jena.apache.org/fuseki#> .

ja:DatasetTxnMem rdfs:subClassOf ja:RDFDataset .
ja:MemoryDataset rdfs:subClassOf ja:RDFDataset .
ja:RDFDatasetOne rdfs:subClassOf ja:RDFDataset .
ja:RDFDatasetSink rdfs:subClassOf ja:RDFDataset .
ja:RDFDatasetZero rdfs:subClassOf ja:RDFDataset .

tdb2:DatasetTDB rdfs:subClassOf ja:RDFDataset .
tdb2:DatasetTDB2 rdfs:subClassOf ja:RDFDataset .

tdb2:GraphTDB rdfs:subClassOf ja:Model .
tdb2:GraphTDB2 rdfs:subClassOf ja:Model .

<http://jena.hpl.hp.com/2008/tdb#DatasetTDB>
rdfs:subClassOf ja:RDFDataset .

<http://jena.hpl.hp.com/2008/tdb#GraphTDB>
rdfs:subClassOf ja:Model .

text:TextDataset
rdfs:subClassOf ja:RDFDataset .
[] rdf:type fuseki:Server ;
fuseki:services (
:skosmos_service
)
.

:service_tdb_all a fuseki:Service ;
rdfs:label "TDB2+text skosmos" ;
fuseki:dataset :text_dataset ;
fuseki:name "skosmos" ;
fuseki:serviceQuery "query" , "" , "sparql" ;
fuseki:serviceReadGraphStore "get" ;
fuseki:serviceReadQuads "" ;
:skosmos_service rdf:type fuseki:Service ;
rdfs:label "TDB2+text skosmos" ;
fuseki:name "skosmos" ;
fuseki:serviceQuery "query" , "" , "sparql" ;
fuseki:serviceReadGraphStore "get" ;
fuseki:serviceReadQuads "" ;
fuseki:serviceReadWriteGraphStore "data" ;
fuseki:serviceReadWriteQuads "" ;
fuseki:serviceUpdate "" , "update" ;
fuseki:serviceUpload "upload" .
fuseki:serviceReadWriteQuads "" ;
fuseki:serviceUpdate "" , "update" ;
fuseki:serviceUpload "upload" ;
fuseki:dataset :text_dataset
.

:text_dataset a text:TextDataset ;
text:dataset :tdb_dataset_readwrite ;
text:index :index_lucene .
:text_dataset rdf:type text:TextDataset ;
text:dataset :tdb_dataset_readwrite ;
text:index <#indexLucene>
.

:tdb_dataset_readwrite
a tdb2:DatasetTDB2 ;
# tdb2:unionDefaultGraph true ;
tdb2:location "/fuseki/databases/skosmos" .
:tdb_dataset_readwrite rdf:type tdb2:DatasetTDB2 ;
tdb2:location "/fuseki/databases/skosmos" ;
# tdb2:unionDefaultGraph true ;
.

:index_lucene a text:TextIndexLucene ;
text:directory <file:/fuseki/databases/skosmos/text> ;
text:entityMap :entity_map ;
text:storeValues true .
<#indexLucene> rdf:type text:TextIndexLucene ;
text:directory <file:/fuseki/databases/skosmos/text> ;
text:entityMap <#entMap> ;
text:storeValues true
.

# Text index configuration for Skosmos
:entity_map a text:EntityMap ;
text:entityField "uri" ;
text:graphField "graph" ;
<#entMap> rdf:type text:EntityMap ;
text:defaultField "pref" ;
text:entityField "uri" ;
text:uidField "uid" ;
text:langField "lang" ;
text:graphField "graph" ;
text:map (
# skos:prefLabel
[ text:field "pref" ;
text:predicate skos:prefLabel ;
text:analyzer [ a text:LowerCaseKeywordAnalyzer ]
text:analyzer [ rdf:type text:LowerCaseKeywordAnalyzer ]
]
# skos:altLabel
[ text:field "alt" ;
text:predicate skos:altLabel ;
text:analyzer [ a text:LowerCaseKeywordAnalyzer ]
text:analyzer [ rdf:type text:LowerCaseKeywordAnalyzer ]
]
# skos:hiddenLabel
[ text:field "hidden" ;
text:predicate skos:hiddenLabel ;
text:analyzer [ a text:LowerCaseKeywordAnalyzer ]
text:analyzer [ rdf:type text:LowerCaseKeywordAnalyzer ]
]
# skos:notation
[ text:field "notation" ;
text:predicate skos:notation ;
text:analyzer [ a text:LowerCaseKeywordAnalyzer ]
text:analyzer [ rdf:type text:LowerCaseKeywordAnalyzer ]
]
) .
)
.
31 changes: 18 additions & 13 deletions dockerfiles/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,31 @@ services:
fuseki:
container_name: skosmos-fuseki
hostname: fuseki
image: stain/jena-fuseki
build:
context: ../dockerfiles/jena-fuseki2-docker
dockerfile: Dockerfile
args:
JENA_VERSION: 4.8.0
command: --config=/fuseki/skosmos.ttl
environment:
- ADMIN_PASSWORD=admin
- JVM_ARGS=-Xmx2g
- JAVA_OPTIONS=-Xmx2g -Xms1g
ports:
- 9030:3030
# You can uncomment the line below to have a local volume bound onto the container, or
# visit https://hub.docker.com/r/stain/jena-fuseki/ for other alternatives
# volumes:
# - ${PWD}/fuseki:/fuseki
- '9030:3030'
volumes:
- type: bind
source: ./config/skosmos.ttl
target: /fuseki/configuration/skosmos.ttl
# You can uncomment the lines below to persist data used in the
# container. For more complete documentation about it, please
# consult the official Apache Jena docs at
# https://github.com/apache/jena/tree/main/jena-fuseki2/jena-fuseki-docker
# - ./databases:/fuseki/databases
# - ./logs:/fuseki/logs
- ./config/skosmos.ttl:/fuseki/skosmos.ttl
user: 'fuseki:fuseki'
fuseki-cache:
container_name: skosmos-fuseki-cache
hostname: fuseki-cache
image: varnish
ports:
- 9031:80
- '9031:80'
volumes:
- type: bind
source: ./config/varnish-default.vcl
Expand All @@ -35,7 +40,7 @@ services:
context: ..
dockerfile: dockerfiles/Dockerfile.ubuntu
ports:
- 9090:80
- '9090:80'
depends_on:
- fuseki
- fuseki-cache
Expand Down
124 changes: 124 additions & 0 deletions dockerfiles/jena-fuseki2-docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.

## Apache Jena Fuseki server Dockerfile.

## This Dockefile builds a reduced footprint container.

ARG JAVA_VERSION=17

ARG ALPINE_VERSION=3.17.1
ARG JENA_VERSION=""

# Internal, passed between stages.
ARG FUSEKI_DIR=/fuseki
ARG FUSEKI_JAR=jena-fuseki-server-${JENA_VERSION}.jar
ARG JAVA_MINIMAL=/opt/java-minimal

## ---- Stage: Download and build java.
FROM eclipse-temurin:${JAVA_VERSION}-alpine AS base

ARG JAVA_MINIMAL
ARG JENA_VERSION
ARG FUSEKI_DIR
ARG FUSEKI_JAR
ARG REPO=https://repo1.maven.org/maven2
ARG JAR_URL=${REPO}/org/apache/jena/jena-fuseki-server/${JENA_VERSION}/${FUSEKI_JAR}

RUN [ "${JENA_VERSION}" != "" ] || { echo -e '\n**** Set JENA_VERSION ****\n' ; exit 1 ; }
RUN echo && echo "==== Docker build for Apache Jena Fuseki ${JENA_VERSION} ====" && echo

# Alpine: For objcopy used in jlink
RUN apk add --no-cache curl binutils

## -- Fuseki installed and runs in /fuseki.
WORKDIR $FUSEKI_DIR

## -- Download the jar file.
COPY download.sh .
RUN chmod a+x download.sh

# Download, with check of the SHA1 checksum.
RUN ./download.sh --chksum sha1 "$JAR_URL"

## -- Alternatives to download : copy already downloaded.
## COPY ${FUSEKI_JAR} .

## Use Docker ADD - does not retry, does not check checksum, and may run every build.
## ADD "$JAR_URL"

## -- Make reduced Java JDK

ARG JDEPS_EXTRA="jdk.crypto.cryptoki,jdk.crypto.ec"
RUN \
JDEPS="$(jdeps --multi-release base --print-module-deps --ignore-missing-deps ${FUSEKI_JAR})" && \
jlink \
--compress 2 --strip-debug --no-header-files --no-man-pages \
--output "${JAVA_MINIMAL}" \
--add-modules "${JDEPS},${JDEPS_EXTRA}"

ADD entrypoint.sh .
ADD log4j2.properties .

## ---- Stage: Build runtime
FROM alpine:${ALPINE_VERSION}

## Import ARGs
ARG JENA_VERSION
ARG JAVA_MINIMAL
ARG FUSEKI_DIR
ARG FUSEKI_JAR

COPY --from=base /opt/java-minimal /opt/java-minimal
COPY --from=base /fuseki /fuseki

WORKDIR $FUSEKI_DIR

ARG LOGS=${FUSEKI_DIR}/logs
ARG DATA=${FUSEKI_DIR}/databases

ARG JENA_USER=fuseki
ARG JENA_GROUP=$JENA_USER
ARG JENA_GID=1000
ARG JENA_UID=1000

# Run as this user
# -H : no home directory
# -D : no password
RUN addgroup -g "${JENA_GID}" "${JENA_GROUP}" && \
adduser "${JENA_USER}" -G "${JENA_GROUP}" -s /bin/ash -u "${JENA_UID}" -H -D

RUN mkdir --parents "${FUSEKI_DIR}" && \
chown -R $JENA_USER ${FUSEKI_DIR}

USER $JENA_USER

RUN \
mkdir -p $LOGS && \
mkdir -p $DATA && \
chmod a+x entrypoint.sh

## Default environment variables.
ENV \
JAVA_HOME=${JAVA_MINIMAL} \
JAVA_OPTIONS="-Xmx2048m -Xms2048m" \
JENA_VERSION=${JENA_VERSION} \
FUSEKI_JAR="${FUSEKI_JAR}" \
FUSEKI_DIR="${FUSEKI_DIR}"

EXPOSE 3030

ENTRYPOINT ["./entrypoint.sh" ]
CMD []
1 change: 1 addition & 0 deletions dockerfiles/jena-fuseki2-docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Commit: 26153afe9a229bb7a609d5406d899eb240ab385e
Loading

0 comments on commit 39f45d4

Please sign in to comment.