feat: add production Dockerfile for gameno-front
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
node_modules
|
||||
dist
|
||||
.git
|
||||
.gitignore
|
||||
.vscode
|
||||
.env
|
||||
.env.local
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
# Multi-stage production Dockerfile for gameno-front (Vue 3 + Vite SPA)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Stage 1: Build the Vite static application
|
||||
# ------------------------------------------------------------------------------
|
||||
FROM node:22-alpine AS build
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package descriptors and install dependencies
|
||||
COPY package*.json ./
|
||||
RUN npm ci
|
||||
|
||||
# Copy application source code
|
||||
COPY . .
|
||||
|
||||
# Build argument for API base URL (can be overridden at build time)
|
||||
ARG VITE_API_BASE_URL
|
||||
ENV VITE_API_BASE_URL=${VITE_API_BASE_URL}
|
||||
|
||||
# Build static assets to /app/dist
|
||||
RUN npm run build
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Stage 2: Production web server serving static files via Nginx
|
||||
# ------------------------------------------------------------------------------
|
||||
FROM nginx:1.27-alpine AS production
|
||||
|
||||
# Inline Nginx configuration for SPA routing, gzip, and caching
|
||||
RUN printf 'server {\n\
|
||||
listen 80;\n\
|
||||
server_name localhost;\n\
|
||||
root /usr/share/nginx/html;\n\
|
||||
index index.html;\n\
|
||||
gzip on;\n\
|
||||
gzip_types text/plain text/css text/javascript application/javascript application/json image/svg+xml;\n\
|
||||
location / {\n\
|
||||
try_files $uri $uri/ /index.html;\n\
|
||||
}\n\
|
||||
location ~* \\.(?:css|js|jpg|jpeg|gif|png|ico|svg|woff|woff2|ttf)$ {\n\
|
||||
expires 1y;\n\
|
||||
access_log off;\n\
|
||||
add_header Cache-Control "public, immutable";\n\
|
||||
}\n\
|
||||
}\n' > /etc/nginx/conf.d/default.conf
|
||||
|
||||
# Copy compiled static assets from build stage
|
||||
COPY --from=build /app/dist /usr/share/nginx/html
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
# Health check to ensure Nginx is responding on port 80
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
|
||||
CMD wget --no-verbose --tries=1 --spider http://localhost:80/ || exit 1
|
||||
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
Reference in New Issue
Block a user