Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ jobs:
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7.0.0
with:
context: .
build-args: |
GIT_SHA=${{ github.sha }}
platforms: ${{ github.event_name == 'pull_request' && 'linux/amd64' || 'linux/amd64,linux/arm64' }}
push: ${{ github.event_name != 'pull_request' }}
load: ${{ github.event_name == 'pull_request' }}
Expand Down
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ HEALTHCHECK --interval=60s --timeout=3s --start-period=30s --retries=3 \
ENV NODE_ENV=production
EXPOSE 3000

# Bake the git SHA into the image so the running app can report which commit it was built from.
# Passed at build time by CI (build-args: GIT_SHA=${{ github.sha }}); defaults to "unknown" for local builds.
ARG GIT_SHA=unknown
ENV GIT_SHA=${GIT_SHA}

# set the user to non-root (node)
USER node

Expand Down
3 changes: 3 additions & 0 deletions src/config/app-config.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export interface EntraIdConfig {

export interface AppConfig {
env: AppEnv;
build: {
gitSha: string;
};
frontend: {
port: number;
url: string;
Expand Down
3 changes: 3 additions & 0 deletions src/config/envs/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const DEFAULT_TIMEOUT_MS = 2500;
export const getDefaultConfig = (): AppConfig => {
return {
env: AppEnv.Default, // MUST be overridden by other configs
build: {
gitSha: process.env.GIT_SHA || 'unknown'
},
frontend: {
port: parseInt(process.env.FRONTEND_PORT || '3000', 10),
url: process.env.FRONTEND_URL!
Expand Down
2 changes: 1 addition & 1 deletion src/routes/healthcheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const checkConnections = async (req: Request, res: Response): Promise<void> => {
};

healthcheck.get('/', (_req: Request, res: Response) => {
res.json({ message: 'success' }); // server is up
res.json({ message: 'success', gitSha: config.build.gitSha }); // server is up
});

healthcheck.get('/ready', checkConnections); // server is up and has active connections to dependencies
Expand Down
5 changes: 4 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ Promise.resolve()
})
.then(() => {
app.listen(PORT, async () => {
logger.info(`Server is running on port ${PORT}`);
logger.info(
{ event: 'app_boot', gitSha: config.build.gitSha, appEnv: config.env, port: PORT },
`Server is running on port ${PORT}`
);
});
})
.catch(async (err) => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/routes/healthcheck.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Healthcheck', () => {
test('/healthcheck/ returns success', async () => {
const res = await request(app).get('/healthcheck/');
expect(res.status).toBe(200);
expect(res.body).toEqual({ message: 'success' });
expect(res.body).toEqual({ message: 'success', gitSha: 'unknown' });
Comment thread
wheelsandcogs marked this conversation as resolved.
});
});

Expand Down
Loading