Skip to content

Deleting the old delivery event consumer #30

Deleting the old delivery event consumer

Deleting the old delivery event consumer #30

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches:
- order
pull_request:
branches:
- order
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '17'
- name: Build with Maven
run: |
cd order/
mvn clean package -DskipTests -Djava.version=17
- name: Debug Maven Build Output
run: ls -l order/target/
- name: Archive JAR Artifact
uses: actions/upload-artifact@v3
with:
name: order.jar
path: order/target/*.jar
deploy:
runs-on: ubuntu-latest
needs: build
timeout-minutes: 30
steps:
- name: Install sshpass
run: sudo apt-get install -y sshpass
- name: Download JAR Artifact
uses: actions/download-artifact@v3
with:
name: order.jar
path: ./
- name: Verify Downloaded JAR File
run: |
echo "Listing JAR files in the workspace:"
ls -l *.jar
- name: Dynamically Set JAR Filename
id: find_jar
run: echo "::set-output name=JAR_NAME::$(ls *.jar)"
- name: Add Server to Known Hosts
run: |
mkdir -p ~/.ssh
ssh-keyscan -H ${{ secrets.DEPLOYMENT_MACHINE_IP }} >> ~/.ssh/known_hosts
- name: Create Destination Directory on VPS
run: |
sshpass -p "${{ secrets.DEPLOYMENT_MACHINE_USER_PSW }}" ssh ${{ secrets.DEPLOYMENT_MACHINE_USER }}@${{ secrets.DEPLOYMENT_MACHINE_IP }} \
"mkdir -p ~/order"
- name: Transfer JAR to VPS
run: |
sshpass -p "${{ secrets.DEPLOYMENT_MACHINE_USER_PSW }}" scp ${{ steps.find_jar.outputs.JAR_NAME }} \
${{ secrets.DEPLOYMENT_MACHINE_USER }}@${{ secrets.DEPLOYMENT_MACHINE_IP }}:~/order/order.jar
- name: Kill Process on Port 8084 (if any)
run: |
sshpass -p "${{ secrets.DEPLOYMENT_MACHINE_USER_PSW }}" ssh ${{ secrets.DEPLOYMENT_MACHINE_USER }}@${{ secrets.DEPLOYMENT_MACHINE_IP }} \
"fuser -k 8084/tcp || echo 'No process on port 8084'"
- name: Deploy JAR to VPS
uses: appleboy/ssh-action@v0.1.2
with:
host: ${{ secrets.DEPLOYMENT_MACHINE_IP }}
username: ${{ secrets.DEPLOYMENT_MACHINE_USER }}
password: ${{ secrets.DEPLOYMENT_MACHINE_USER_PSW }}
script: |
echo "Starting Spring Boot service..."
cd ~/order
nohup java -jar order.jar --server.port=8084 > order.log 2>&1 &
echo "Spring Boot service deployed successfully!"
sleep 30
echo "Performing health check..."
curl -X 'GET' 'http://localhost:8084/api' -H 'accept: application/json' || (echo "Service health check failed!" && exit 1)
echo "Service deployed and healthy!"
tail -n 50 ~/order/order.log