From 02a99f98e8863ceb5da792a7b34be1d6a89c2d68 Mon Sep 17 00:00:00 2001
From: Olivia Guyot <olivia.guyot@camptocamp.com>
Date: Wed, 27 Dec 2023 16:00:31 +0100
Subject: [PATCH] feat(support-services): set default pipeline before
 reindexing all records

---
 apps/datahub-e2e/src/e2e/datasets.cy.ts       | 13 -----------
 support-services/docker-compose.yml           | 23 +++++++++++--------
 .../02-set-default-pipeline.sh                |  7 ++++++
 3 files changed, 21 insertions(+), 22 deletions(-)
 create mode 100755 support-services/docker-entrypoint.d/02-set-default-pipeline.sh

diff --git a/apps/datahub-e2e/src/e2e/datasets.cy.ts b/apps/datahub-e2e/src/e2e/datasets.cy.ts
index 9152ace7ef..c49ca0f8c8 100644
--- a/apps/datahub-e2e/src/e2e/datasets.cy.ts
+++ b/apps/datahub-e2e/src/e2e/datasets.cy.ts
@@ -483,19 +483,6 @@ describe('datasets', () => {
           .should('not.exist')
       })
 
-      it('should reindex records', () => {
-        cy.login('admin', 'admin', false)
-        cy.visit(
-          `http://localhost:8080/geonetwork/srv/eng/admin.console#/tools`
-        )
-        cy.intercept({
-          method: 'PUT',
-          url: 'http://localhost:8080/geonetwork/srv/api/site/index?reset=false&asynchronous=true',
-        }).as('indexingRecordsXHR')
-        cy.get('[class=panel-body]').find('button').first().click()
-        cy.wait('@indexingRecordsXHR')
-      })
-
       it('should display quality widget', () => {
         cy.visit('/search')
         cy.get('gn-ui-progress-bar')
diff --git a/support-services/docker-compose.yml b/support-services/docker-compose.yml
index 330455c0df..7422819410 100644
--- a/support-services/docker-compose.yml
+++ b/support-services/docker-compose.yml
@@ -99,6 +99,18 @@ services:
     ports:
       - '8080:8080'
 
+  init-pipeline:
+    image: geonetwork/geonetwork-ui-tools-pipelines:latest
+    build: ../tools/pipelines
+    environment:
+      ES_HOST: http://elasticsearch:9200
+      RECORDS_INDEX: gn-records
+    depends_on:
+      geonetwork:
+        condition: service_healthy
+      elasticsearch:
+        condition: service_healthy
+
   init:
     image: alpine/curl
     # only run init if volumes were cleared
@@ -110,6 +122,8 @@ services:
         condition: service_healthy
       elasticsearch:
         condition: service_healthy
+      init-pipeline:
+        condition: service_completed_successfully
     healthcheck:
       test: ['CMD-SHELL', "sh -c '[ -f /done ]'"]
       interval: 5s
@@ -140,12 +154,3 @@ services:
         condition: service_healthy
     ports:
       - '8081:8080'
-
-  tools-pipelines:
-    image: geonetwork/geonetwork-ui-tools-pipelines:latest
-    environment:
-      ES_HOST: http://elasticsearch:9200
-      RECORDS_INDEX: gn-records
-    depends_on:
-      init:
-        condition: service_completed_successfully
diff --git a/support-services/docker-entrypoint.d/02-set-default-pipeline.sh b/support-services/docker-entrypoint.d/02-set-default-pipeline.sh
new file mode 100755
index 0000000000..42108454bf
--- /dev/null
+++ b/support-services/docker-entrypoint.d/02-set-default-pipeline.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+indexConfigDir=/mnt/geonetwork_data/config/index/
+
+echo "Setting default pipeline to geonetwork-ui ..."
+jq '.settings.index.default_pipeline = "geonetwork-ui"' ${indexConfigDir}records.json > /tmp.json
+mv /tmp.json ${indexConfigDir}records.json