From 839aace50cf86079d62b094e4b9e51a963116ffc Mon Sep 17 00:00:00 2001 From: Aroy-Art Date: Mon, 19 May 2025 09:52:23 +0200 Subject: [PATCH] Add: Dockerfile & nginx config for container prod setup --- Dockerfile | 31 +++++++++++++++++++++++++++++++ nginx.conf | 21 +++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 Dockerfile create mode 100644 nginx.conf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7d0a453 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +### STAGE 1: Build ### +FROM node:lts-alpine AS build + +#### make the 'app' folder the current working directory +WORKDIR /usr/src/app + +#### copy both 'package.json' and 'package-lock.json' (if available) +COPY package*.json ./ + +#### install angular cli +RUN npm install -g @angular/cli + +#### install project dependencies +RUN npm install + +#### copy things +COPY . . + +#### generate build --prod +RUN npm run build --prod + +### STAGE 2: Run ### +FROM nginxinc/nginx-unprivileged + +#### copy nginx conf +COPY ./nginx.conf /etc/nginx/conf.d/default.conf + +#### copy artifact build from the 'build environment' +COPY --from=build /usr/src/app/dist/bookproject /usr/share/nginx/html + +CMD ["nginx", "-g", "daemon off;"] diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..2b7a475 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,21 @@ +server { + listen 0.0.0.0:8080; + listen [::]:8080; + default_type application/octet-stream; + + gzip on; + gzip_comp_level 6; + gzip_vary on; + gzip_min_length 1000; + gzip_proxied any; + gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; + gzip_buffers 16 8k; + gunzip on; + client_max_body_size 256M; + + root /usr/share/nginx/html; + + location / { + try_files $uri $uri/ /index.html =404; + } +}