2024-06-25 17:07:48 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# 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
|
2024-05-28 14:11:10 +02:00
|
|
|
MVN_NAME=$(mvn -q \
|
2024-06-25 17:07:48 +02:00
|
|
|
-Dexec.executable=echo \
|
|
|
|
-Dexec.args='${project.artifactId}' \
|
|
|
|
--non-recursive \
|
|
|
|
exec:exec)
|
2024-05-28 14:11:10 +02:00
|
|
|
echo "MVN_NAME=${MVN_NAME}"
|
|
|
|
|
2024-06-25 17:07:48 +02:00
|
|
|
# Retrieve Maven final name of the build artifact
|
2024-05-28 14:11:10 +02:00
|
|
|
MVN_FINALNAME=$(mvn -q \
|
2024-06-25 17:07:48 +02:00
|
|
|
-Dexec.executable=echo \
|
|
|
|
-Dexec.args='${project.build.finalName}' \
|
|
|
|
--non-recursive \
|
|
|
|
exec:exec)
|
2024-05-28 14:11:10 +02:00
|
|
|
echo "MVN_FINALNAME=${MVN_FINALNAME}"
|
|
|
|
|
2024-06-25 17:07:48 +02:00
|
|
|
# Execute Maven clean and package
|
|
|
|
mvn clean package
|
2024-05-28 14:11:10 +02:00
|
|
|
|
2024-06-25 17:07:48 +02:00
|
|
|
# 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
|
2024-05-28 14:11:10 +02:00
|
|
|
|
2024-06-25 17:07:48 +02:00
|
|
|
# Tail log from the last server in the list
|
|
|
|
ssh $HOST "sudo journalctl -fl -u liferay"
|