hello world
This commit is contained in:
29
Dockerfile
29
Dockerfile
@@ -1,11 +1,7 @@
|
|||||||
# =========================================
|
# =========================================
|
||||||
# Stage 1: Build the Angular Application
|
# Stage 1: Build the Angular Application
|
||||||
# =========================================
|
# =========================================
|
||||||
# =========================================
|
|
||||||
# Stage 1: Build the Angular Application
|
|
||||||
# =========================================
|
|
||||||
ARG NODE_VERSION=24.7.0-alpine
|
ARG NODE_VERSION=24.7.0-alpine
|
||||||
ARG NGINX_VERSION=alpine3.22
|
|
||||||
|
|
||||||
# Use a lightweight Node.js image for building (customizable via ARG)
|
# Use a lightweight Node.js image for building (customizable via ARG)
|
||||||
FROM node:${NODE_VERSION} AS builder
|
FROM node:${NODE_VERSION} AS builder
|
||||||
@@ -26,24 +22,23 @@ COPY . .
|
|||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# =========================================
|
# =========================================
|
||||||
# Stage 2: Prepare Nginx to Serve Static Files
|
# Stage 2: Run SSR Server
|
||||||
# =========================================
|
# =========================================
|
||||||
|
|
||||||
FROM nginxinc/nginx-unprivileged:${NGINX_VERSION} AS runner
|
FROM node:${NODE_VERSION} AS runner
|
||||||
|
|
||||||
# Use a built-in non-root user for security best practices
|
|
||||||
USER nginx
|
|
||||||
|
|
||||||
# Copy custom Nginx config
|
WORKDIR /app
|
||||||
COPY nginx.conf /etc/nginx/nginx.conf
|
|
||||||
|
|
||||||
# Copy the static build output from the build stage to Nginx's default HTML serving directory
|
ENV NODE_ENV=production
|
||||||
COPY --chown=nginx:nginx --from=builder /app/dist/*/browser /usr/share/nginx/html
|
|
||||||
|
|
||||||
# Expose port 8080 to allow HTTP traffic
|
# Copy only necessary build output
|
||||||
# Note: The default NGINX container now listens on port 8080 instead of 80
|
COPY --from=builder /app/dist ./dist
|
||||||
EXPOSE 8080
|
COPY --from=builder /app/package.json ./package.json
|
||||||
|
COPY --from=builder /app/node_modules ./node_modules
|
||||||
|
|
||||||
|
# Angular SSR default port
|
||||||
|
EXPOSE 4000
|
||||||
|
|
||||||
# Start Nginx directly with custom config
|
# Start Nginx directly with custom config
|
||||||
ENTRYPOINT ["nginx", "-c", "/etc/nginx/nginx.conf"]
|
CMD ["node", "dist/*/server/server.mjs"]
|
||||||
CMD ["-g", "daemon off;"]
|
|
||||||
|
|||||||
75
nginx.conf
75
nginx.conf
@@ -1,75 +0,0 @@
|
|||||||
worker_processes auto;
|
|
||||||
|
|
||||||
pid /tmp/nginx.pid;
|
|
||||||
|
|
||||||
events {
|
|
||||||
worker_connections 1024;
|
|
||||||
}
|
|
||||||
|
|
||||||
http {
|
|
||||||
include /etc/nginx/mime.types;
|
|
||||||
default_type application/octet-stream;
|
|
||||||
|
|
||||||
client_body_temp_path /tmp/client_temp;
|
|
||||||
proxy_temp_path /tmp/proxy_temp_path;
|
|
||||||
fastcgi_temp_path /tmp/fastcgi_temp;
|
|
||||||
uwsgi_temp_path /tmp/uwsgi_temp;
|
|
||||||
scgi_temp_path /tmp/scgi_temp;
|
|
||||||
|
|
||||||
# Logging
|
|
||||||
access_log off;
|
|
||||||
error_log /dev/stderr warn;
|
|
||||||
|
|
||||||
# Performance
|
|
||||||
sendfile on;
|
|
||||||
tcp_nopush on;
|
|
||||||
tcp_nodelay on;
|
|
||||||
keepalive_timeout 65;
|
|
||||||
keepalive_requests 1000;
|
|
||||||
|
|
||||||
# Compression
|
|
||||||
gzip on;
|
|
||||||
gzip_vary on;
|
|
||||||
gzip_proxied any;
|
|
||||||
gzip_min_length 256;
|
|
||||||
gzip_comp_level 6;
|
|
||||||
gzip_types
|
|
||||||
text/plain
|
|
||||||
text/css
|
|
||||||
text/xml
|
|
||||||
text/javascript
|
|
||||||
application/javascript
|
|
||||||
application/x-javascript
|
|
||||||
application/json
|
|
||||||
application/xml
|
|
||||||
application/xml+rss
|
|
||||||
font/ttf
|
|
||||||
font/otf
|
|
||||||
image/svg+xml;
|
|
||||||
|
|
||||||
server {
|
|
||||||
listen 8080;
|
|
||||||
server_name localhost;
|
|
||||||
|
|
||||||
root /usr/share/nginx/html;
|
|
||||||
index index.html;
|
|
||||||
|
|
||||||
# Angular Routing
|
|
||||||
location / {
|
|
||||||
try_files $uri $uri/ /index.html;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Static Assets Caching
|
|
||||||
location ~* \.(?:ico|css|js|gif|jpe?g|png|woff2?|eot|ttf|svg|map)$ {
|
|
||||||
expires 1y;
|
|
||||||
access_log off;
|
|
||||||
add_header Cache-Control "public, immutable";
|
|
||||||
}
|
|
||||||
|
|
||||||
# Optional: Explicit asset route
|
|
||||||
location /assets/ {
|
|
||||||
expires 1y;
|
|
||||||
add_header Cache-Control "public, immutable";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user