feat(Dockerfile): use Alpine base image and add healthcheck

This commit is contained in:
Jewgeni 2024-10-04 23:45:56 +02:00
parent ab4bad05ae
commit 02e218d185

View File

@ -1,19 +1,15 @@
FROM node:20-slim AS base # Build Stage
FROM node:20-alpine AS build
ENV PNPM_HOME="/pnpm" ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH" ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable RUN corepack enable
WORKDIR /app WORKDIR /app
COPY package.json pnpm-lock.yaml ./ 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 RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
FROM build-deps AS build
COPY . . COPY . .
ARG SITE_URL ARG SITE_URL
ENV SITE_URL=${SITE_URL} ENV SITE_URL=${SITE_URL}
@ -21,10 +17,21 @@ ARG DIRECTUS_URL
ENV DIRECTUS_URL=${DIRECTUS_URL} ENV DIRECTUS_URL=${DIRECTUS_URL}
RUN pnpm run build RUN pnpm run build
# Runtime Stage
FROM nginx:1.25-alpine AS runtime FROM nginx:1.25-alpine AS runtime
# Copy custom nginx config
COPY nginx/nginx.conf /etc/nginx/nginx.conf COPY nginx/nginx.conf /etc/nginx/nginx.conf
# Copy built assets from build stage
COPY --from=build /app/dist /usr/share/nginx/html 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 EXPOSE 80
CMD ["nginx", "-g", "daemon off;"] CMD ["nginx", "-g", "daemon off;"]