Skip to content

Commit

Permalink
feat: support docker (#174)
Browse files Browse the repository at this point in the history
* feat: add docker

* fix: nginx failed to load

* docs: update README.md

* chore: change to npm ci and remove static in nuxt.config.js

* docs: update server to serve

* docs: add Self Host section
  • Loading branch information
muhammad-asn authored Jul 27, 2024
1 parent b6a85dc commit b52e530
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 0 deletions.
90 changes: 90 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM node:18 AS build-stage

WORKDIR /app

COPY package*.json ./

RUN npm ci

COPY . .

ENV NODE_OPTIONS=--openssl-legacy-provider
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/default.conf /etc/nginx/conf.d/default.conf

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,29 @@ $ npm run start
# generate static project
$ npm run generate
```

## 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
```
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
services:
offline-diff-viewer:
build:
context: .
dockerfile: Dockerfile
container_name: offline-diff-viewer
ports:
- "3000:80"
security_opt:
- no-new-privileges:true
volumes:
- /var/log/nginx
restart: unless-stopped
environment:
- NODE_ENV=production
- NODE_OPTIONS=--openssl-legacy-provider
15 changes: 15 additions & 0 deletions nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
server {
listen 80;
server_name offline-diff-viewer.local;

location / {
charset utf-8;
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;
}
}

0 comments on commit b52e530

Please sign in to comment.