Last active
June 16, 2016 17:56
-
-
Save danlamanna/9ffce8a0b6106246417689babb811bb0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM girder/girder | |
RUN mkdir /assetstore | |
RUN git clone https://github.com/memex-explorer/image_space.git | |
RUN girder-install plugin -s image_space/imagespace | |
RUN girder-install plugin -s image_space/imagespace_smqtk | |
RUN npm install --only=prod --unsafe-perm | |
ENV IMAGE_SPACE_SOLR=http://imagespace-solr:8983/solr/imagespace | |
ENV IMAGE_SPACE_SOLR_PREFIX=/images | |
ENV IMAGE_SPACE_PREFIX=http://localhost:8080/images | |
ENV IMAGE_SPACE_IMAGE_DIR=/images | |
ENTRYPOINT ["python", "-m", "girder"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PREFIX="imagespace" | |
CORE_NAME="imagespace" | |
SOLR_IMAGE="solr:6.0" | |
MONGO_IMAGE="mongo:3.0" | |
IMAGESPACE_IMAGE="imagespace/quickstart" | |
SMQTK_ENABLED=0 | |
IMAGESPACE_DOCKER_ARGS="" | |
if [[ $# -eq 0 ]]; then | |
echo "Usage: imagespace-quickstart DIR" | |
fi | |
while [[ $# -gt 0 ]] | |
do | |
key="$1" | |
shift # past key | |
case ${key} in | |
-i|--images) | |
IMAGE_DIR="$1" | |
shift | |
;; | |
-n|--docker-network) | |
DOCKER_NETWORK="$1" | |
shift | |
;; | |
--mongo-data-dir) | |
MONGO_DATA_DIR="$1" | |
shift | |
;; | |
--smqtk-iqr-url) | |
SMQTK_IQR_URL="$1" | |
SMQTK_ENABLED=1 | |
IMAGESPACE_DOCKER_ARGS="$IMAGESPACE_DOCKER_ARGS -e IMAGE_SPACE_SMQTK_IQR_URL=$SMQTK_IQR_URL" | |
shift # past value | |
;; | |
--smqtk-nn-url) | |
SMQTK_NN_URL="$1" | |
SMQTK_ENABLED=1 | |
IMAGESPACE_DOCKER_ARGS="$IMAGESPACE_DOCKER_ARGS -e IMAGE_SPACE_SMQTK_SIMILARITY_SEARCH=$SMQTK_NN_URL" | |
shift | |
;; | |
*) # unknown option | |
;; | |
esac | |
done | |
if [ -z "${IMAGE_DIR}" ] | |
then | |
echo "ERROR: No image directory provided. Please provide -i|--images option." | |
exit 1 | |
elif [ -z "$(ls "${IMAGE_DIR}")" ] | |
then | |
echo "ERROR: Nothing in provided image directory: ${IMAGE_DIR}" | |
exit 2 | |
fi | |
if [ -z "${DOCKER_NETWORK}" ] | |
then | |
DOCKER_NETWORK="imagespace-network" | |
fi | |
# | |
# Make sure docker network exists / is created | |
# | |
if [ -z "$(docker network ls 2>/dev/null | tail -n +2 | grep "${DOCKER_NETWORK}")" ] | |
then | |
# network doesn't exist yet, create it | |
echo "Creating new docker network \"${DOCKER_NETWORK}\" using bridge driver" | |
docker network create --driver bridge "${DOCKER_NETWORK}" | |
else | |
echo "Found docker network \"${DOCKER_NETWORK}\" already exists" | |
fi | |
docker run --name $PREFIX-solr -d -P --net=$DOCKER_NETWORK $IMAGESPACE_DOCKER_ARGS $SOLR_IMAGE solr-create -c $CORE_NAME | |
SOLR_CONTAINER_PORT=$(docker port $PREFIX-solr 8983 | cut -d: -f2) | |
echo "Waiting for Solr to become available.." | |
SOLR_EXIT_STATUS=-1 | |
while [ $SOLR_EXIT_STATUS -ne 0 ]; do | |
# Sleep until the curl call returns an http code 200 | |
curl --location --write-out "%{http_code}" --silent "http://localhost:$SOLR_CONTAINER_PORT/solr" | grep -q '^200' | |
SOLR_EXIT_STATUS=$? | |
sleep 1 | |
done | |
# Add sha1sum_s_md field as a single valued string | |
curl "http://localhost:$SOLR_CONTAINER_PORT/solr/$CORE_NAME/schema" -H 'Accept: application/json, text/plain, */*' -H 'Content-Type: application/json;charset=utf-8' --data '{"add-field":{"stored":"true","indexed":"true","name":"sha1sum_s_md","type":"string"}}' | |
echo "Importing images into Solr" | |
# Load images into Solr | |
for filename in $(find "$IMAGE_DIR" -type f); do | |
sha=$(sha1sum "$filename" | cut -d' ' -f1) | |
filename=/images/$(basename "$filename") | |
curl --silent "http://localhost:$SOLR_CONTAINER_PORT/solr/$CORE_NAME/update?commitWithin=30000" -H 'Content-Type: application/json' --data "[{'id' : '$filename', 'sha1sum_s_md': '$sha' }]" > /dev/null | |
done | |
docker run --name $PREFIX-mongo -v "$MONGO_DATA_DIR":/data/db -d --net=$DOCKER_NETWORK $IMAGESPACE_DOCKER_ARGS $MONGO_IMAGE | |
# Wait for Mongo to start up | |
MONGO_OUTPUT=$(docker logs $PREFIX-mongo) | |
while [[ $MONGO_OUTPUT != *"waiting for connections on port 27017"* ]]; do | |
sleep 1 | |
MONGO_OUTPUT=$(docker logs $PREFIX-mongo) | |
done | |
docker run --name $PREFIX-girder \ | |
--volume "$IMAGE_DIR":/images -d -p 8080:8080 --publish-all=true --net=$DOCKER_NETWORK $IMAGESPACE_DOCKER_ARGS $IMAGESPACE_IMAGE --database mongodb://imagespace-mongo/girder | |
# Wait for Girder to start up | |
echo $(docker logs $PREFIX-girder 2>&1) | grep -qi "engine bus started" | |
GIRDER_STARTED=$? | |
while [[ $GIRDER_STARTED -ne 0 ]]; do | |
sleep 1 | |
echo $(docker logs $PREFIX-girder 2>&1) | grep -qi "engine bus started" | |
GIRDER_STARTED=$? | |
done | |
# Create Girder admin user, enable plugins | |
docker exec -it $PREFIX-girder python -c " | |
import requests | |
user = requests.post('http://localhost:8080/api/v1/user', data={'login': 'girder', 'email': '[email protected]', 'firstName': 'girder', 'lastName': 'girder', 'password': 'girder'}) | |
token = user.json()['authToken']['token'] | |
requests.post('http://localhost:8080/api/v1/assetstore', data={'name': 'assetstore', 'type': 0, 'root': '/assetstore'}, headers={'Girder-Token': token}) | |
requests.put('http://localhost:8080/api/v1/system/setting', data={'key': 'core.plugins_enabled', 'value': '[\"imagespace\"]'}, headers={'Girder-Token': token}) | |
requests.put('http://localhost:8080/api/v1/system/restart', headers={'Girder-Token': token})" | |
if [ $SMQTK_ENABLED -eq 1 ]; then | |
docker exec -it $PREFIX-girder python -c " | |
import requests | |
user = requests.get('http://localhost:8080/api/v1/user/authentication', auth=('girder', 'girder')) | |
token = user.json()['authToken']['token'] | |
r = requests.put('http://localhost:8080/api/v1/system/setting', data={'key': 'core.plugins_enabled', 'value': '[\"imagespace\", \"imagespace_smqtk\"]'}, headers={'Girder-Token': token}) | |
requests.put('http://localhost:8080/api/v1/system/restart', headers={'Girder-Token': token}) | |
assert r.ok" | |
fi | |
echo "ImageSpace is being served at http://localhost:8080" | |
echo "Image similarity might not be available for all images until descriptors are computed." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment