From 02e218d1853c3c06d48bb3f8811564d910c61837 Mon Sep 17 00:00:00 2001 From: Jewgeni Date: Fri, 4 Oct 2024 23:45:56 +0200 Subject: [PATCH] feat(Dockerfile): use Alpine base image and add healthcheck --- Dockerfile | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8b82215..da275b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,15 @@ -FROM node:20-slim AS base +# Build Stage +FROM node:20-alpine AS build ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" RUN corepack enable WORKDIR /app + COPY package.json pnpm-lock.yaml ./ - -FROM base AS prod-deps -RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile - -FROM base AS build-deps RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile -FROM build-deps AS build COPY . . ARG SITE_URL ENV SITE_URL=${SITE_URL} @@ -21,10 +17,21 @@ ARG DIRECTUS_URL ENV DIRECTUS_URL=${DIRECTUS_URL} RUN pnpm run build +# Runtime Stage FROM nginx:1.25-alpine AS runtime + +# Copy custom nginx config COPY nginx/nginx.conf /etc/nginx/nginx.conf + +# Copy built assets from build stage COPY --from=build /app/dist /usr/share/nginx/html +# Add curl for healthchecks +RUN apk add --no-cache curl + +# Healthcheck +HEALTHCHECK --interval=30s --timeout=3s CMD curl -f http://localhost/ || exit 1 + EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]