diff --git a/package-lock.json b/package-lock.json index 648bc0c866..ca50836cc5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -106,7 +106,6 @@ "@typescript-eslint/eslint-plugin": "5.62.0", "@typescript-eslint/parser": "5.62.0", "autoprefixer": "^10.4.13", - "commander": "11.1.0", "cypress": "^12.17.1", "cypress-browser-permissions": "^1.1.0", "cypress-real-events": "^1.9.1", @@ -15571,15 +15570,6 @@ "node": ">= 0.8" } }, - "node_modules/commander": { - "version": "11.1.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-11.1.0.tgz", - "integrity": "sha512-yPVavfyCcRhmorC7rWlkHn15b4wDVgVmBA7kV4QVBsF7kv/9TKJAbAXVTxvTnwP8HHKjRCJDClKbciiYS7p0DQ==", - "dev": true, - "engines": { - "node": ">=16" - } - }, "node_modules/comment-json": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/comment-json/-/comment-json-4.2.3.tgz", diff --git a/package.json b/package.json index 0c60268348..f89027809d 100644 --- a/package.json +++ b/package.json @@ -140,7 +140,6 @@ "@typescript-eslint/eslint-plugin": "5.62.0", "@typescript-eslint/parser": "5.62.0", "autoprefixer": "^10.4.13", - "commander": "11.1.0", "cypress": "^12.17.1", "cypress-browser-permissions": "^1.1.0", "cypress-real-events": "^1.9.1", diff --git a/tools/.gitignore b/tools/.gitignore new file mode 100644 index 0000000000..3c3629e647 --- /dev/null +++ b/tools/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/tools/package-lock.json b/tools/package-lock.json new file mode 100644 index 0000000000..418e28e83b --- /dev/null +++ b/tools/package-lock.json @@ -0,0 +1,22 @@ +{ + "name": "geonetwork-ui-tools", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "geonetwork-ui-tools", + "devDependencies": { + "commander": "11.1.0" + } + }, + "node_modules/commander": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-11.1.0.tgz", + "integrity": "sha512-yPVavfyCcRhmorC7rWlkHn15b4wDVgVmBA7kV4QVBsF7kv/9TKJAbAXVTxvTnwP8HHKjRCJDClKbciiYS7p0DQ==", + "dev": true, + "engines": { + "node": ">=16" + } + } + } +} diff --git a/tools/package.json b/tools/package.json index 3dbc1ca591..3d6578aa86 100644 --- a/tools/package.json +++ b/tools/package.json @@ -1,3 +1,12 @@ { - "type": "module" + "name": "geonetwork-ui-tools", + "description": "A series of tools used alongside GeoNetwork-UI", + "type": "module", + "devDependencies": { + "commander": "11.1.0" + }, + "scripts": { + "pipelines:register": "node pipelines/register-es-pipelines.js register", + "pipelines:docker-build": "docker build . -f pipelines/Dockerfile -t $(./print-docker-tag.sh tools-pipelines)" + } } diff --git a/tools/pipelines/Dockerfile b/tools/pipelines/Dockerfile new file mode 100644 index 0000000000..3da666665f --- /dev/null +++ b/tools/pipelines/Dockerfile @@ -0,0 +1,15 @@ +FROM node:lts-alpine + +RUN mkdir /app +WORKDIR /app +COPY ./pipelines/register-es-pipelines.js ./ +COPY ./package.json ./ +COPY ./package-lock.json ./ + +ENV ES_HOST="http://elasticsearch:9200" +ENV RECORDS_INDEX="gn-records" + +RUN npm ci + +#ENTRYPOINT ["node", "./register-es-pipelines.js", "register", "--host", "echo $ES_HOST", "--records-index", "echo $RECORDS_INDEX"] +ENTRYPOINT node ./register-es-pipelines.js register --host $ES_HOST --records-index $RECORDS_INDEX diff --git a/tools/register-es-pipelines.js b/tools/pipelines/register-es-pipelines.js similarity index 91% rename from tools/register-es-pipelines.js rename to tools/pipelines/register-es-pipelines.js index d559aa988b..31b0424de2 100644 --- a/tools/register-es-pipelines.js +++ b/tools/pipelines/register-es-pipelines.js @@ -8,14 +8,14 @@ program program .command('register') .description('Register pipelines') - .option('--host ', 'ElasticSearch host', 'http://localhost:9200/') + .option('--host ', 'ElasticSearch host', 'http://localhost:9200') .option( '--records-index ', 'Name of the index used by GeoNetwork for records', 'gn-records' ) .action((options) => { - const esUrl = options.host + const esUrl = options.host.replace(/\/$/, '') // remove trailing slash if any const recordsIndex = options.recordsIndex registerPipelines(esUrl, recordsIndex) }) @@ -24,11 +24,11 @@ program .description('Clear all registered pipelines') .option( '--host ', - 'ElasticSearch host, default is http://localhost:9090/', - 'http://localhost:9200/' + 'ElasticSearch host, default is http://localhost:9090', + 'http://localhost:9200' ) .action((options) => { - const esUrl = options.host || 'http://localhost:9200/' + const esUrl = options.host.replace(/\/$/, '') // remove trailing slash if any clearPipelines(esUrl) }) @@ -132,7 +132,7 @@ for(int i = ctx.format.length - 1; i >= 0; i--) { async function registerPipeline(esHost, name, payload) { console.log(`adding ${name} pipeline...`) - await fetch(`${esHost}_ingest/pipeline/${name}`, { + await fetch(`${esHost}/_ingest/pipeline/${name}`, { method: 'PUT', body: JSON.stringify(payload), headers: { @@ -153,7 +153,7 @@ async function registerPipeline(esHost, name, payload) { async function clearPipeline(esHost, name) { console.log(`clearing ${name} pipeline...`) - await fetch(`${esHost}_ingest/pipeline/${name}`, { + await fetch(`${esHost}/_ingest/pipeline/${name}`, { method: 'DELETE', }) .then((resp) => resp.json()) @@ -170,7 +170,7 @@ async function clearPipeline(esHost, name) { async function setDefaultPipeline(esHost, recordsIndex, name) { console.log(`setting ${name} as default pipeline...`) - await fetch(`${esHost}${recordsIndex}/_settings`, { + await fetch(`${esHost}/${recordsIndex}/_settings`, { method: 'PUT', body: JSON.stringify({ 'index.default_pipeline': name }), headers: { @@ -191,7 +191,7 @@ async function setDefaultPipeline(esHost, recordsIndex, name) { async function registerPipelines(esHost, recordsIndex) { console.log('querying currently registered pipelines...') - const pipelines = await fetch(`${esHost}_ingest/pipeline`).then((resp) => + const pipelines = await fetch(`${esHost}/_ingest/pipeline`).then((resp) => resp.json() ) @@ -210,7 +210,7 @@ async function registerPipelines(esHost, recordsIndex) { } async function clearPipelines(esHost) { - const pipelines = await fetch(`${esHost}_ingest/pipeline`).then((resp) => + const pipelines = await fetch(`${esHost}/_ingest/pipeline`).then((resp) => resp.json() )