mirror of
https://dev.azure.com/tstanciu94/ReverseProxy/_git/ReverseProxy_Frontend
synced 2025-10-03 16:49:04 +03:00
61 lines
1.7 KiB
Docker
61 lines
1.7 KiB
Docker
# Modern Dockerfile for Vite + React application
|
|
# Build stage
|
|
FROM node:24.9-alpine3.21 AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
ARG OWN_NPM_TOKEN
|
|
# Copy npm config required for private registry access. Ensure the build context includes .npmrc.
|
|
COPY .npmrc .npmrc
|
|
# Copy package files
|
|
COPY package*.json ./
|
|
|
|
# Install dependencies (include devDependencies for Vite build)
|
|
RUN npm ci
|
|
RUN rm -f .npmrc
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Build the application
|
|
ARG APP_SUBFOLDER=""
|
|
ENV VITE_BASE_PATH=${APP_SUBFOLDER}
|
|
RUN npm run build
|
|
|
|
# Production stage - Use nginx for better performance
|
|
FROM nginx:1.29.1-alpine
|
|
|
|
# Remove default nginx website
|
|
RUN rm -rf /usr/share/nginx/html/*
|
|
|
|
# Create subfolder structure dynamically based on APP_SUBFOLDER
|
|
ARG APP_SUBFOLDER=""
|
|
RUN if [ -n "$APP_SUBFOLDER" ]; then mkdir -p /usr/share/nginx/html/$APP_SUBFOLDER; fi
|
|
|
|
# Copy built application
|
|
COPY --from=builder /app/build /usr/share/nginx/html/${APP_SUBFOLDER}
|
|
|
|
# Copy and configure nginx
|
|
COPY nginx.conf /tmp/nginx.conf.template
|
|
# Generate nginx.conf with correct subfolder path
|
|
RUN if [ -n "$APP_SUBFOLDER" ]; then \
|
|
sed "s|# SUBFOLDER_PLACEHOLDER|location /$APP_SUBFOLDER/ { try_files \$uri \$uri/ /$APP_SUBFOLDER/index.html; }|g" /tmp/nginx.conf.template > /etc/nginx/nginx.conf; \
|
|
else \
|
|
sed "s|# SUBFOLDER_PLACEHOLDER||g" /tmp/nginx.conf.template > /etc/nginx/nginx.conf; \
|
|
fi
|
|
|
|
# Add environment variables
|
|
ENV Author="Tudor Stanciu"
|
|
ARG APP_VERSION=0.0.0
|
|
ENV APP_VERSION=${APP_VERSION}
|
|
|
|
# Expose port 80
|
|
EXPOSE 80
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=120s --timeout=10s --start-period=60s --retries=3 \
|
|
CMD if [ -n "$APP_SUBFOLDER" ]; then curl -f http://localhost/$APP_SUBFOLDER/ || exit 1; else curl -f http://localhost/ || exit 1; fi
|
|
|
|
# Start nginx
|
|
CMD ["nginx", "-g", "daemon off;"]
|