diff --git a/angular/Dockerfile b/angular/Dockerfile new file mode 100644 index 0000000..a8d2c8d --- /dev/null +++ b/angular/Dockerfile @@ -0,0 +1,36 @@ +# Stage 1: Build Angular app +FROM node:20-alpine AS builder + +WORKDIR /app + +# Install pnpm globally +RUN npm install -g pnpm + +# Copy package files first +COPY package.json pnpm-lock.yaml ./ + +# Install dependencies with cache mount +RUN --mount=type=cache,target=/root/.local/share/pnpm/store \ + pnpm install --frozen-lockfile + +# Copy rest of the application +COPY . . + +# Build Angular app +RUN pnpm run build + +# Stage 2: Serve with NGINX +FROM nginx:1.25-alpine + +# Copy built Angular app to NGINX HTML folder +COPY --from=builder /app/dist/browser/ /usr/share/nginx/html + +# Remove default NGINX config +RUN rm /etc/nginx/conf.d/default.conf + +# Add custom NGINX config for SPA routing +COPY nginx.conf /etc/nginx/conf.d + +EXPOSE 80 + +CMD ["nginx", "-g", "daemon off;"] diff --git a/angular/nginx.conf b/angular/nginx.conf new file mode 100644 index 0000000..1660db0 --- /dev/null +++ b/angular/nginx.conf @@ -0,0 +1,17 @@ +server { + listen 80; + server_name localhost; + + root /usr/share/nginx/html; + index index.html; + + location / { + try_files $uri $uri/ /index.html; + } + + # Optional: gzip for better performance + gzip on; + gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; + gzip_proxied any; + gzip_min_length 256; +}