2025-10-12 18:23:13 +05:30
# Build stage
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
# Build without type checking (vite build only)
2025-12-11 19:34:14 +05:30
# Pass SIMPLE_MODE and BASE_URL environment variables if provided
2025-10-20 01:42:50 -07:00
ARG SIMPLE_MODE = false
2025-12-11 19:34:14 +05:30
ARG BASE_URL = /
2025-10-20 01:42:50 -07:00
ENV SIMPLE_MODE = $SIMPLE_MODE
2025-12-11 19:34:14 +05:30
ENV BASE_URL = $BASE_URL
2025-10-12 18:23:13 +05:30
RUN npm run build -- --mode production
# Production stage
2025-10-24 00:36:40 -07:00
FROM nginxinc/nginx-unprivileged:stable-alpine-slim
2025-10-12 18:23:13 +05:30
2025-11-07 18:48:39 +01:00
LABEL org.opencontainers.image.source= "https://github.com/alam00000/bentopdf"
2025-12-11 19:34:14 +05:30
ARG BASE_URL = /
ENV BASE_URL = $BASE_URL
# Switch to root to create directories and copy files (dont worry guys, its not a security issue as we switch it only for the duration of the build and its needed to create the destination directory based on BASE_URL)
USER root
2025-10-24 00:36:40 -07:00
COPY --chown= nginx:nginx nginx.conf /etc/nginx/nginx.conf
2025-12-11 19:34:14 +05:30
RUN set -e; \
SUBDIR = $( echo " ${ BASE_URL } " | sed 's:^/::; s:/$::' ) ; \
if [ -z " ${ SUBDIR } " ] || [ " ${ SUBDIR } " = "/" ] ; then \
DEST_DIR = "/usr/share/nginx/html" ; \
else \
DEST_DIR = " /usr/share/nginx/html/ ${ SUBDIR } " ; \
mkdir -p " ${ DEST_DIR } " ; \
fi ; \
chown -R nginx:nginx /usr/share/nginx/html; \
echo " Destination directory: ${ DEST_DIR } "
COPY --chown= nginx:nginx --from= builder /app/dist /tmp/dist
RUN set -e; \
SUBDIR = $( echo " ${ BASE_URL } " | sed 's:^/::; s:/$::' ) ; \
if [ -z " ${ SUBDIR } " ] || [ " ${ SUBDIR } " = "/" ] ; then \
DEST_DIR = "/usr/share/nginx/html" ; \
else \
DEST_DIR = " /usr/share/nginx/html/ ${ SUBDIR } " ; \
fi ; \
cp -r /tmp/dist/* " ${ DEST_DIR } / " ; \
rm -rf /tmp/dist; \
chown -R nginx:nginx /usr/share/nginx/html; \
echo " Files copied to: ${ DEST_DIR } " ; \
ls -la " ${ DEST_DIR } " | head -20
2025-10-24 00:36:40 -07:00
RUN mkdir -p /etc/nginx/tmp && chown -R nginx:nginx /etc/nginx/tmp
2025-10-22 19:10:33 -07:00
2025-12-11 19:34:14 +05:30
USER nginx
2025-10-25 00:53:18 -07:00
EXPOSE 8080
2025-10-23 19:42:34 -07:00
CMD [ "nginx" , "-g" , "daemon off;" ]
2025-10-25 00:53:18 -07:00
# Old Dockerfile for Root User
# # Build stage
# FROM node:20-alpine AS builder
# WORKDIR /app
# COPY package*.json ./
# RUN npm ci
# COPY . .
# # Build without type checking (vite build only)
# # Pass SIMPLE_MODE environment variable if provided
# ARG SIMPLE_MODE=false
# ENV SIMPLE_MODE=$SIMPLE_MODE
# RUN npm run build -- --mode production
# # Production stage
# FROM nginx:alpine
# COPY --from=builder /app/dist /usr/share/nginx/html
# COPY nginx.conf /etc/nginx/nginx.conf
# EXPOSE 8080
# CMD ["nginx", "-g", "daemon off;"]