Added .dockerignore file to speed up local image builds

Changed Dockerfile as previos file was failing to build consistently
removed some unused packages
added compression to json payloads
changed vite ports to 3000 to not break existing builds
backend and frontend both use port 3000 now
This commit is contained in:
Thegan Govender
2023-11-11 17:06:44 +02:00
parent 2beefd8184
commit e63f52e2fb
7 changed files with 43 additions and 1204 deletions

8
.dockerignore Normal file
View File

@@ -0,0 +1,8 @@
node_modules
npm-debug.log
Dockerfile
.dockerignore
.git
.gitignore
.vscode
.github

View File

@@ -1,26 +1,21 @@
# pull the Node.js Docker image # Stage 1: Build the application
FROM node:lts-alpine FROM node:slim AS builder
# update the package index WORKDIR /app
RUN apk update && apk add --no-cache tzdata
# set timezone data COPY package*.json ./
ENV TZ=Asia/Kuala_Lumpur RUN npm cache clean --force
RUN npm install
# create app directory COPY ./ ./
WORKDIR /usr/src/app
# bundle app source # Stage 2: Create the production image
COPY . . FROM node:slim
# install node_modules, build client React JS, delete node_modules server side, prune image for production, clear npm cache, delete unnecessary folder client side WORKDIR /app
RUN npm install && \
npm run build && \ COPY --from=builder /app .
npm cache clean --force && \
rm -rf src
# app run on port 3000
EXPOSE 3000 EXPOSE 3000
# run the server CMD ["npm", "run", "start"]
CMD ["npm", "start"]

View File

@@ -3,6 +3,7 @@ require('dotenv').config();
const http = require('http'); const http = require('http');
const path = require('path'); const path = require('path');
const express = require('express'); const express = require('express');
const compression = require('compression');
const cors = require('cors'); const cors = require('cors');
const jwt = require('jsonwebtoken'); const jwt = require('jsonwebtoken');
const knex = require('knex'); const knex = require('knex');
@@ -35,7 +36,7 @@ const { setupWebSocketServer } = require('./ws');
const app = express(); const app = express();
const db = knex(knexConfig.development); const db = knex(knexConfig.development);
const PORT = process.env.PORT || 3003; const PORT = 3000;
const LISTEN_IP = '127.0.0.1'; const LISTEN_IP = '127.0.0.1';
const JWT_SECRET = process.env.JWT_SECRET; const JWT_SECRET = process.env.JWT_SECRET;
@@ -49,6 +50,8 @@ app.use(express.json()); // middleware to parse JSON request bodies
app.use(cors()); app.use(cors());
app.set('trust proxy', 1); app.set('trust proxy', 1);
app.disable('x-powered-by'); app.disable('x-powered-by');
app.use(compression());
// initiate routes // initiate routes
app.use('/auth', authRouter, () => { app.use('/auth', authRouter, () => {

View File

@@ -13,6 +13,7 @@ services:
POSTGRES_IP: jellystat-db POSTGRES_IP: jellystat-db
POSTGRES_PORT: 5432 POSTGRES_PORT: 5432
JWT_SECRET: 'my-secret-jwt-key' JWT_SECRET: 'my-secret-jwt-key'
TZ: Africa/Johannesburg
ports: ports:
- "3000:3000" - "3000:3000"
depends_on: depends_on:

1176
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -2,6 +2,7 @@
"name": "jfstat", "name": "jfstat",
"version": "1.0.8", "version": "1.0.8",
"private": true, "private": true,
"main": "src/index.jsx",
"scripts": { "scripts": {
"start-client": "vite --host", "start-client": "vite --host",
"start-server": "cd backend && nodemon server.js", "start-server": "cd backend && nodemon server.js",
@@ -18,10 +19,6 @@
"@jellyfin/sdk": "^0.8.2", "@jellyfin/sdk": "^0.8.2",
"@mui/material": "^5.12.2", "@mui/material": "^5.12.2",
"@mui/x-data-grid": "^6.2.1", "@mui/x-data-grid": "^6.2.1",
"@nivo/api": "^0.74.1",
"@nivo/bar": "^0.80.0",
"@nivo/core": "^0.80.0",
"@nivo/line": "^0.80.0",
"@testing-library/jest-dom": "^5.16.5", "@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0", "@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0", "@testing-library/user-event": "^13.5.0",
@@ -30,6 +27,7 @@
"axios-cache-interceptor": "^1.3.1", "axios-cache-interceptor": "^1.3.1",
"bootstrap": "^5.2.3", "bootstrap": "^5.2.3",
"compare-versions": "^6.0.0-rc.1", "compare-versions": "^6.0.0-rc.1",
"compression": "^1.7.4",
"config": "^3.3.9", "config": "^3.3.9",
"cors": "^2.8.5", "cors": "^2.8.5",
"crypto-js": "^4.1.1", "crypto-js": "^4.1.1",

View File

@@ -22,16 +22,16 @@ export default defineConfig({
port: 3000, port: 3000,
// port for exposing APIs // port for exposing APIs
proxy: { proxy: {
'/api': 'http://localhost:3003', '/api': 'http://localhost:3000',
'/proxy': 'http://localhost:3003', '/proxy': 'http://localhost:3000',
'/stats': 'http://localhost:3003', '/stats': 'http://localhost:3000',
'/sync': 'http://localhost:3003', '/sync': 'http://localhost:3000',
'/auth': 'http://localhost:3003', '/auth': 'http://localhost:3000',
'/backup': 'http://localhost:3003', '/backup': 'http://localhost:3000',
'/logs': 'http://localhost:3003', '/logs': 'http://localhost:3000',
'/socket.io': 'http://localhost:3003', '/socket.io': 'http://localhost:3000',
'/swagger': 'http://localhost:3003', '/swagger': 'http://localhost:3000',
'/utils': 'http://localhost:3003', '/utils': 'http://localhost:3000',
}, },
}, },
target: ['es2015'], target: ['es2015'],