From fe2789a21556211a2605567038eae39e31dabeba Mon Sep 17 00:00:00 2001 From: m-tartari <37861893+m-tartari@users.noreply.github.com> Date: Wed, 4 Dec 2024 16:54:02 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(docker):=20add=20Docker=20conf?= =?UTF-8?q?iguration=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 27 ++++++++++++++++++++++++++ Dockerfile | 37 +++++++++++++++++++++++++++++++++++ docker-compose.yml | 13 +++++++++++++ nginx.conf | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 nginx.conf diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1cff1d1 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,27 @@ +# compiled output +.vscode +node_modules +dist +npm-debug.log +.npmrc + +# git +.git +.gitignore +.github + +# code formatter +.eslintrc +.eslintignore +.editorconfig +.huskyrc +.lintstagedrc.json +.prettierrc + +# test +jest.config.js + +# docker +Dockerfile +docker-compose.yml +.dockerignore diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cfb43f9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,37 @@ +ARG PRODUCTION_IMAGE=nginx:alpine +ARG BASE_IMAGE=node:lts + +# --------------> The development image +FROM $BASE_IMAGE AS development + +ENV NODE_ENV=development +COPY --chown=1000:1000 . /workspaces/m-tartari.github.io +WORKDIR /workspaces/m-tartari.github.io +USER 1000:1000 + +CMD [ "sleep", "infinity" ] + +# --------------> The production build stage +FROM $BASE_IMAGE AS production-build + +ENV NODE_ENV=production +COPY . /app +WORKDIR /app + +RUN npm ci --omit=dev +RUN npm run build:prod + +# --------------> The production image +FROM ${PRODUCTION_IMAGE} AS production + +# Remove default nginx website +RUN rm -rf html; mkdir html + +COPY --from=production-build /app/dist /usr/share/nginx/html +# COPY .htpasswd /usr/share/nginx/html/.htpasswd +COPY ./nginx.conf /etc/nginx/ + +RUN chmod -R o+r /usr/share/nginx/html +WORKDIR /usr/share/nginx + +ENTRYPOINT ["nginx", "-g", "daemon off;"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..2ba39d1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +version: '3.8' + +services: + app: + image: git.m-tartari.eu/m-tartari.github.io + build: + context: . + dockerfile: Dockerfile + target: production + container_name: m-tartari.github.io + restart: unless-stopped + ports: + - '8080:8080' diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..8971788 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,48 @@ +user nginx; + +worker_processes auto; + +events { worker_connections 1024; } + +http { + server { + server_tokens off; + + listen 8080; + root /usr/share/nginx/html; + include /etc/nginx/mime.types; + + location / { + # # This sets the authentication realm name + # auth_basic "Restricted Access"; + # # This specifies the location of the .htpasswd file + # auth_basic_user_file /usr/share/nginx/html/.htpasswd; + + try_files $uri $uri/ /index.html; + } + + gzip on; + gzip_vary on; + gzip_http_version 1.0; + gzip_comp_level 5; + gzip_types + application/atom+xml + application/javascript + application/json + application/rss+xml + application/vnd.ms-fontobject + application/x-font-ttf + application/x-web-app-manifest+json + application/xhtml+xml + application/xml + font/opentype + image/svg+xml + image/x-icon + text/css + text/plain + text/x-component; + gzip_proxied no-cache no-store private expired auth; + gzip_min_length 256; + gunzip on; + } +}