Skip to content

Commit 49c3f1f

Browse files
committed
chore(deploy): implements Health Checker
1 parent 61fb8ec commit 49c3f1f

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

.github/workflows/cd.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,12 @@ jobs:
7070
ssh -i ~/.ssh/ec2.pem \
7171
${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} \
7272
"sudo systemctl restart ${{ secrets.SERVICE_NAME }}"
73+
74+
# ============================
75+
# HEALTH CHECK
76+
# ============================
77+
- name: Health check
78+
run: |
79+
echo "Waiting application startup..."
80+
sleep 10
81+
curl -f http://${{ secrets.EC2_HOST }}:8080/health
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.github.renancvitor.inventory.infra.observability;
2+
3+
import java.time.OffsetDateTime;
4+
import java.util.HashMap;
5+
import java.util.Map;
6+
7+
import org.springframework.beans.factory.annotation.Value;
8+
import org.springframework.http.ResponseEntity;
9+
import org.springframework.web.bind.annotation.GetMapping;
10+
import org.springframework.web.bind.annotation.RequestMapping;
11+
import org.springframework.web.bind.annotation.RestController;
12+
13+
@RestController
14+
@RequestMapping("/health")
15+
public class HealthController {
16+
17+
@Value("${app.name}")
18+
private String application;
19+
20+
@Value("${app.version}")
21+
private String version;
22+
23+
@Value("${app.environment.default}")
24+
private String environment;
25+
26+
@GetMapping
27+
public ResponseEntity<Map<String, Object>> healthCheck() {
28+
Map<String, Object> response = new HashMap<>();
29+
30+
response.put("status", "UP");
31+
response.put("application", application);
32+
response.put("version", version);
33+
response.put("environment", environment);
34+
response.put("timestamp", OffsetDateTime.now().toString());
35+
36+
return ResponseEntity.ok(response);
37+
}
38+
39+
}

src/main/resources/application-dev.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ messaging:
1616
outbox:
1717
scheduler:
1818
enabled: true
19+
20+
app:
21+
environment: development

src/main/resources/application-prod.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ app:
2626
mail:
2727
sender: ${APP_MAIL_SENDER}
2828
recipient: ${APP_MAIL_RECIPIENT}
29+
environment: production

src/main/resources/application.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ logging:
2323
security:
2424
token:
2525
secret: ${JWT_SECRET}
26+
27+
app:
28+
name: Inventory Notification System Backend
29+
version: 1.0.0

0 commit comments

Comments
 (0)