Skip to content

Commit 410ccf8

Browse files
author
hywax
committed
fix: healthcheck exec failed
1 parent aca8577 commit 410ccf8

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

Diff for: Dockerfile

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
FROM node:20.12.2-alpine as build
1+
ARG NODE=node:20.12.2-alpine
2+
3+
FROM $NODE as build
24

35
WORKDIR /app
46

@@ -11,7 +13,7 @@ COPY . /app
1113

1214
RUN yarn run build
1315

14-
FROM gcr.io/distroless/nodejs20
16+
FROM $NODE
1517

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

2426
COPY --from=build /app/.output /app
27+
COPY --from=build /app/extra/healthcheck.mjs /app/extra/healthcheck.mjs
2528

2629
EXPOSE 3000/tcp
2730

28-
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))"
31+
HEALTHCHECK --interval=10s --timeout=5s --start-period=10s CMD ["node", "/app/extra/healthcheck.mjs"]
2932

3033
CMD ["/app/server/index.mjs"]

Diff for: extra/healthcheck.mjs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import process from 'node:process'
2+
import http from 'node:http'
3+
4+
const options = {
5+
hostname: 'localhost',
6+
port: 3000,
7+
path: '/api/health',
8+
method: 'GET',
9+
}
10+
11+
const request = http.request(options, (response) => {
12+
if (response.statusCode === 200) {
13+
process.exit(0)
14+
} else {
15+
process.exit(1)
16+
}
17+
})
18+
19+
request.on('error', (error) => {
20+
console.error('Health Check ERROR:', error)
21+
process.exit(1)
22+
})
23+
24+
request.end()

0 commit comments

Comments
 (0)