File tree Expand file tree Collapse file tree 4 files changed +90
-0
lines changed
Expand file tree Collapse file tree 4 files changed +90
-0
lines changed Original file line number Diff line number Diff line change 7979 vuln-type : ' os,library'
8080 severity : ' CRITICAL,HIGH' # Only fail on Critical and High issues
8181
82+ # --- NEW STEP: Run Smoke Tests ---
83+ - name : Start Services and Run Smoke Tests
84+ run : |
85+ # Create a network
86+ docker network create smoke-test-net
87+
88+ # Start MongoDB
89+ docker run -d --name mongodb --network smoke-test-net \
90+ mongo:6-jammy
91+
92+ # Wait a bit for MongoDB
93+ sleep 10
94+
95+ # Start App
96+ docker run -d --name app --network smoke-test-net \
97+ -e SERVER_PORT=8080 \
98+ -e MONGODB_URI=mongodb://mongodb:27017/CSO2_product_catalogue_service \
99+ -p 8080:8080 \
100+ local-image-scan:latest
101+
102+ # Run smoke test script
103+ chmod +x ./scripts/smoke-test.sh
104+ ./scripts/smoke-test.sh http://localhost:8080
105+
106+ # Cleanup
107+ docker stop app mongodb
108+ docker rm app mongodb
109+ docker network rm smoke-test-net
110+
82111 - name : Log in to GHCR
83112 uses : docker/login-action@v3
84113 with :
Original file line number Diff line number Diff line change 4545 <scope >runtime</scope >
4646 <optional >true</optional >
4747 </dependency >
48+ <dependency >
49+ <groupId >org.springframework.boot</groupId >
50+ <artifactId >spring-boot-starter-actuator</artifactId >
51+ </dependency >
4852 </dependencies >
4953
5054 <build >
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ # Configuration
4+ SERVICE_URL=${1:- " http://localhost:8080" }
5+ MAX_RETRIES=30
6+ SLEEP_INTERVAL=5
7+
8+ echo " Starting smoke tests against $SERVICE_URL ..."
9+
10+ # Function to check health
11+ check_health () {
12+ local url=" $1 /actuator/health"
13+
14+ # Get HTTP response code and body
15+ local response=$( curl -s -w " \n%{http_code}" " $url " )
16+ local body=$( echo " $response " | sed ' $d' )
17+ local http_code=$( echo " $response " | tail -n1)
18+
19+ if [ " $http_code " == " 200" ]; then
20+ # Check if status is UP
21+ if echo " $body " | grep -q ' "status":"UP"' ; then
22+ return 0
23+ else
24+ echo " Health check returned 200 but status is not UP: $body "
25+ return 1
26+ fi
27+ else
28+ echo " Health check returned HTTP $http_code "
29+ return 1
30+ fi
31+ }
32+
33+ # Wait for service to be ready
34+ echo " Waiting for service to be up..."
35+ for (( i= 1 ; i<= MAX_RETRIES; i++ )) ; do
36+ if check_health " $SERVICE_URL " ; then
37+ echo " ✅ Service is UP and healthy!"
38+
39+ # Print health details
40+ echo " Health endpoint response:"
41+ curl -s " $SERVICE_URL /actuator/health" | head -c 500
42+ echo " "
43+
44+ exit 0
45+ fi
46+ echo " Attempt $i /$MAX_RETRIES : Service not ready yet... waiting ${SLEEP_INTERVAL} s"
47+ sleep $SLEEP_INTERVAL
48+ done
49+
50+ echo " ❌ Service failed to start within timeout."
51+ echo " Final health check attempt:"
52+ curl -s " $SERVICE_URL /actuator/health" || echo " Could not reach service"
53+ exit 1
Original file line number Diff line number Diff line change @@ -3,3 +3,7 @@ server.port=${SERVER_PORT:8082}
33
44# MongoDB Configuration (override via env vars in production)
55spring.data.mongodb.uri =${MONGODB_URI:mongodb://localhost:27017/CSO2_product_catalogue_service}
6+
7+ # Actuator Configuration
8+ management.endpoints.web.exposure.include =health,info
9+ management.endpoint.health.show-details =always
You can’t perform that action at this time.
0 commit comments