From 85ff1fa293e0e84083533dc6ebb2d036015abd47 Mon Sep 17 00:00:00 2001 From: liv Date: Wed, 24 Apr 2024 19:57:01 +1000 Subject: [PATCH] Optimised docker --- backend/.dockerignore | 1 - backend/.env | 5 ----- backend/Dockerfile | 8 ++++++-- backend/db/index.ts | 2 -- backend/docker-compose.yml | 6 +++--- backend/index.ts | 4 ---- backend/package-lock.json | 13 ------------- backend/package.json | 1 - 8 files changed, 9 insertions(+), 31 deletions(-) delete mode 100644 backend/.env diff --git a/backend/.dockerignore b/backend/.dockerignore index d5f19d8..3c3629e 100644 --- a/backend/.dockerignore +++ b/backend/.dockerignore @@ -1,2 +1 @@ node_modules -package-lock.json diff --git a/backend/.env b/backend/.env deleted file mode 100644 index 1be54d5..0000000 --- a/backend/.env +++ /dev/null @@ -1,5 +0,0 @@ -PORT = 8080 -DB_HOST = db -DB_PORT = 5432 -DB_USER = postgres -DB_PASSWORD = postgres diff --git a/backend/Dockerfile b/backend/Dockerfile index 88d61da..df7126a 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -2,8 +2,12 @@ FROM node:latest WORKDIR /app -COPY . /app +COPY ./package.json /app +COPY ./package-lock.json /app +RUN npm ci -RUN npm install +COPY ./index.ts . +COPY ./db ./db +COPY ./routes ./routes CMD ["npm", "run", "start"] diff --git a/backend/db/index.ts b/backend/db/index.ts index 5df35ff..6ee7145 100644 --- a/backend/db/index.ts +++ b/backend/db/index.ts @@ -1,8 +1,6 @@ // Imports import { Pool } from 'pg' -const dotenv = require('dotenv'); - const pool = new Pool({ user: process.env.DB_USER, host: process.env.DB_HOST, diff --git a/backend/docker-compose.yml b/backend/docker-compose.yml index c0d7d81..1d37056 100644 --- a/backend/docker-compose.yml +++ b/backend/docker-compose.yml @@ -20,9 +20,9 @@ services: db: image: postgres:latest environment: - DB_USER: "postgres" - DB_PASSWORD: "postgres" - DB_DATABASE: "postgres" + POSTGRES_USER: "postgres" + POSTGRES_PASSWORD: "postgres" + POSTGRES_DATABASE: "postgres" adminer: image: adminer diff --git a/backend/index.ts b/backend/index.ts index 22e6505..aae2d58 100644 --- a/backend/index.ts +++ b/backend/index.ts @@ -8,10 +8,6 @@ import cors from 'cors'; import { routes } from './routes/index'; import * as db from './db/index'; -const dotenv = require('dotenv'); - -dotenv.config(); - const PORT: number = process.env.PORT ? parseInt(process.env.PORT) : 8080; // Make the app diff --git a/backend/package-lock.json b/backend/package-lock.json index 489b2f0..31f9d8d 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -17,7 +17,6 @@ "@types/pg": "^8.11.5", "@types/uuid": "^9.0.8", "cors": "^2.8.5", - "dotenv": "^16.4.5", "express": "^4.19.2", "pg": "^8.11.5", "uuid": "^9.0.1" @@ -457,18 +456,6 @@ "node": ">=0.3.1" } }, - "node_modules/dotenv": { - "version": "16.4.5", - "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", - "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", - "dev": true, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://dotenvx.com" - } - }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", diff --git a/backend/package.json b/backend/package.json index 0d8ea64..bc3f40d 100644 --- a/backend/package.json +++ b/backend/package.json @@ -15,7 +15,6 @@ "@types/pg": "^8.11.5", "@types/uuid": "^9.0.8", "cors": "^2.8.5", - "dotenv": "^16.4.5", "express": "^4.19.2", "pg": "^8.11.5", "uuid": "^9.0.1"