diff --git a/Dockerfile b/Dockerfile index 810fbb7..2d541f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,41 +1,10 @@ -FROM node:20-alpine AS base - -### Dependencies ### -FROM base AS deps -RUN apk add --no-cache libc6-compat git curl - -# Setup pnpm environment -ENV PNPM_HOME="/pnpm" -ENV PATH="$PNPM_HOME:$PATH" -RUN corepack enable -RUN corepack prepare pnpm@latest --activate - -WORKDIR /app - -COPY package.json pnpm-lock.yaml ./ -RUN pnpm install --frozen-lockfile --prefer-frozen-lockfile - -# Builder -FROM base AS builder - -RUN corepack enable -RUN corepack prepare pnpm@latest --activate - -WORKDIR /app - -COPY . . -COPY --from=deps /app/node_modules ./node_modules -COPY ./src ./src -COPY ./public ./public -COPY package.json pnpm-lock.yaml ./ -RUN pnpm install --frozen-lockfile --prefer-frozen-lockfile -RUN pnpm build - ### Production image runner ### FROM base AS runner +# Install curl for healthcheck +RUN apk add --no-cache curl + # Disable Next.js telemetry -# https://nextjs.org/telemetry ENV NEXT_TELEMETRY_DISABLED 1 # Set correct permissions for nextjs user and don't run as root @@ -45,7 +14,6 @@ RUN mkdir .next RUN chown nextjs:nodejs .next # Automatically leverage output traces to reduce image size -# https://nextjs.org/docs/advanced-features/output-file-tracing COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static COPY --from=builder --chown=nextjs:nodejs /app/public ./public diff --git a/src/app/health/route.ts b/src/app/health/route.ts new file mode 100644 index 0000000..170c354 --- /dev/null +++ b/src/app/health/route.ts @@ -0,0 +1,13 @@ +import { ResponseHelper } from "@/lib/helper"; +import { RESPONSE } from "@/lib/const"; + +const { INTERNAL_SERVER_ERROR } = RESPONSE; + +export async function GET(): Promise { + try { + return ResponseHelper.success("Healthy"); + } catch (error) { + console.error("Health check failed:", error); + return ResponseHelper.error(INTERNAL_SERVER_ERROR, error); + } +}