diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index bafaa75..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,8 +0,0 @@ -version: "3.6" -services: - blazegraph: - build: - context: . - dockerfile: Dockerfile-blazegraph - ports: - - "192.168.56.101:9999:9999" diff --git a/docker/Dockerfile b/docker/Dockerfile index e294080..c933981 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,37 +1,9 @@ -FROM ubuntu:18.04 - -RUN apt-get update && \ - apt-get install -y git python3 graphviz python3-pip ssh mercurial python-setuptools zip - -RUN python3 -m pip install --upgrade pip && \ - pip3 install rdflib requests rapidfuzz fuzzywuzzy pygithub pybids duecredit setuptools \ - python-Levenshtein pytest graphviz prov pydot validators ontquery \ - click rdflib-jsonld pyld pytest-cov tabulate joblib - - - +FROM python:3.11 +RUN apt-get update && apt-get install -y graphviz WORKDIR /opt - -RUN wget https://files.pythonhosted.org/packages/af/1c/7e4c25d5539ac8979d633afe03d16ddb01716c6cde97ebea33a6659ea9c6/Owlready2-0.24.tar.gz&& \ - tar -xzf Owlready2-0.24.tar.gz && \ - cd Owlready2-0.24 && \ - python setup.py build && \ - python setup.py install - ENV LC_ALL=C.UTF-8 ENV LANG=C.UTF-8 -RUN update-alternatives --remove python /usr/bin/python2 && \ - update-alternatives --install /usr/bin/python python /usr/bin/python3 10 && \ - update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 10 - -RUN cd / && \ - git clone https://github.com/incf-nidash/PyNIDM.git && \ - mv PyNIDM PyNIDM-snapshot && \ - cd PyNIDM-snapshot && \ - pip install -e . - -RUN git config --global user.name "docker user" && git config --global user.email "docker@example.com" - -ENV TMPDIR=/opt/project/cache - -COPY . . +RUN pip install git+https://github.com/incf-nidash/PyNIDM.git +RUN git config --global user.name "docker user" && \ + git config --global user.email "docker@example.com" +CMD ["/bin/bash"] diff --git a/docker/Dockerfile-datalad b/docker/Dockerfile-datalad deleted file mode 100644 index 4f03cd5..0000000 --- a/docker/Dockerfile-datalad +++ /dev/null @@ -1,13 +0,0 @@ -FROM pynidm:latest - -WORKDIR /opt - -RUN pip install datalad - -RUN wget -O- http://neuro.debian.net/lists/bionic.us-nh.full | tee /etc/apt/sources.list.d/neurodebian.sources.list && \ - apt-key adv --recv-keys --keyserver hkp://pool.sks-keyservers.net:80 0xA5D32F012649A5A9 && \ - apt-get update - -RUN apt-get install -y git-annex-standalone - -RUN datalad install ///abide2/RawData/NYU_1 diff --git a/docker/Dockerfile-rest b/docker/Dockerfile-rest index aec6d1f..6a8a170 100644 --- a/docker/Dockerfile-rest +++ b/docker/Dockerfile-rest @@ -1,6 +1,5 @@ FROM pynidm:latest - -RUN pip3 install flask flask_restful flask-cors - +RUN pip install flask flask_restful flask-cors EXPOSE 5000 -CMD ["python", "/opt/project/rest-server.py"] +COPY rest-server.py /usr/src/ +CMD ["python", "/usr/src/rest-server.py"] diff --git a/docker/README.md b/docker/README.md index d587d18..6d233b8 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,38 +1,40 @@ # Docker and REST API -This dockerfile can be used to create a development docker container suitable for both -interactive use and also as a proof of concept REST API server. +This Dockerfile can be used to create a development Docker container suitable +for both interactive use and also as a proof-of-concept REST API server. -#Build the container +## Build the container -These instructions assume you have the PyNIDM source code in ~/PyNIDM. -To build the container, start in this directory and use the command: +To build the container, start in this directory and run the commands: ``` -./build.sh +docker build -f Dockerfile -t pynidm . +docker build -f Dockerfile-rest -t pynidm-rest . ``` ## Interactive -You can then run the container interactively with: +You can then run the container interactively with a command like: + ``` -./rundocker.sh +docker run -it -v ~/PyNIDM:/opt/project pynidm ``` -This will make a live mount of the files in ~/PyNIDM on your host system -in the directory /opt/PyNIDM in the container. +This will make a live mount of the files in `~/PyNIDM` on your host system in +the directory `/opt/project` in the container. ## REST Server -This section assumes you have the PyNIDM source code in ~/PyNIDM. You should -also put any NIDM ttl files you want the REST s erver to process somewhere under the -~/PyNIDM/ttl directory. Once you have done those things, use the command: +This section assumes you have any NIDM ttl files you want the REST server to +process stored under `ttl/` in the current directory. Then, use the command: + ``` -./runrest.sh +docker run -it -p 5000:5000 -v "$PWD/ttl":/opt/project/ttl pynidm-rest ``` -This should start a HTTP server that is listening on port 5000 of your +This should start an HTTP server that is listening on port 5000 of your local system. You should be able to connect to the following routes: + ``` http://localhost:5000/projects http://localhost:5000/projects/[Project-UUID] @@ -40,6 +42,6 @@ http://localhost:5000/projects/[Project-UUID]/subjects http://localhost:5000/projects/[Project-UUID]/subjects/[Subject-UUID] ``` -After the server is started you can continue to modify the files in your -~/PyNIDM/ttl directory and those changes will immediately be reflected in the -REST API results. +After the server is started you can continue to modify the files in your `ttl/` +directory, and those changes will immediately be reflected in the REST API +results. diff --git a/docker/build.sh b/docker/build.sh deleted file mode 100755 index 0f1e686..0000000 --- a/docker/build.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -mkdir -p ../cache -sudo docker build -f Dockerfile -t pynidm . -sudo docker build -f Dockerfile-rest -t pynidm-rest . diff --git a/docker/rest-blaze.py b/docker/rest-blaze.py deleted file mode 100755 index 50585db..0000000 --- a/docker/rest-blaze.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/python - -import glob -import json -import os -from flask import Flask, request -from flask_cors import CORS -from flask_restful import Api, Resource -from nidm.experiment.tools.rest import RestParser - - -def getTTLFiles(): - files = [] - for filename in glob.glob("/opt/project/ttl/**/*.ttl", recursive=True): - files.append(filename) - return files - - -class NIDMRest(Resource): - def get(self, all): # noqa: A002 - query_bits = [] - for a in request.args.keys(): - query_bits.append("{}={}".format(a, request.args.get(a))) - query = "&".join(query_bits) - - files = getTTLFiles() - if len(files) == 0: - return { - "error": "No NIDM files found. You may need to add NIDM ttl files to ~/PyNIDM/ttl" - } - restParser = RestParser( - output_format=RestParser.OBJECT_FORMAT, verbosity_level=5 - ) - - json_str = json.dumps( - restParser.run(files, "{}?{}".format(all, query)), indent=2 - ) - response = app.response_class( - response=json_str, status=200, mimetype="application/json" - ) - - return response - - -class Instructions(Resource): - def get(self): - return { - "message": "You probably want to start at {}projects See instructions at PyNIDM/docker/README.md for details on the API and loading data.".format( - request.url_root - ) - } - - -app = Flask(__name__) -CORS(app) -api = Api(app) -api.add_resource(Instructions, "/") -api.add_resource(NIDMRest, "/") - -if __name__ == "__main__": - os.system("java -server -Xmx512mb -jar /opt/blazegraph.jar") - app.run(debug=True, host="0.0.0.0") diff --git a/rest-server.py b/docker/rest-server.py similarity index 100% rename from rest-server.py rename to docker/rest-server.py diff --git a/docker/rundatalad.sh b/docker/rundatalad.sh deleted file mode 100755 index 61c5766..0000000 --- a/docker/rundatalad.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -# -# You can create the docker container with: -# docker build -t pynidm . -# -# The command below will mount the ~/PyNIDM and ~/simple2_NIDM_examples directories -# in /opt and give you a bash shell in the container - -sudo docker run -v ~/PyNIDM:/opt/project -v ~/simple2_NIDM_examples:/opt/simple2_NIDM_examples -it datalad diff --git a/docker/rundocker.sh b/docker/rundocker.sh deleted file mode 100755 index 50ccca3..0000000 --- a/docker/rundocker.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -# -# You can create the docker container with the build.sh script in this directory -# -# The command below will mount the ~/PyNIDM and ~/simple2_NIDM_examples directories -# in /opt and give you a bash shell in the container - -sudo docker run -v ~/PyNIDM:/opt/project -v ~/simple2_NIDM_examples:/opt/simple2_NIDM_examples -it pynidm diff --git a/docker/runrest.sh b/docker/runrest.sh deleted file mode 100755 index b575373..0000000 --- a/docker/runrest.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -# -# You can create the docker container with: -# docker build -t pynidm . -# -# The command below will mount the ~/PyNIDM and ~/simple2_NIDM_examples directories -# in /opt and give you a bash shell in the container - -sudo docker run -p 5000:5000 -v ~/PyNIDM:/opt/project pynidm-rest