Skip to content

Commit

Permalink
Working Dockerfile
Browse files Browse the repository at this point in the history
david-habgood committed Mar 9, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 9e7e661 commit d644a97
Showing 9 changed files with 432 additions and 0 deletions.
99 changes: 99 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# 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.


FROM openjdk:11-jre-slim-buster
#MAINTAINER Stian Soiland-Reyes <[email protected]>

ENV LANG C.UTF-8
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
bash curl ca-certificates findutils coreutils gettext pwgen procps tini \
; \
rm -rf /var/lib/apt/lists/*

ARG FUSEKI_JAR=jena-fuseki-geosparql-4.5.0-SNAPSHOT.jar
COPY dggs-jar/current/${FUSEKI_JAR} .
ADD output/dataset_dggs_level_7.ttl .

# Update below according to https://jena.apache.org/download/
# and checksum for apache-jena-fuseki-4.x.x.tar.gz.sha512
#ENV FUSEKI_SHA512 c0b9ab61a57f2c0e027f9d1a07710a22e672eb87730a6460b0869f6a6997a2628703bd99b1590bccd38bdc2a0f78d7be17890b4b88f65ef5518c882c8736a6b3
#ENV FUSEKI_VERSION 4.0.0
# No need for https due to sha512 checksums below
#ENV ASF_MIRROR http://www.apache.org/dyn/mirrors/mirrors.cgi?action=download&filename=
#ENV ASF_ARCHIVE http://archive.apache.org/dist/

#LABEL org.opencontainers.image.url https://github.com/stain/jena-docker/tree/master/jena-fuseki
#LABEL org.opencontainers.image.source https://github.com/stain/jena-docker/
#LABEL org.opencontainers.image.documentation https://jena.apache.org/documentation/fuseki2/
#LABEL org.opencontainers.image.title "Apache Jena Fuseki"
#LABEL org.opencontainers.image.description "Fuseki is a SPARQL 1.1 server with a web interface, backed by the Apache Jena TDB RDF triple store."
#LABEL org.opencontainers.image.version ${FUSEKI_VERSION}
#LABEL org.opencontainers.image.licenses "(Apache-2.0 AND (GPL-2.0 WITH Classpath-exception-2.0) AND GPL-3.0)"
#LABEL org.opencontainers.image.authors "Apache Jena Fuseki by https://jena.apache.org/; this image by https://orcid.org/0000-0001-9842-9718"

# Config and data
ENV FUSEKI_BASE /fuseki

# Installation folder
ENV FUSEKI_HOME /jena-fuseki

WORKDIR /tmp
# published sha512 checksum
#RUN echo "$FUSEKI_SHA512 fuseki.tar.gz" > fuseki.tar.gz.sha512
# Download/check/unpack/move in one go (to reduce image size)
#RUN (curl --location --silent --show-error --fail --retry-connrefused --retry 3 --output fuseki.tar.gz ${ASF_MIRROR}jena/binaries/apache-jena-fuseki-$FUSEKI_VERSION.tar.gz || \
# curl --fail --silent --show-error --retry-connrefused --retry 3 --output fuseki.tar.gz $ASF_ARCHIVE/jena/binaries/apache-jena-fuseki-$FUSEKI_VERSION.tar.gz) && \
# sha512sum -c fuseki.tar.gz.sha512 && \
# tar zxf fuseki.tar.gz && \
# mv apache-jena-fuseki* $FUSEKI_HOME && \
# rm fuseki.tar.gz* && \
# cd $FUSEKI_HOME && rm -rf fuseki.war && chmod 755 fuseki-server

# Test the install by testing it's ping resource. 20s sleep because Docker Hub.
#RUN $FUSEKI_HOME/fuseki-server & \
# sleep 20 && \
# curl -sS --fail 'http://localhost:3030/$/ping'

# No need to kill Fuseki as our shell will exit after curl

# As "localhost" is often inaccessible within Docker container,
# we'll enable basic-auth with a random admin password
# (which we'll generate on start-up)
COPY shiro.ini $FUSEKI_HOME/shiro.ini
COPY docker-entrypoint.sh /
RUN chmod 755 /docker-entrypoint.sh


#COPY load.sh $FUSEKI_HOME/
#COPY tdbloader $FUSEKI_HOME/
#COPY tdbloader2 $FUSEKI_HOME/
#RUN chmod 755 $FUSEKI_HOME/load.sh $FUSEKI_HOME/tdbloader $FUSEKI_HOME/tdbloader2
#VOLUME /staging

# Where we start our server from
WORKDIR $FUSEKI_HOME

# Make sure we start with empty /fuseki
RUN rm -rf $FUSEKI_BASE
#VOLUME $FUSEKI_BASE

#EXPOSE 3030
RUN mkdir /fuseki
ENTRYPOINT ["/usr/bin/tini", "--", "/docker-entrypoint.sh"]
#CMD ["/jena-fuseki/fuseki-server"]
CMD ["sh", "-c", "java -jar /jena-fuseki-geosparql-4.5.0-SNAPSHOT.jar -rf /dataset_dggs_level_7.ttl -l false"]
119 changes: 119 additions & 0 deletions Dockerfile.old
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
## 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 OPENJDK_VERSION=17
ARG ALPINE_VERSION=3.15.0
ARG JENA_VERSION=4.5.0

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

## ---- Stage: Download and build java.
FROM openjdk:${OPENJDK_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 dggs-jar/current/${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 .
ADD output/dataset_dggs_level_7.ttl .

# Run as this user
# -H : no home directorry
# -D : no password

RUN adduser -H -D fuseki fuseki

## ---- 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
COPY --from=base /etc/passwd /etc/passwd

WORKDIR $FUSEKI_DIR

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

RUN \
mkdir -p $LOGS && \
mkdir -p $DATA && \
chown -R fuseki ${FUSEKI_DIR} #&& \
# 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}"

USER fuseki

#EXPOSE 3030

ENTRYPOINT ["sh", "-c", "/opt/java-minimal/bin/java -jar /fuseki/jena-fuseki-geosparql-4.5.0-SNAPSHOT.jar -rf dataset_dggs_level_7.ttl"]
#$JAVA_HOME/bin/java" $JAVA_OPTIONS -jar "${FUSEKI_DIR}/${FUSEKI_JAR}
CMD []
75 changes: 75 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash
# 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.

set -e

if [ ! -f "$FUSEKI_BASE/shiro.ini" ] ; then
# First time
echo "###################################"
echo "Initializing Apache Jena Fuseki"
echo ""
cp "$FUSEKI_HOME/shiro.ini" "$FUSEKI_BASE/shiro.ini"
if [ -z "$ADMIN_PASSWORD" ] ; then
ADMIN_PASSWORD=$(pwgen -s 15)
echo "Randomly generated admin password:"
echo ""
echo "admin=$ADMIN_PASSWORD"
fi
echo ""
echo "###################################"
fi

if [ -d "/fuseki-extra" ] && [ ! -d "$FUSEKI_BASE/extra" ] ; then
ln -s "/fuseki-extra" "$FUSEKI_BASE/extra"
fi

# $ADMIN_PASSWORD only modifies if ${ADMIN_PASSWORD}
# is in shiro.ini
if [ -n "$ADMIN_PASSWORD" ] ; then
export ADMIN_PASSWORD
envsubst '${ADMIN_PASSWORD}' < "$FUSEKI_BASE/shiro.ini" > "$FUSEKI_BASE/shiro.ini.$$" && \
mv "$FUSEKI_BASE/shiro.ini.$$" "$FUSEKI_BASE/shiro.ini"
unset ADMIN_PASSWORD # Don't keep it in memory
export ADMIN_PASSWORD
fi

# fork
exec "$@" &

TDB_VERSION=''
if [ ! -z ${TDB+x} ] && [ "${TDB}" = "2" ] ; then
TDB_VERSION='tdb2'
else
TDB_VERSION='tdb'
fi

# Wait until server is up
while [[ $(curl -I http://localhost:3030 2>/dev/null | head -n 1 | cut -d$' ' -f2) != '200' ]]; do
sleep 1s
done

# Convert env to datasets
printenv | egrep "^FUSEKI_DATASET_" | while read env_var
do
dataset=$(echo $env_var | egrep -o "=.*$" | sed 's/^=//g')
curl -s 'http://localhost:3030/$/datasets'\
-H "Authorization: Basic $(echo -n admin:${ADMIN_PASSWORD} | base64)" \
-H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8'\
--data "dbName=${dataset}&dbType=${TDB_VERSION}"
done

# rejoin our exec
wait
5 changes: 5 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
## Licensed under the terms of http://www.apache.org/licenses/LICENSE-2.0

## env | sort
exec "$JAVA_HOME/bin/java" $JAVA_OPTIONS -jar "${FUSEKI_DIR}/${FUSEKI_JAR}" "$@"
5 changes: 5 additions & 0 deletions jena-build-run-query-scripts/build_jena.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export PATH=/usr/local/apache-maven-3.8.4/bin:$PATH &&
cd /mnt/sda2/Surround/jena-source/jena/jena-geosparql &&
mvn clean install &&
cd /mnt/sda2/Surround/jena-source/jena/jena-fuseki2/jena-fuseki-geosparql &&
mvn clean install
1 change: 1 addition & 0 deletions jena-build-run-query-scripts/query_jena.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl http://localhost:3030/ds -X POST --data 'query=PREFIX+geof%3A+%3Chttp%3A%2F%2Fwww.opengis.net%2Fdef%2Ffunction%2Fgeosparql%2F%3E%0APREFIX+geo%3A+%3Chttp%3A%2F%2Fwww.opengis.net%2Font%2Fgeosparql%23%3E%0APREFIX+testgeom%3A+%3Chttp%3A%2F%2Ftestgeom%23%3E%0A%0ASELECT+%3Fa+%3Fb+%3Fgeoma+%3Fgeomb+%7B%0A++%3Fa+geo%3AhasGeometry+%2F+geo%3AasDGGS+%3Fgeoma+.%0A++%7B+SELECT+%3Fb+%3Fgeomb+%7B%0A++%09%3Fb+geo%3AhasGeometry+%2F+geo%3AasDGGS+%3Fgeomb+.%0A%09%7D%0A++%7D+%0A++FILTER+(%3Fa+!%3D+%3Fb)%0A++FILTER(geof%3AsfEquals(%3Fgeoma%2C+%3Fgeomb))%0A%7D+LIMIT+10'
1 change: 1 addition & 0 deletions jena-build-run-query-scripts/run_jena.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java -jar /mnt/sda2/Surround/jena-source/jena/jena-fuseki2/jena-fuseki-geosparql/target/jena-fuseki-geosparql-4.5.0-SNAPSHOT.jar -rf "/mnt/sda2/Surround/geosparql-benchmark-dggs/output/dataset_dggs_level_7.ttl"
70 changes: 70 additions & 0 deletions log4j2.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
## Licensed under the terms of http://www.apache.org/licenses/LICENSE-2.0
status = error
name = PropertiesConfig

## filters = threshold
## filter.threshold.type = ThresholdFilter
## filter.threshold.level = ALL

appender.console.type = Console
appender.console.name = OUT
appender.console.target = SYSTEM_OUT
appender.console.layout.type = PatternLayout
## appender.console.layout.pattern = %d{HH:mm:ss} %-5p %-15c{1} :: %m%n
## Include date.
appender.console.layout.pattern = [%d{yyyy-MM-dd HH:mm:ss}] %-5p %-15c{1} :: %m%n

## To a file.
## appender.file.type = File
## appender.file.name = FILE
## appender.file.fileName=/fuseki/logs/log.fuseki
## appender.file.layout.type=PatternLayout
## appender.file.layout.pattern = [%d{yyyy-MM-dd HH:mm:ss}] %-5p %-15c{1} :: %m%n

rootLogger.level = INFO
rootLogger.appenderRef.stdout.ref = OUT

logger.jena.name = org.apache.jena
logger.jena.level = INFO

logger.arq-exec.name = org.apache.jena.arq.exec
logger.arq-exec.level = INFO

logger.riot.name = org.apache.jena.riot
logger.riot.level = INFO

logger.fuseki.name = org.apache.jena.fuseki
logger.fuseki.level = INFO

logger.fuseki-fuseki.name = org.apache.jena.fuseki.Fuseki
logger.fuseki-fuseki.level = INFO

logger.fuseki-server.name = org.apache.jena.fuseki.Server
logger.fuseki-server.level = INFO

logger.fuseki-admin.name = org.apache.jena.fuseki.Admin
logger.fuseki-admin.level = INFO

logger.jetty.name = org.eclipse.jetty
logger.jetty.level = WARN

# May be useful to turn up to DEBUG if debugging HTTP communication issues
logger.apache-http.name = org.apache.http
logger.apache-http.level = WARN

logger.shiro.name = org.apache.shiro
logger.shiro.level = WARN
# Hide bug in Shiro 1.5.x
logger.shiro-realm.name = org.apache.shiro.realm.text.IniRealm
logger.shiro-realm.level = ERROR

# This goes out in NCSA format
appender.plain.type = Console
appender.plain.name = PLAIN
appender.plain.layout.type = PatternLayout
appender.plain.layout.pattern = %m%n

logger.request-log.name = org.apache.jena.fuseki.Request
logger.request-log.additivity = false
logger.request-log.level = OFF
logger.request-log.appenderRef.plain.ref = PLAIN
57 changes: 57 additions & 0 deletions shiro.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# 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.

[main]
# Development
ssl.enabled = false

plainMatcher=org.apache.shiro.authc.credential.SimpleCredentialsMatcher
#iniRealm=org.apache.shiro.realm.text.IniRealm
iniRealm.credentialsMatcher = $plainMatcher

#localhost=org.apache.jena.fuseki.authz.LocalhostFilter

[users]
# Implicitly adds "iniRealm = org.apache.shiro.realm.text.IniRealm"
# The admin password will be replaced by value of ADMIN_PASSWORD
# variable by docker-entrypoint.sh on FIRST start up.
admin=${ADMIN_PASSWORD}

[roles]

[urls]
## Control functions open to anyone
/$/status = anon
/$/ping = anon

## and the rest are restricted
/$/** = authcBasic,user[admin]

## Sparql update is restricted
/*/update/** = authcBasic,user[admin]


## If you want simple, basic authentication user/password
## on the operations,
## 1 - set a password in [users]
## 2 - change the line above to:
## /$/** = authcBasic,user[admin]
## and set a better

## or to allow any access.
##/$/** = anon

# Everything else
/**=anon

0 comments on commit d644a97

Please sign in to comment.