Skip to content

Commit

Permalink
feat: add docker healthchecks to server and ml (#9583)
Browse files Browse the repository at this point in the history
* add healthcheck

* format, import, IMMICH_PORT, and eslint change

* chore: clean up nodejs healthcheck

* fix ruff formating

* add healthcheck

* format, import, IMMICH_PORT, and eslint change

* chore: clean up nodejs healthcheck

* fix ruff formating

* add healthcheck to dockerfile

* poetry run ruff check --fix

* removed 2 of 3 console calls

---------

Co-authored-by: Jason Rasmussen <[email protected]>
  • Loading branch information
CodaBool and jrasm91 authored May 22, 2024
1 parent f6f82a5 commit 6a4c2e9
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions machine-learning/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,5 @@ COPY start.sh log_conf.json ./
COPY app .
ENTRYPOINT ["tini", "--"]
CMD ["./start.sh"]

HEALTHCHECK CMD python3 healthcheck.py
14 changes: 14 additions & 0 deletions machine-learning/app/healthcheck.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
import sys

import requests

port = os.getenv("IMMICH_PORT", 3003)

try:
response = requests.get(f"http://localhost:{port}/ping", timeout=2)
if response.status_code == 200:
sys.exit(0)
sys.exit(1)
except requests.RequestException:
sys.exit(1)
2 changes: 2 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ VOLUME /usr/src/app/upload
EXPOSE 3001
ENTRYPOINT ["tini", "--", "/bin/bash"]
CMD ["start.sh"]

HEALTHCHECK CMD npm run healthcheck
1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"check": "tsc --noEmit",
"check:code": "npm run format && npm run lint && npm run check",
"check:all": "npm run check:code && npm run test:cov",
"healthcheck": "node ./dist/utils/healthcheck.js",
"test": "vitest",
"test:watch": "vitest --watch",
"test:cov": "vitest --coverage",
Expand Down
29 changes: 29 additions & 0 deletions server/src/utils/healthcheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env node
const port = Number(process.env.IMMICH_PORT) || 3001;
const controller = new AbortController();

const main = async () => {
const timeout = setTimeout(() => controller.abort(), 2000);
try {
const response = await fetch(`http://localhost:${port}/api/server-info/ping`, {
signal: controller.signal,
});

if (response.ok) {
const body = await response.json();
if (body.res === 'pong') {
process.exit();
}
}
} catch (error) {
if (error instanceof DOMException === false) {
console.error(error);
}
} finally {
clearTimeout(timeout);
}

process.exit(1);
};

void main();

0 comments on commit 6a4c2e9

Please sign in to comment.