diff --git a/.env.template b/.env.template index 475f031ad80ba309d13a68c4e5f7b3dc37c5f1ce..a51a08256bb473621bbdbde229c0d9f9c829966d 100644 --- a/.env.template +++ b/.env.template @@ -19,5 +19,16 @@ HTTP_FOLDER=./www # hosts allowed to access ressources from $HTTP_FOLDER # * to allow all, http://localhost:$DEV_PORT to allow only devserver CORS_ALLOWED_HOSTS=http://localhost:$DEV_PORT +# Annotot configuration (annotation storage server +# ENV = development or production +ANNOTOT_ENV=development +ANNOTOT_PORT=3000 +ANNOTOT_LISTEN_IP=0.0.0.0 +# This is the host used by annotot request launched by the client using mirador +# It should be localhost on dev mode, an something like annotot.yourservice.com in production +ANNOTOT_HOST=localhost +# For production only +ANNOTOT_SECRET_KEY_BASE=insert-a-random-key-here +# For traefik (optionnal) NAME=IIIF HOST=IIIF.tetras-lab.io diff --git a/.gitignore b/.gitignore index bf92917fc058a259666df921db979d9ed0dca915..a1921ae8fc1652b49d86b995ae7c66571d1097bd 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ node_modules/ dist/ .cache/ .*.sw? +annotot-db/ diff --git a/README.md b/README.md index 5aa601816b3a7be1af1d387e05c3bbf73240937a..434742c7fb372783233307cae034a0ca956c3f35 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ This readme assumes that you now a few basic about `docker` and `docker-compose` Copy `.env.template` to `.env` and change variables to suit your need. +You **MUST** set at least the `ANNOTOT_SECRET_KEY_BASE` to a random string, the rest is preconfigured for a local development environment. The `$HTTP_FOLDER` (`./www` by default) directory will be accessible via HTTP at `http://localhost:$PORT/data` and can be used to store manifests and theirs ressources and see them in Mirador. @@ -31,6 +32,9 @@ Run `docker-compose up -d`, which will serve a mirador instance at `http://local For production, one **also** need to setup : + `COMPOSE_FILE` should be at least `docker-compose.yml` ++ `ANNOTOT_ENV` should be `production` ++ `ANNOTOT_HOST` should be the public hostname of your annotot server + Run `docker-compose up -d`, which will serve a mirador instance at `http://localhost:$PORT` (default port is 8080). If sources files are modified, run `docker-compose up -d --build` to update Mirador diff --git a/dev.yml b/dev.yml index 62146828dcb7fefb384c5df5d7710f4187540516..1948184b2bc5149b42be9a86cbc086c425254e80 100644 --- a/dev.yml +++ b/dev.yml @@ -18,3 +18,7 @@ services: httpd: ports: - $PORT:80 + + annotot: + ports: + - ${ANNOTOT_PORT}:3000 diff --git a/docker-compose.yml b/docker-compose.yml index 19661442781fef917b2633380deabdaacb2ebb62..7b8770da07ceefb2c51e4eddb35c023b87767cbd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,3 +9,12 @@ services: volumes: - $HTTP_FOLDER:/srv/data - ./Caddyfile:/etc/caddy/Caddyfile + + annotot: + image: tetraslibre/annotot-app + environment: + - IP=${ANNOTOT_LISTEN_IP} + - ENV=${ANNOTOT_ENV} + - SECRET_KEY_BASE=${ANNOTOT_SECRET_KEY_BASE} + volumes: + - ./annotot-db:/app/db diff --git a/package-lock.json b/package-lock.json index 1baffaddcd8a36cddb9369bd0358da0f38029a94..e9a4f016b65f0877c7869eb76e6245aed25a5940 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "ISC", "dependencies": { "css-loader": "^3.6.0", + "dotenv-webpack": "^8.0.1", "mirador": "git+https://gitlab.tetras-libre.fr/iiif/mirador-video-annotation#wip-webpack-from-git", "mirador-annotations": "0.4.0", "react": "^16.13.1", @@ -2470,6 +2471,36 @@ "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.4.0.tgz", "integrity": "sha512-Be9tbQMZds4a3C6xTmz68NlMfeONA//4dOavl/1rNw50E+/QO0KVpbcU0PcaW0nsQxurXls9ZocqFxk8R2mWEA==" }, + "node_modules/dotenv": { + "version": "8.6.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.6.0.tgz", + "integrity": "sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==", + "engines": { + "node": ">=10" + } + }, + "node_modules/dotenv-defaults": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/dotenv-defaults/-/dotenv-defaults-2.0.2.tgz", + "integrity": "sha512-iOIzovWfsUHU91L5i8bJce3NYK5JXeAwH50Jh6+ARUdLiiGlYWfGw6UkzsYqaXZH/hjE/eCd/PlfM/qqyK0AMg==", + "dependencies": { + "dotenv": "^8.2.0" + } + }, + "node_modules/dotenv-webpack": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/dotenv-webpack/-/dotenv-webpack-8.0.1.tgz", + "integrity": "sha512-CdrgfhZOnx4uB18SgaoP9XHRN2v48BbjuXQsZY5ixs5A8579NxQkmMxRtI7aTwSiSQcM2ao12Fdu+L3ZS3bG4w==", + "dependencies": { + "dotenv-defaults": "^2.0.2" + }, + "engines": { + "node": ">=10" + }, + "peerDependencies": { + "webpack": "^4 || ^5" + } + }, "node_modules/draft-js": { "version": "0.11.7", "resolved": "https://registry.npmjs.org/draft-js/-/draft-js-0.11.7.tgz", @@ -10145,6 +10176,27 @@ "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.4.0.tgz", "integrity": "sha512-Be9tbQMZds4a3C6xTmz68NlMfeONA//4dOavl/1rNw50E+/QO0KVpbcU0PcaW0nsQxurXls9ZocqFxk8R2mWEA==" }, + "dotenv": { + "version": "8.6.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.6.0.tgz", + "integrity": "sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==" + }, + "dotenv-defaults": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/dotenv-defaults/-/dotenv-defaults-2.0.2.tgz", + "integrity": "sha512-iOIzovWfsUHU91L5i8bJce3NYK5JXeAwH50Jh6+ARUdLiiGlYWfGw6UkzsYqaXZH/hjE/eCd/PlfM/qqyK0AMg==", + "requires": { + "dotenv": "^8.2.0" + } + }, + "dotenv-webpack": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/dotenv-webpack/-/dotenv-webpack-8.0.1.tgz", + "integrity": "sha512-CdrgfhZOnx4uB18SgaoP9XHRN2v48BbjuXQsZY5ixs5A8579NxQkmMxRtI7aTwSiSQcM2ao12Fdu+L3ZS3bG4w==", + "requires": { + "dotenv-defaults": "^2.0.2" + } + }, "draft-js": { "version": "0.11.7", "resolved": "https://registry.npmjs.org/draft-js/-/draft-js-0.11.7.tgz", diff --git a/package.json b/package.json index 1ed8a1947a10359a72df790dbdddf5c96228813f..a47ef8382c7dedfb85adcb5933306b8ca2850182 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "license": "ISC", "dependencies": { "css-loader": "^3.6.0", + "dotenv-webpack": "^8.0.1", "mirador": "git+https://gitlab.tetras-libre.fr/iiif/mirador-video-annotation#wip-webpack-from-git", "mirador-annotations": "0.4.0", "react": "^16.13.1", diff --git a/src/index.js b/src/index.js index 0e7931ea82fa0d3c84289299e36d6c459b6934e1..e6ea0a1fdfdd068eb612e6236f41d8dd263066a7 100644 --- a/src/index.js +++ b/src/index.js @@ -5,11 +5,10 @@ import annotationPlugins from 'mirador-annotations/es/index'; import LocalStorageAdapter from 'mirador-annotations/es/LocalStorageAdapter'; import AnnototAdapter from 'mirador-annotations/es/AnnototAdapter'; -const endpointUrl = 'http://127.0.0.1:3000/annotations'; +const endpointUrl = `http://${process.env.ANNOTOT_HOST}:${process.env.ANNOTOT_PORT}/annotations`; const config = { annotation: { - adapter: (canvasId) => new LocalStorageAdapter(`localStorage://?canvasId=${canvasId}`), - // adapter: (canvasId) => new AnnototAdapter(canvasId, endpointUrl), + adapter: (canvasId) => new AnnototAdapter(canvasId, endpointUrl), exportLocalStorageAnnotations: false, // display annotation JSON export button }, id: 'demo', diff --git a/traefik.yml b/traefik.yml index d6ccaef82556712b5a55da226a351a7b4f7f67c3..5dab8fecd11eba758d2e5308674fac75fe4007c8 100644 --- a/traefik.yml +++ b/traefik.yml @@ -12,6 +12,18 @@ services: - "traefik.http.routers.${NAME}.entrypoints=web,websecure" - "traefik.http.routers.${NAME}.middlewares=hardening@docker" + annotot: + networks: + - default + - traefik + labels: + - "traefik.enable=true" + - "traefik.docker.network=traefik" + - "traefik.http.routers.ANNOTOT_${NAME}.rule=Host(`${ANNOTOT_HOST}`)" + - "traefik.http.routers.ANNOTOT_${NAME}.tls.certresolver=myresolver" + - "traefik.http.routers.ANNOTOT_${NAME}.entrypoints=web,websecure" + - "traefik.http.routers.ANNOTOT_${NAME}.middlewares=hardening@docker" + - "traefik.http.services.ANNOTOT_${NAME}.loadbalancer.server.port=3000" networks: traefik: diff --git a/webpack.config.js b/webpack.config.js index 8f2a54375e34f3333d36b6d91b0ddc560308258a..d9fda3b3e99bb9a46f27e5b6df71d5770165dd6d 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,5 +1,6 @@ const path = require('path'); const webpack = require('webpack'); +const Dotenv = require('dotenv-webpack'); module.exports = { mode: process.env.WEBPACK_MODE, @@ -35,6 +36,7 @@ module.exports = { new webpack.IgnorePlugin({ /* cf https://gitlab.tetras-libre.fr/iiif/mirador-video-annotation/-/blob/annotation-on-video/webpack.config.js#L42 */ resourceRegExp: /@blueprintjs\/(core|icons)/, // ignore optional UI framework dependencies - }) + }), + new Dotenv() ] };