Update healthcheck
This commit is contained in:
parent
be66b16a08
commit
4b0253f211
@ -1,5 +1,11 @@
|
|||||||
FROM node:lts-slim
|
FROM node:lts-slim
|
||||||
|
|
||||||
|
# Install wget for healthcheck
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get install -y wget && \
|
||||||
|
apt-get clean && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY app/ ./
|
COPY app/ ./
|
||||||
@ -21,6 +27,6 @@ ENV NODE_ENV=production
|
|||||||
# Type checking is done in the repo before building the image.
|
# Type checking is done in the repo before building the image.
|
||||||
RUN npx tsc --noCheck
|
RUN npx tsc --noCheck
|
||||||
|
|
||||||
HEALTHCHECK --interval=30s --start-period=10s --timeout=5s CMD node /app/healthcheck.js || exit 1
|
HEALTHCHECK --interval=30s --start-period=10s --timeout=5s CMD wget -q http://localhost:3000/healthcheck || exit 1
|
||||||
|
|
||||||
CMD ["pm2-runtime", "dist/index.js" ]
|
CMD ["pm2-runtime", "dist/index.js" ]
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
(async () => {
|
|
||||||
try {
|
|
||||||
const res = await fetch('http://localhost:3000/healthcheck')
|
|
||||||
if (await res.text() === 'ok') {
|
|
||||||
process.exit(0)
|
|
||||||
}
|
|
||||||
} catch (e) { }
|
|
||||||
process.exit(1)
|
|
||||||
})()
|
|
@ -11,17 +11,21 @@ class Immich {
|
|||||||
* the possible attack surface of this app.
|
* the possible attack surface of this app.
|
||||||
*/
|
*/
|
||||||
async request (endpoint: string) {
|
async request (endpoint: string) {
|
||||||
const res = await fetch(process.env.IMMICH_URL + '/api' + endpoint)
|
try {
|
||||||
if (res.status === 200) {
|
const res = await fetch(process.env.IMMICH_URL + '/api' + endpoint)
|
||||||
const contentType = res.headers.get('Content-Type') || ''
|
if (res.status === 200) {
|
||||||
if (contentType.includes('application/json')) {
|
const contentType = res.headers.get('Content-Type') || ''
|
||||||
return res.json()
|
if (contentType.includes('application/json')) {
|
||||||
|
return res.json()
|
||||||
|
} else {
|
||||||
|
return res
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return res
|
log('Immich API status ' + res.status)
|
||||||
|
console.log(await res.text())
|
||||||
}
|
}
|
||||||
} else {
|
} catch (e) {
|
||||||
log('Immich API status ' + res.status)
|
log('Unable to reach Immich on ' + process.env.IMMICH_URL)
|
||||||
console.log(await res.text())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,6 +233,10 @@ class Immich {
|
|||||||
expires: dayjs().add(1, 'hour').format()
|
expires: dayjs().add(1, 'hour').format()
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async accessible () {
|
||||||
|
return !!(await immich.request('/server/ping'))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const immich = new Immich()
|
const immich = new Immich()
|
||||||
|
@ -69,8 +69,12 @@ app.get('/:type(photo|video)/:key/:id', async (req, res) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Healthcheck
|
// Healthcheck
|
||||||
app.get('/healthcheck', (_req, res) => {
|
app.get('/healthcheck', async (_req, res) => {
|
||||||
res.send('ok')
|
if (await immich.accessible()) {
|
||||||
|
res.send('ok')
|
||||||
|
} else {
|
||||||
|
res.status(502).send()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Send a 404 for all other routes
|
// Send a 404 for all other routes
|
||||||
|
@ -6,3 +6,7 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- ${PORT}:3000
|
- ${PORT}:3000
|
||||||
env_file: .env
|
env_file: .env
|
||||||
|
healthcheck:
|
||||||
|
test: wget -q http://localhost:3000/healthcheck || exit 1
|
||||||
|
start_period: 10s
|
||||||
|
timeout: 5s
|
||||||
|
Loading…
Reference in New Issue
Block a user