Add Image healthcheck. (#48)
* add support for `health` argument * add healthcheck to the image file
This commit is contained in:
parent
3574d91d9f
commit
f7c81687b5
2 changed files with 23 additions and 4 deletions
|
@ -45,3 +45,5 @@ WORKDIR /app
|
||||||
USER appuser
|
USER appuser
|
||||||
|
|
||||||
ENTRYPOINT ["/tini", "--", "/app/invidious_companion"]
|
ENTRYPOINT ["/tini", "--", "/app/invidious_companion"]
|
||||||
|
|
||||||
|
HEALTHCHECK --interval=5s --timeout=5s --start-period=10s --retries=3 CMD ["/tini", "--", "/app/invidious_companion", "healthcheck"]
|
||||||
|
|
25
src/main.ts
25
src/main.ts
|
@ -14,10 +14,28 @@ if (Deno.env.get("GET_FETCH_CLIENT_LOCATION")) {
|
||||||
) as string;
|
) as string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const args = Deno.args;
|
||||||
|
const konfigStore = await konfigLoader();
|
||||||
|
const host = Deno.env.get("HOST") || konfigStore.get("server.host") as string;
|
||||||
|
const port = Deno.env.get("PORT") || konfigStore.get("server.port") as string;
|
||||||
|
|
||||||
|
if (args?.[0] == "healthcheck") {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`http://${host}:${port}/healthz`);
|
||||||
|
if (response.status === 200) {
|
||||||
|
Deno.exit(0);
|
||||||
|
} else {
|
||||||
|
Deno.exit(1);
|
||||||
|
}
|
||||||
|
} catch (_) {
|
||||||
|
Deno.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const { getFetchClient } = await import(getFetchClientLocation);
|
const { getFetchClient } = await import(getFetchClientLocation);
|
||||||
|
|
||||||
const app = new Hono();
|
const app = new Hono();
|
||||||
const konfigStore = await konfigLoader();
|
|
||||||
|
|
||||||
let innertubeClient: Innertube;
|
let innertubeClient: Innertube;
|
||||||
let innertubeClientFetchPlayer = true;
|
let innertubeClientFetchPlayer = true;
|
||||||
|
@ -116,7 +134,6 @@ app.use("*", async (c, next) => {
|
||||||
routes(app, konfigStore);
|
routes(app, konfigStore);
|
||||||
|
|
||||||
Deno.serve({
|
Deno.serve({
|
||||||
port: Number(Deno.env.get("PORT")) ||
|
port: Number(port),
|
||||||
konfigStore.get("server.port") as number,
|
hostname: host,
|
||||||
hostname: Deno.env.get("HOST") || konfigStore.get("server.host") as string,
|
|
||||||
}, app.fetch);
|
}, app.fetch);
|
||||||
|
|
Reference in a new issue