Skip to content

Commit 8bce436

Browse files
committed
feat: add health check endpoints for API readiness and health status
1 parent f95a82a commit 8bce436

4 files changed

Lines changed: 112 additions & 1 deletion

File tree

.github/workflows/release-cd.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Release CD Version
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
VERSION:
7+
description: "The version of the Helm chart to release"
8+
required: true
9+
type: string
10+
11+
env:
12+
OPS_REPO: kopexa-grc/envs
13+
IMAGE_NAME: ghcr.io/kopexa-grc/docs
14+
DOCKER_PLATFORM: linux/amd64
15+
16+
permissions:
17+
contents: read
18+
19+
jobs:
20+
publish:
21+
runs-on: ubuntu-latest
22+
permissions:
23+
packages: write
24+
contents: read
25+
steps:
26+
- name: Harden the runner (Audit all outbound calls)
27+
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
28+
with:
29+
egress-policy: audit
30+
31+
- name: Checkout repository
32+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
33+
34+
- name: Validate input version
35+
env:
36+
INPUT_VERSION: ${{ inputs.VERSION }}
37+
run: |
38+
set -euo pipefail
39+
# Validate input version format (expects clean semver without 'v' prefix)
40+
if [[ ! "$INPUT_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?(\+[a-zA-Z0-9.-]+)?$ ]]; then
41+
echo "❌ Error: Invalid version format. Must be clean semver (e.g., 1.2.3, 1.2.3-alpha)"
42+
echo "Expected: clean version without 'v' prefix"
43+
echo "Provided: $INPUT_VERSION"
44+
exit 1
45+
fi
46+
47+
# Store validated version in environment variable
48+
echo "VERSION<<EOF" >> $GITHUB_ENV
49+
echo "$INPUT_VERSION"
50+
51+
- name: Trigger GitOps Update (dev)
52+
uses: peter-evans/repository-dispatch@v3
53+
with:
54+
token: ${{ secrets.KOPEXA_CLOUD_REPO_ACCESS_TOKEN }}
55+
repository: ${{ env.OPS_REPO }}
56+
event-type: update-docs-image
57+
client-payload: '{"image": "${{ env.IMAGE_NAME }}:${{ inputs.VERSION }}", "environment": "platform-iac"}'

.github/workflows/release.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,13 @@ jobs:
1717
uses: ./.github/workflows/release-docker-github.yml
1818
secrets: inherit
1919
with:
20-
IS_PRERELEASE: ${{ github.event.release.prerelease }}
20+
IS_PRERELEASE: ${{ github.event.release.prerelease }}
21+
22+
devops-release:
23+
name: Push Tag to DevOps
24+
uses: ./.github/workflows/release-cd.yml
25+
secrets: inherit
26+
needs:
27+
- docker-build
28+
with:
29+
VERSION: ${{ needs.docker-build.outputs.VERSION }}

src/app/api/healthz/route.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { NextRequest } from "next/server";
2+
3+
export const dynamic = "force-dynamic";
4+
5+
export function GET(_req: NextRequest) {
6+
return new Response("ok", {
7+
status: 200,
8+
headers: {
9+
"content-type": "text/plain; charset=utf-8",
10+
"cache-control": "no-store",
11+
},
12+
});
13+
}
14+
15+
export function HEAD(_req: NextRequest) {
16+
return new Response(null, {
17+
status: 200,
18+
headers: {
19+
"cache-control": "no-store",
20+
},
21+
});
22+
}

src/app/api/readyz/route.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { NextRequest } from "next/server";
2+
3+
export const dynamic = "force-dynamic";
4+
5+
// In the future, add checks here (e.g., required env vars, ability to read content directory)
6+
export function GET(_req: NextRequest) {
7+
return new Response("ready", {
8+
status: 200,
9+
headers: {
10+
"content-type": "text/plain; charset=utf-8",
11+
"cache-control": "no-store",
12+
},
13+
});
14+
}
15+
16+
export function HEAD(_req: NextRequest) {
17+
return new Response(null, {
18+
status: 200,
19+
headers: {
20+
"cache-control": "no-store",
21+
},
22+
});
23+
}

0 commit comments

Comments
 (0)