Skip to content

Commit

Permalink
Payment Synchronous communication and Security Configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
NibrasAmmar01 committed Dec 24, 2024
2 parents 1368650 + d231d92 commit 94a983b
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 4 deletions.
101 changes: 101 additions & 0 deletions .github/workflows/order-ci-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
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: 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 if the correct JAR file exists
run: |
ls *.jar || (echo "JAR file not found!" && exit 1)
- 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 order.jar \
${{ secrets.DEPLOYMENT_MACHINE_USER }}@${{ secrets.DEPLOYMENT_MACHINE_IP }}:~/order/order.jar
- name: Verify if the JAR file exists on the VPS
run: |
sshpass -p "${{ secrets.DEPLOYMENT_MACHINE_USER_PSW }}" ssh ${{ secrets.DEPLOYMENT_MACHINE_USER }}@${{ secrets.DEPLOYMENT_MACHINE_IP }} \
"ls -l ~/order/order.jar"
- name: Show system resources usage after file transfer
run: |
sshpass -p "${{ secrets.DEPLOYMENT_MACHINE_USER_PSW }}" ssh ${{ secrets.DEPLOYMENT_MACHINE_USER }}@${{ secrets.DEPLOYMENT_MACHINE_IP }} \
"df -h && free -h && top -bn1 | grep 'Cpu(s)'"
- 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: |
sleep 10
echo "Starting Spring Boot service..."
cd ~/order
nohup java -jar order.jar --server.port=8083 > order.log 2>&1 &
echo "Spring Boot service deployed successfully!"
sleep 30
echo "Performing health check..."
curl -X 'GET' 'http://localhost:8083/actuator/health' -H 'accept: application/json' || (echo "Service health check failed!" && exit 1)
echo "Service deployed and healthy!"
tail -n 50 ~/order/order.log
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public PaymentService(WebClient.Builder webClientBuilder) {
public PaymentResponseDTO processPayment(List<CartItem> cartItems, @NotNull PaymentRequestDTO paymentRequestDTO) {

cartResponse pricingResponse = pricingService.checkPrice(cartItems);
BigDecimal totalAmount = pricingResponse.getTotalAfterDiscount();
BigDecimal totalAmount = pricingResponse.getTotalBeforeDiscount();


paymentRequestDTO.setAmount(totalAmount);
Expand Down
7 changes: 4 additions & 3 deletions order/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ spring:
datasource:
url: jdbc:postgresql://localhost:5437/db_order
username: postgres
password: fadizoe1212
password: nebras2001
driver-class-name: org.postgresql.Driver
jpa:
hibernate:
Expand All @@ -24,10 +24,11 @@ spring:
cors:
enabled: true
origins: "*"

logging:
level:
org:
flywaydb : DEBUG
flywaydb: DEBUG

server:
port: 8084
port: 8084

0 comments on commit 94a983b

Please sign in to comment.