This commit is contained in:
mukesh13
2025-06-25 10:08:02 +05:30
parent e191a7251d
commit 5ce138bfc8

View File

@ -1,49 +1,55 @@
# syntax=docker/dockerfile:1.4 # syntax=docker/dockerfile:1
FROM node:18-alpine AS development ### Base Image ###
FROM node:18-alpine AS base
### Dependencies Stage ###
FROM base AS deps
# Use default Alpine mirror (or Tsinghua if preferred)
RUN echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.18/main" > /etc/apk/repositories && \
echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.18/community" >> /etc/apk/repositories && \
apk update --no-cache && \
apk add --no-cache vips-dev
WORKDIR /app WORKDIR /app
# Install build dependencies
RUN apk add --no-cache python make g++ \
&& apk add vips-dev fftw-dev build-base \
--update-cache \
--repository https://alpine.global.ssl.fastly.net/alpine/v3.10/community \
--repository https://alpine.global.ssl.fastly.net/alpine/v3.10/main \
&& rm -fR /var/cache/apk/*
# Copy package files
COPY package.json package-lock.json ./ COPY package.json package-lock.json ./
# Enforce prebuilt sharp binaries
ENV SHARP_IGNORE_GLOBAL_LIBVIPS=true
RUN npm ci
# Install dependencies ### Builder Stage ###
RUN npm ci --legacy-peer-deps FROM base AS builder
RUN echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.18/main" > /etc/apk/repositories && \
echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.18/community" >> /etc/apk/repositories && \
apk update --no-cache && \
apk add --no-cache vips-dev
# Copy source code WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . . COPY . .
ENV CI=true
ENV PORT=3000
CMD ["npm", "start"]
# Build stage
FROM development AS build
RUN npm run build RUN npm run build
# Production stage ### Production Runner Stage ###
FROM nginx:alpine AS production FROM nginx:alpine AS runner
WORKDIR /usr/share/nginx/html WORKDIR /usr/share/nginx/html
# Remove default nginx files # Set permissions for default nginx user
RUN mkdir -p /var/cache/nginx /var/run/nginx && \
chown -R nginx:nginx /var/cache/nginx /var/run/nginx /usr/share/nginx/html && \
chmod -R 755 /var/cache/nginx /var/run/nginx /usr/share/nginx/html
# Remove default Nginx assets
RUN rm -rf ./* RUN rm -rf ./*
# Copy built app # Copy static assets from builder
COPY --from=build /app/build . COPY --from=builder --chown=nginx:nginx /app/public .
# Copy nginx config if it exists
COPY .nginx/nginx.conf /etc/nginx/conf.d/default.conf
# Expose port
EXPOSE 80 EXPOSE 80
ENTRYPOINT ["nginx", "-g", "daemon off;"] # Healthcheck
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:80 || exit 1
# Run Nginx
CMD ["nginx", "-g", "daemon off;"]