deploy script can deploy to dev, pre, prod

This commit is contained in:
Alfredo Oliviero 2024-06-25 17:07:48 +02:00
parent c4a3b51339
commit 56c7e43c4e
1 changed files with 43 additions and 24 deletions

View File

@ -1,35 +1,54 @@
# VERSION=1.0.0-snapshot #!/bin/bash
# MVN_VERSION=$(mvn -q \ set -e
# -Dexec.executable=echo \
# -Dexec.args='${project.version}' \
# --non-recursive \
# exec:exec)
# echo "MVN_VERSION=${MVN_VERSION}"
# 10.1.30.156 # Define server arrays for different environments
DEST_HOST=lr62-dev SERVERS_PRE=("lr62-pre-01" "lr62-pre-02")
# DEST_HOST=lr62-prod-01 SERVERS_PROD=("lr62-prod-01" "lr62-prod-02")
# DEST_HOST=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 \ MVN_NAME=$(mvn -q \
-Dexec.executable=echo \ -Dexec.executable=echo \
-Dexec.args='${project.artifactId}' \ -Dexec.args='${project.artifactId}' \
--non-recursive \ --non-recursive \
exec:exec) exec:exec)
echo "MVN_NAME=${MVN_NAME}" echo "MVN_NAME=${MVN_NAME}"
# Retrieve Maven final name of the build artifact
MVN_FINALNAME=$(mvn -q \ MVN_FINALNAME=$(mvn -q \
-Dexec.executable=echo \ -Dexec.executable=echo \
-Dexec.args='${project.build.finalName}' \ -Dexec.args='${project.build.finalName}' \
--non-recursive \ --non-recursive \
exec:exec) exec:exec)
echo "MVN_FINALNAME=${MVN_FINALNAME}" echo "MVN_FINALNAME=${MVN_FINALNAME}"
# Execute Maven clean and package
mvn clean package mvn clean package
scp target/$MVN_FINALNAME.war life@$DEST_HOST:/home/life/Portal-Bundle/deploy/$MVN_NAME.war # Deploy to each server in the selected list
for HOST in "${SERVERS[@]}"; do
ssh $DEST_HOST "sudo journalctl -fl -u liferay" 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"