Skip to content

Commit

Permalink
Update gradle.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
DongJun1110 authored Aug 27, 2024
1 parent 2500c1b commit 8d54807
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,40 @@ jobs:
PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
HOSTNAME: ${{ secrets.SERVER_IP }}
USER_NAME: ${{ secrets.SSH_USERNAME }}

run: |
echo "$PRIVATE_KEY" > private_key && chmod 600 private_key
ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} '
# Navigate to the application directory
cd /home/ubuntu/FOREGG_SERVER &&
echo "$PRIVATE_KEY" > private_key
chmod 600 private_key
ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} << 'EOF'
# Navigate to the application directory
cd /home/ubuntu/FOREGG_SERVER ||
{ echo "Failed to navigate to directory"; exit 1; }
# Fetch the latest code
git checkout main &&
git fetch --all &&
git reset --hard origin/main &&
git pull origin main &&
git pull origin main ||
{ echo "Failed to update code"; exit 1; }
# Build the Spring application using Gradle
./gradlew clean build &&
./gradlew clean build ||
{ echo "Gradle build failed"; exit 1; }
# Find the process ID (PID) using port 8080 and kill it
PID=$(sudo netstat -tnlp | grep ":8080" | awk \'{print $7}\' | cut -d/ -f1) &&
PID=$(sudo netstat -tnlp | grep ":8080" | awk '{print $7}' | cut -d/ -f1) &&
if [ -n "$PID" ]; then
echo "Stopping process with PID $PID" &&
sudo kill -9 $PID
else
echo "No process found on port 8080"
fi &&
fi ||
{ echo "Failed to stop old process"; exit 1; }
# Replace the old JAR with the new one
sudo cp build/libs/*.jar /cicd &&
sudo cp build/libs/*.jar /cicd ||
{ echo "Failed to copy JAR file"; exit 1; }
# Start the application again
nohup java -jar /cicd/*.jar > /dev/null 2>&1 &
'
EOF

0 comments on commit 8d54807

Please sign in to comment.