mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-03 18:22:57 +00:00
54 lines
1.2 KiB
Docker
54 lines
1.2 KiB
Docker
# Build stage
|
|
FROM node:18-alpine AS build
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy package files
|
|
COPY package*.json ./
|
|
|
|
# Install dependencies with cache mount
|
|
RUN --mount=type=cache,target=/root/.npm \
|
|
npm ci --prefer-offline --no-audit --no-fund
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Build the app with production settings
|
|
ENV NODE_ENV=production
|
|
ENV NODE_OPTIONS="--max-old-space-size=1024"
|
|
RUN --mount=type=cache,target=/root/.npm \
|
|
npm run build
|
|
|
|
|
|
RUN ls -R /app/build
|
|
|
|
# Production stage
|
|
FROM nginx:alpine
|
|
|
|
# Remove default nginx static assets
|
|
RUN rm -rf /usr/share/nginx/html/*
|
|
|
|
# Copy built assets from build stage
|
|
COPY --from=build /app/build /usr/share/nginx/html
|
|
|
|
# Copy nginx config
|
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
|
|
|
# Set proper permissions
|
|
RUN chown -R nginx:nginx /usr/share/nginx/html && \
|
|
chmod -R 755 /usr/share/nginx/html && \
|
|
chown -R nginx:nginx /var/cache/nginx && \
|
|
chown -R nginx:nginx /var/log/nginx && \
|
|
chown -R nginx:nginx /etc/nginx/conf.d && \
|
|
touch /var/run/nginx.pid && \
|
|
chown -R nginx:nginx /var/run/nginx.pid
|
|
|
|
# Switch to non-root user
|
|
USER nginx
|
|
|
|
# Expose port 80
|
|
EXPOSE 80
|
|
|
|
# Start nginx
|
|
CMD ["nginx", "-g", "daemon off;"]
|