From 56c7e43c4e2e52803750e3e0c2a551b38153e031 Mon Sep 17 00:00:00 2001 From: Alfredo Oliviero Date: Tue, 25 Jun 2024 17:07:48 +0200 Subject: [PATCH] deploy script can deploy to dev, pre, prod --- deploy.sh | 67 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/deploy.sh b/deploy.sh index 407e7ba..c36b664 100755 --- a/deploy.sh +++ b/deploy.sh @@ -1,35 +1,54 @@ -# VERSION=1.0.0-snapshot +#!/bin/bash -# MVN_VERSION=$(mvn -q \ -# -Dexec.executable=echo \ -# -Dexec.args='${project.version}' \ -# --non-recursive \ -# exec:exec) -# echo "MVN_VERSION=${MVN_VERSION}" +set -e -# 10.1.30.156 -DEST_HOST=lr62-dev -# DEST_HOST=lr62-prod-01 -# DEST_HOST=lr62-prod-02 +# Define server arrays for different environments +SERVERS_PRE=("lr62-pre-01" "lr62-pre-02") +SERVERS_PROD=("lr62-prod-01" "lr62-prod-02") +SERVERS_DEV=("lr62-dev") +# Set default deployment environment to 'dev', can override with 'pre' or 'prod' +ENVIRONMENT=${1:-dev} + +# Select the appropriate server array based on the environment +case "$ENVIRONMENT" in + pre) + SERVERS=("${SERVERS_PRE[@]}") + ;; + prod) + SERVERS=("${SERVERS_PROD[@]}") + ;; + *) + SERVERS=("${SERVERS_DEV[@]}") + ;; +esac + +echo "Selected environment: $ENVIRONMENT" +echo "Deploying to servers: ${SERVERS[*]}" + +# Retrieve Maven project name MVN_NAME=$(mvn -q \ - -Dexec.executable=echo \ - -Dexec.args='${project.artifactId}' \ - --non-recursive \ - exec:exec) + -Dexec.executable=echo \ + -Dexec.args='${project.artifactId}' \ + --non-recursive \ + exec:exec) echo "MVN_NAME=${MVN_NAME}" +# Retrieve Maven final name of the build artifact MVN_FINALNAME=$(mvn -q \ - -Dexec.executable=echo \ - -Dexec.args='${project.build.finalName}' \ - --non-recursive \ - exec:exec) - + -Dexec.executable=echo \ + -Dexec.args='${project.build.finalName}' \ + --non-recursive \ + exec:exec) echo "MVN_FINALNAME=${MVN_FINALNAME}" + +# Execute Maven clean and package mvn clean package -scp target/$MVN_FINALNAME.war life@$DEST_HOST:/home/life/Portal-Bundle/deploy/$MVN_NAME.war - -ssh $DEST_HOST "sudo journalctl -fl -u liferay" - +# Deploy to each server in the selected list +for HOST in "${SERVERS[@]}"; do + scp target/$MVN_FINALNAME.war life@$HOST:/home/life/Portal-Bundle/deploy/$MVN_NAME.war +done +# Tail log from the last server in the list +ssh $HOST "sudo journalctl -fl -u liferay"