From c3cd2196f114b5b7332b0400ca0155be62d6ce70 Mon Sep 17 00:00:00 2001 From: muhammad-asn Date: Sun, 14 Jul 2024 22:59:16 +0700 Subject: [PATCH 1/6] feat: add docker --- .dockerignore | 90 ++++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 21 +++++++++++ docker-compose.yml | 18 ++++++++++ nginx/nginx.conf | 14 ++++++++ nuxt.config.js | 1 + 5 files changed, 144 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 nginx/nginx.conf diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e8f682b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,90 @@ +# Created by .ignore support plugin (hsz.mobi) +### Node template +# Logs +/logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + +# parcel-bundler cache (https://parceljs.org/) +.cache + +# next.js build output +.next + +# nuxt.js build output +.nuxt + +# Nuxt generate +dist + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless + +# IDE / Editor +.idea + +# Service worker +sw.* + +# macOS +.DS_Store + +# Vim swap files +*.swp diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..67d377d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM node:16 AS build-stage + +WORKDIR /app + +COPY package*.json ./ + +RUN npm install + +COPY . . + +RUN npm run generate + +FROM nginx:1.27.0-alpine-slim AS production-stage + +COPY --from=build-stage /app/dist /usr/share/nginx/html + +COPY nginx/nginx.conf /etc/nginx/nginx.conf + +EXPOSE 80 + +CMD ["nginx", "-g", "daemon off;"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..2adb92c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,18 @@ +services: + offline-diff-viewer: + build: + context: . + dockerfile: Dockerfile + container_name: offline-diff-viewer + ports: + - "3000:80" + security_opt: + - no-new-privileges:true + cap_drop: + - ALL + volumes: + - /var/log/nginx + restart: unless-stopped + environment: + - NODE_ENV=production + - NODE_OPTIONS=--openssl-legacy-provider diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..cad35cd --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,14 @@ +server { + listen 80; + server_name localhost; + + location / { + root /usr/share/nginx/html; + try_files $uri $uri/ /index.html; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} diff --git a/nuxt.config.js b/nuxt.config.js index 8fa127b..e1c6b86 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -13,6 +13,7 @@ const canonicalLinks = domainAliases.map((x) => ({ rel: 'canonical', href: x })) const DESCRIPTION = 'A privacy first diff viewer that is secure, easy, simple and for any text type' export default { + target: 'static', ssr: false, head: { title: `Diff viewer - ${DESCRIPTION}`, From 26cda509f5dbb87c129b3d902418f34410ee3820 Mon Sep 17 00:00:00 2001 From: muhammad-asn Date: Sun, 14 Jul 2024 23:19:36 +0700 Subject: [PATCH 2/6] fix: nginx failed to load --- Dockerfile | 2 +- docker-compose.yml | 2 -- nginx/{nginx.conf => default.conf} | 3 ++- 3 files changed, 3 insertions(+), 4 deletions(-) rename nginx/{nginx.conf => default.conf} (78%) diff --git a/Dockerfile b/Dockerfile index 67d377d..c4d3c5a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ FROM nginx:1.27.0-alpine-slim AS production-stage COPY --from=build-stage /app/dist /usr/share/nginx/html -COPY nginx/nginx.conf /etc/nginx/nginx.conf +COPY nginx/default.conf /etc/nginx/conf.d/default.conf EXPOSE 80 diff --git a/docker-compose.yml b/docker-compose.yml index 2adb92c..5b40a46 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,8 +8,6 @@ services: - "3000:80" security_opt: - no-new-privileges:true - cap_drop: - - ALL volumes: - /var/log/nginx restart: unless-stopped diff --git a/nginx/nginx.conf b/nginx/default.conf similarity index 78% rename from nginx/nginx.conf rename to nginx/default.conf index cad35cd..8a2c62f 100644 --- a/nginx/nginx.conf +++ b/nginx/default.conf @@ -1,8 +1,9 @@ server { listen 80; - server_name localhost; + server_name offline-diff-viewer.local; location / { + charset utf-8; root /usr/share/nginx/html; try_files $uri $uri/ /index.html; } From 74e65250384ac020e85b3a519c3a450114df14a3 Mon Sep 17 00:00:00 2001 From: muhammad-asn Date: Sun, 14 Jul 2024 23:22:25 +0700 Subject: [PATCH 3/6] docs: update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 11473c7..f7edbd1 100644 --- a/README.md +++ b/README.md @@ -76,4 +76,7 @@ $ npm run start # generate static project $ npm run generate + +# server with docker +$ docker compose up -d --build ``` From 2948287edf028cc7e47fbe9a22f4073090b7d096 Mon Sep 17 00:00:00 2001 From: muhammad-asn Date: Wed, 17 Jul 2024 17:41:29 +0700 Subject: [PATCH 4/6] chore: change to npm ci and remove static in nuxt.config.js --- Dockerfile | 5 +++-- nuxt.config.js | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index c4d3c5a..f96c7ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,14 @@ -FROM node:16 AS build-stage +FROM node:18 AS build-stage WORKDIR /app COPY package*.json ./ -RUN npm install +RUN npm ci COPY . . +ENV NODE_OPTIONS=--openssl-legacy-provider RUN npm run generate FROM nginx:1.27.0-alpine-slim AS production-stage diff --git a/nuxt.config.js b/nuxt.config.js index e1c6b86..8fa127b 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -13,7 +13,6 @@ const canonicalLinks = domainAliases.map((x) => ({ rel: 'canonical', href: x })) const DESCRIPTION = 'A privacy first diff viewer that is secure, easy, simple and for any text type' export default { - target: 'static', ssr: false, head: { title: `Diff viewer - ${DESCRIPTION}`, From a18da6f6d1813b3333c4154b2f7e6e6f24714529 Mon Sep 17 00:00:00 2001 From: muhammad-asn Date: Wed, 17 Jul 2024 17:44:33 +0700 Subject: [PATCH 5/6] docs: update server to serve --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f7edbd1..1d1012a 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,6 @@ $ npm run start # generate static project $ npm run generate -# server with docker +# serve with docker $ docker compose up -d --build ``` From 90a2f78a3efa610c903dfc260dba49e5f13b6707 Mon Sep 17 00:00:00 2001 From: muhammad-asn Date: Fri, 19 Jul 2024 11:18:10 +0700 Subject: [PATCH 6/6] docs: add Self Host section --- README.md | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1d1012a..9606165 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,30 @@ $ npm run start # generate static project $ npm run generate +``` -# serve with docker -$ docker compose up -d --build +## Self Host +This guide provides detailed instructions on how to self-host the offline-diff-viewer application using Docker and Docker Compose. Self-hosting allows you to run the application on your own server, providing you with full control over its environment and configuration. + +### Building and Running the Docker Container +1. Build the Docker Image +```bash +$ docker build -t offline-diff-viewer . ``` +2. Run the Docker Container via docker run command +```bash +$ docker run -d \ + --name offline-diff-viewer \ + -p 3000:80 \ + --security-opt no-new-privileges:true \ + -v /var/log/nginx:/var/log/nginx \ + --restart unless-stopped \ + -e NODE_ENV=production \ + -e NODE_OPTIONS=--openssl-legacy-provider \ + offline-diff-viewer +``` + +### Running the Container with Docker Compose +```bash +$ docker compose up -d --build +``` \ No newline at end of file