From 9441f0f3265ba2566447f8d6792d9856eb14f5f6 Mon Sep 17 00:00:00 2001 From: amandilaras Date: Thu, 16 May 2024 13:33:48 +0300 Subject: [PATCH] deploy script and elastic script changes --- deployment/deploy_opencdmp.sh | 15 +++---- deployment/docker-compose.yml | 51 ++++++++++++++++------ deployment/elk/elasticsearch/index_init.sh | 19 +++++--- 3 files changed, 56 insertions(+), 29 deletions(-) diff --git a/deployment/deploy_opencdmp.sh b/deployment/deploy_opencdmp.sh index bd4ea15b7..c5c486bb0 100644 --- a/deployment/deploy_opencdmp.sh +++ b/deployment/deploy_opencdmp.sh @@ -26,19 +26,16 @@ docker-compose pull chmod 744 ./elk/elasticsearch/index_init.sh -recreate_directories() { - echo "Resetting postgres and elasticsearch..." +if [[ $1 == "-r" ]]; then + echo "Resetting PostgreSQL and Elasticsearch storage..." sudo rm -rf ./storage/postgres/data mkdir -p ./storage/postgres/data sudo rm -rf ./storage/elasticsearch mkdir -p ./storage/elasticsearch -} - -if [[ $1 == "-r" ]]; then - recreate_directories fi +echo "Deploying Elasticsearch Container" docker-compose up -d opencdmp.elasticsearch function loading_icon() { @@ -61,7 +58,7 @@ function loading_icon() { printf " \b\n" } -loading_icon 45 "Waiting for Elasticsearch to Startup!" +loading_icon 60 "Waiting for Elasticsearch to Startup!" docker exec opencdmp.elasticsearch /usr/share/elasticsearch/config/index_init.sh @@ -73,6 +70,8 @@ loading_icon 20 "Waiting for PostgreSQL to Initialize!" docker-compose up -d opencdmp.keycloak -loading_icon 60 "Waiting for Keycloak to Startup!" +loading_icon 90 "Waiting for Keycloak to Startup!" docker-compose up -d + +loading_icon 60 "Waiting for the Backend to Startup!" diff --git a/deployment/docker-compose.yml b/deployment/docker-compose.yml index 78c1cf157..6b9e139a3 100644 --- a/deployment/docker-compose.yml +++ b/deployment/docker-compose.yml @@ -1,14 +1,20 @@ services: + ############################## PROXY ######################################## opencdmp.proxy: container_name: opencdmp.proxy image: nginx:${PROXY_TAG} depends_on: - - opencdmp.frontend - - opencdmp.backend - - opencdmp.notification - - opencdmp.annotation - # - opencdmp.keycloak + opencdmp.frontend: + condition: service_started + opencdmp.backend: + condition: service_started + opencdmp.notification: + condition: service_started + opencdmp.annotation: + condition: service_started + opencdmp.keycloak: + condition: service_started ############################## OPENDMP APP ################################# @@ -16,27 +22,41 @@ services: container_name: opencdmp.frontend image: ${DOCKER_REGISTRY}open-dmp-webapp:${MAIN_APP_TAG} depends_on: - - opencdmp.backend - - opencdmp.notification - - opencdmp.annotation + opencdmp.backend: + condition: service_started + opencdmp.notification: + condition: service_started + opencdmp.annotation: + condition: service_started opencdmp.backend: container_name: opencdmp.backend image: ${DOCKER_REGISTRY}open-dmp-api:${MAIN_APP_TAG} depends_on: - - opencdmp.postgres + opencdmp.postgres: + condition: service_started + opencdmp.keycloak: + condition: service_started opencdmp.notification: container_name: opencdmp.notification image: ${DOCKER_REGISTRY}open-dmp-notification-api:${NOTIFICATION_APP_TAG} depends_on: - - opencdmp.postgres + opencdmp.postgres: + condition: service_started + opencdmp.keycloak: + condition: service_started opencdmp.annotation: container_name: opencdmp.annotation image: ${DOCKER_REGISTRY}open-dmp-annotation-api:${ANNOTATION_APP_TAG} depends_on: - - opencdmp.postgres + opencdmp.postgres: + condition: service_started + opencdmp.keycloak: + condition: service_started + opencdmp.backend: + condition: service_started # # ############################## FILE-TRANSFORMERS ####################################### @@ -44,20 +64,23 @@ services: container_name: opencdmp.file.transformer.docx image: ${DOCKER_REGISTRY}file-transformation-docx-api:${DOCX_APP_TAG} depends_on: - - opencdmp.backend + opencdmp.backend: + condition: service_started opencdmp.file.transformer.rdajson: container_name: opencdmp.file.transformer.rdajson image: ${DOCKER_REGISTRY}file-transformation-rda-json-api:${JSON_APP_TAG} depends_on: - - opencdmp.backend + opencdmp.backend: + condition: service_started # ################################ ZENODO ############################################### opencdmp.zenodo: container_name: opencdmp.zenodo image: ${DOCKER_REGISTRY}repository-deposit-zenodo:${ZENODO_APP_TAG} depends_on: - - opencdmp.backend + opencdmp.backend: + condition: service_started ############################## POSTGRES 16 ############################################ opencdmp.postgres: diff --git a/deployment/elk/elasticsearch/index_init.sh b/deployment/elk/elasticsearch/index_init.sh index 4e84456ca..51cc11638 100644 --- a/deployment/elk/elasticsearch/index_init.sh +++ b/deployment/elk/elasticsearch/index_init.sh @@ -1,5 +1,5 @@ #!/bin/bash -echo "Elasticsearch is now available. Proceeding with initialization..." +set -e echo "Creating Elasticsearch indexes, roles, and users..." @@ -17,7 +17,7 @@ curl -XPUT "http://localhost:9200/opencdmp-plans-test" -u elastic:elastic -H 'Co "date_added": { "type": "date" } } } -}' +}' || { echo "Failed to create the 'plans' index"; exit 1; } # Command to create the "descriptions" index curl -XPUT "http://localhost:9200/opencdmp-descriptions-test" -u elastic:elastic -H 'Content-Type: application/json' -d '{ @@ -32,8 +32,9 @@ curl -XPUT "http://localhost:9200/opencdmp-descriptions-test" -u elastic:elastic "language": { "type": "keyword" } } } -}' +}' || { echo "Failed to create the 'descriptions' index"; exit 1; } +# Command to create the role curl -XPOST "localhost:9200/_security/role/opencdmp-api-test" -u elastic:elastic -H 'Content-Type: application/json' -d '{ "indices": [ { @@ -41,12 +42,16 @@ curl -XPOST "localhost:9200/_security/role/opencdmp-api-test" -u elastic:elastic "privileges": [ "all" ] } ] -}' +}' || { echo "Failed to create the role"; exit 1; } -curl -XPOST "localhost:9200/_security/user/opencdmp-api-test?pretty" -u elastic:elastic -H 'Content-Type: application/json' -d' +# Command to create the user +curl -XPOST "localhost:9200/_security/user/opencdmp-api-test?pretty" -u elastic:elastic -H 'Content-Type: application/json' -d ' { "password" : "opencdmp", "roles" : [ "opencdmp-api-test" ] -}' +}' || { echo "Failed to create the user"; exit 1; } -elasticsearch-plugin install analysis-icu \ No newline at end of file +# Install the analysis-icu plugin +elasticsearch-plugin install analysis-icu || { echo "Failed to install the analysis-icu plugin"; exit 1; } + +echo "Initialization complete."