Skip to content

Commit 33f9b36

Browse files
adds commit sha
1 parent fa6af3c commit 33f9b36

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

.github/workflows/deploy-apps.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ jobs:
2828
- name: Apply K8s manifests
2929
run: kubectl apply -f infra/k8s/items-app-deployment.yaml
3030

31+
- name: Set commit SHA env
32+
run: |
33+
kubectl set env deployment/items-app -n default COMMIT_SHA=${{ github.sha }}
34+
3135
- name: Update deployment image to current SHA
3236
run: |
3337
kubectl set image deployment/items-app items-app=ghcr.io/${{ github.repository_owner }}/items-app:sha-${{ github.sha }} -n default

apps/items-app/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ let items: Item[] = [{ id: 1, name: "first" }];
66
const PORT = Number(process.env.PORT || 8080);
77
const API_PREFIX = "/v1";
88
const APP_PREFIX = "/items";
9+
const COMMIT_SHA = process.env.COMMIT_SHA || "unknown";
910

1011
function json(data: unknown, init: ResponseInit = {}) {
1112
return new Response(JSON.stringify(data), {
@@ -29,7 +30,7 @@ const openapi = {
2930
responses: {
3031
"200": {
3132
description: "OK",
32-
content: { "application/json": { schema: { type: "object", properties: { status: { type: "string" } } } } },
33+
content: { "application/json": { schema: { type: "object", properties: { status: { type: "string" }, commit: { type: "string" } } } } },
3334
},
3435
},
3536
},
@@ -104,7 +105,7 @@ async function handle(req: Request): Promise<Response> {
104105
path = path.slice(API_PREFIX.length) || "/";
105106

106107
if (path === "/test1" && req.method === "GET") return json({ status: "test1" });
107-
if (path === "/health" && req.method === "GET") return json({ status: "ok" });
108+
if (path === "/health" && req.method === "GET") return json({ status: "ok", commit: COMMIT_SHA });
108109
if (path === "/items" && req.method === "GET") return json({ items });
109110

110111
if (path === "/items" && req.method === "POST") {

infra/k8s/items-app-deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ spec:
2525
env:
2626
- name: PORT
2727
value: "8080"
28+
- name: COMMIT_SHA
29+
value: "unknown"
2830
resources:
2931
requests:
3032
memory: "64Mi"

0 commit comments

Comments
 (0)