mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-21 15:25:49 +00:00
Update maven-build.yml
This commit is contained in:
parent
1b8005fc24
commit
592ff9743a
1 changed files with 25 additions and 17 deletions
40
.github/workflows/maven-build.yml
vendored
40
.github/workflows/maven-build.yml
vendored
|
@ -22,6 +22,7 @@ jobs:
|
||||||
else
|
else
|
||||||
echo "Git is already installed."
|
echo "Git is already installed."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Check for Docker
|
- name: Check for Docker
|
||||||
run: |
|
run: |
|
||||||
if ! command -v docker &> /dev/null
|
if ! command -v docker &> /dev/null
|
||||||
|
@ -34,6 +35,7 @@ jobs:
|
||||||
else
|
else
|
||||||
echo "Docker is already installed."
|
echo "Docker is already installed."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Check for Maven
|
- name: Check for Maven
|
||||||
run: |
|
run: |
|
||||||
if ! command -v mvn &> /dev/null
|
if ! command -v mvn &> /dev/null
|
||||||
|
@ -44,6 +46,7 @@ jobs:
|
||||||
else
|
else
|
||||||
echo "Maven is already installed."
|
echo "Maven is already installed."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Validate Installation
|
- name: Validate Installation
|
||||||
run: |
|
run: |
|
||||||
echo "Validating installation..."
|
echo "Validating installation..."
|
||||||
|
@ -57,6 +60,7 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Build with Maven
|
- name: Build with Maven
|
||||||
run: ./mvnw -B package
|
run: ./mvnw -B package
|
||||||
|
|
||||||
|
@ -66,6 +70,7 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: ./mvnw test
|
run: ./mvnw test
|
||||||
|
|
||||||
|
@ -93,26 +98,29 @@ jobs:
|
||||||
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
|
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
|
||||||
chmod 600 ~/.ssh/id_rsa
|
chmod 600 ~/.ssh/id_rsa
|
||||||
ssh-keyscan -H $DEPLOY_SERVER >> ~/.ssh/known_hosts || true
|
ssh-keyscan -H $DEPLOY_SERVER >> ~/.ssh/known_hosts || true
|
||||||
|
|
||||||
- name: Deploy application
|
- name: Deploy application
|
||||||
env:
|
env:
|
||||||
DEPLOY_SERVER: '192.168.1.199'
|
DEPLOY_SERVER: 192.168.10.11
|
||||||
DEPLOY_PORT: '8080'
|
DEPLOY_PORT: 8080
|
||||||
DEPLOY_USER: 'aiman'
|
DEPLOY_USER: aiman
|
||||||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
run: |
|
run: |
|
||||||
echo "Deploying application to $DEPLOY_SERVER"
|
echo "Deploying application to $DEPLOY_SERVER"
|
||||||
|
# Create deployment directory if it doesn't exist
|
||||||
|
ssh -i ~/.ssh/id_rsa $DEPLOY_USER@$DEPLOY_SERVER "mkdir -p /home/aiman/deployments/"
|
||||||
|
|
||||||
|
# Copy JAR file
|
||||||
scp -i ~/.ssh/id_rsa /home/aiman/Documents/spring-petclinic/target/spring-petclinic-3.3.0-SNAPSHOT.jar $DEPLOY_USER@$DEPLOY_SERVER:/home/aiman/deployments/
|
scp -i ~/.ssh/id_rsa /home/aiman/Documents/spring-petclinic/target/spring-petclinic-3.3.0-SNAPSHOT.jar $DEPLOY_USER@$DEPLOY_SERVER:/home/aiman/deployments/
|
||||||
ssh -i ~/.ssh/id_rsa $DEPLOY_USER@$DEPLOY_SERVER "nohup java -jar /home/aiman/deployments/spring-petclinic-3.3.0-SNAPSHOT.jar > /dev/null 2>&1 &"
|
|
||||||
rm -f ~/.ssh/id_rsa
|
# Ensure the JAR file exists and start the application
|
||||||
- name: Wait for application to start
|
ssh -i ~/.ssh/id_rsa $DEPLOY_USER@$DEPLOY_SERVER "
|
||||||
run: |
|
if [ -f /home/aiman/deployments/spring-petclinic-3.3.0-SNAPSHOT.jar ]; then
|
||||||
echo "Waiting for application to start..."
|
nohup java -jar /home/aiman/deployments/spring-petclinic-3.3.0-SNAPSHOT.jar > /dev/null 2>&1 &
|
||||||
for i in {1..30}; do
|
|
||||||
if curl -s http://192.168.1.199:8080 > /dev/null; then
|
|
||||||
echo "Application is up!"
|
|
||||||
break
|
|
||||||
else
|
else
|
||||||
echo "Application is not up yet, retrying in 10 seconds..."
|
echo 'JAR file not found!';
|
||||||
sleep 10
|
exit 1;
|
||||||
fi
|
fi"
|
||||||
done
|
|
||||||
|
# Clean up private key
|
||||||
|
rm -f ~/.ssh/id_rsa
|
||||||
|
|
Loading…
Reference in a new issue