Skip to content

Commit

Permalink
fix: healthcheck exec failed
Browse files Browse the repository at this point in the history
  • Loading branch information
hywax committed May 7, 2024
1 parent aca8577 commit 410ccf8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM node:20.12.2-alpine as build
ARG NODE=node:20.12.2-alpine

FROM $NODE as build

WORKDIR /app

Expand All @@ -11,7 +13,7 @@ COPY . /app

RUN yarn run build

FROM gcr.io/distroless/nodejs20
FROM $NODE

LABEL org.opencontainers.image.title="Mafl"
LABEL org.opencontainers.image.description="Minimalistic flexible homepage"
Expand All @@ -22,9 +24,10 @@ LABEL org.opencontainers.image.licenses="MIT"
WORKDIR /app

COPY --from=build /app/.output /app
COPY --from=build /app/extra/healthcheck.mjs /app/extra/healthcheck.mjs

EXPOSE 3000/tcp

HEALTHCHECK --interval=10s --timeout=5s --start-period=10s CMD node -e "require('http').get('http://localhost:3000/api/health', res => process.exit(res.statusCode === 200 ? 0 : 1)).on('error', () => process.exit(1))"
HEALTHCHECK --interval=10s --timeout=5s --start-period=10s CMD ["node", "/app/extra/healthcheck.mjs"]

CMD ["/app/server/index.mjs"]
24 changes: 24 additions & 0 deletions extra/healthcheck.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import process from 'node:process'
import http from 'node:http'

const options = {
hostname: 'localhost',
port: 3000,
path: '/api/health',
method: 'GET',
}

const request = http.request(options, (response) => {
if (response.statusCode === 200) {
process.exit(0)
} else {
process.exit(1)
}
})

request.on('error', (error) => {
console.error('Health Check ERROR:', error)
process.exit(1)
})

request.end()

0 comments on commit 410ccf8

Please sign in to comment.