From 7c31ad8c0f46367e200d548d4722fa7a6789262e Mon Sep 17 00:00:00 2001 From: Sebastian Pietschner Date: Thu, 29 Aug 2024 16:57:14 +1000 Subject: [PATCH] add healthcheck --- Dockerfile | 12 ++++++++++-- src/app.controller.ts | 9 +++++++++ src/app.module.ts | 2 ++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b63ab328..318efb0f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -# Deps +# Base FROM node:21-alpine AS base ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" @@ -6,17 +6,20 @@ RUN corepack enable COPY . /app WORKDIR /app +# Prod Dependencies FROM base AS prod-deps RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile +# Build FROM base AS build RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile RUN pnpm run build +# Build Artifacts FROM scratch AS extract COPY --from=build /app/dist /dist -# Runner +# Pterodactyl Image FROM base as pterodactyl COPY --from=prod-deps /app/node_modules /app/node_modules COPY --from=build /app/dist /app/dist @@ -30,10 +33,13 @@ RUN adduser -H -D container -s /bin/bash ENV USER=container HOME=/home/container USER container +HEALTHCHECK CMD curl --fail http://localhost:3000 || exit 1 + COPY entrypoint.sh /entrypoint.sh CMD [ "/bin/bash", "/entrypoint.sh" ] +# Default Image FROM base COPY --from=prod-deps /app/node_modules /app/node_modules COPY --from=build /app/dist /app/dist @@ -43,4 +49,6 @@ ENV DATABASE_URL "file:/app/config/db.sqlite" ARG VERSION ENV VERSION=$VERSION +HEALTHCHECK CMD curl --fail http://localhost:3000 || exit 1 + CMD [ "pnpm", "start" ] diff --git a/src/app.controller.ts b/src/app.controller.ts index e69de29b..2c7ab079 100644 --- a/src/app.controller.ts +++ b/src/app.controller.ts @@ -0,0 +1,9 @@ +import { Get } from "@nestjs/common"; +import { AppService } from "./app.service"; + +export class AppController { + @Get() + getOk(): string { + return "OK"; + } +} diff --git a/src/app.module.ts b/src/app.module.ts index ba1c102f..4046fcec 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -12,6 +12,7 @@ import { MqttModule } from "./features/mqtt/mqtt.module"; import { PrimaryModule } from "./features/primary/primary.module"; import { SecondaryModule } from "./features/secondary/secondary.module"; import { DrizzleModule } from "./features/drizzle/drizzle.module"; +import { AppController } from "./app.controller"; @Module({ imports: [ ConfigModule.forRoot({ @@ -37,5 +38,6 @@ import { DrizzleModule } from "./features/drizzle/drizzle.module"; MqttModule, ], providers: [AppService, InfoCommands], + controllers: [AppController], }) export class AppModule {}