Skip to content

Commit 6903333

Browse files
committed
PEER-255 Impl .env security fixes
Signed-off-by: SeeuSim <[email protected]>
1 parent 9627990 commit 6903333

File tree

10 files changed

+33
-25
lines changed

10 files changed

+33
-25
lines changed

backend/user/.dockerignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules
2-
dist/
2+
dist/
3+
.git
4+
.env*
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
EXPRESS_ENV="local"
2-
PEERPREP_UI_HOST="http://localhost:5173"
1+
EXPRESS_ENV=local
2+
PEERPREP_UI_HOST=http://localhost:5173
33

44
EXPRESS_PORT=9001
55

66
# When run with standalone build
7-
EXPRESS_DB_HOST="host.docker.internal"
7+
EXPRESS_DB_HOST=host.docker.internal
88

99
EXPRESS_DB_PORT=5431
10-
POSTGRES_DB="user"
11-
POSTGRES_USER="peerprep-user-express"
12-
POSTGRES_PASSWORD="69/X8JxtAVsM+0YHT4RR5D7Ahf7bTobI4EED64FrzIU="
13-
PGDATA="/data/user-db"
10+
POSTGRES_DB=user
11+
POSTGRES_USER=peerprep-user-express
12+
POSTGRES_PASSWORD=69/X8JxtAVsM+0YHT4RR5D7Ahf7bTobI4EED64FrzIU=
13+
PGDATA=/data/user-db
1414

15-
EXPRESS_JWT_SECRET_KEY="jd+9qlXA0a3YsmVf2KJgyiJ3SprIR318IAwhRXck4Y8="
15+
EXPRESS_JWT_SECRET_KEY=jd+9qlXA0a3YsmVf2KJgyiJ3SprIR318IAwhRXck4Y8=

backend/user/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
1. Run this command to build:
66
```sh
77
docker build \
8-
-t user-express-local
9-
--build-arg env=local-docker-standalone \
8+
-t user-express-local \
109
--build-arg port=9001 \
1110
-f express.Dockerfile .
1211
```
@@ -19,7 +18,7 @@
1918
2019
4. Run this command to expose the container:
2120
```sh
22-
docker run -p 9001:9001 user-express-local
21+
docker run -p 9001:9001 --env-file ./.env.local-docker-standalone user-express-local
2322
```
2423
2524
## Running with Docker-Compose (Main config)

backend/user/express.Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
FROM node:lts-alpine AS build
2-
WORKDIR /data/question-express
2+
WORKDIR /data/user-express
33
COPY package*.json ./
44
RUN npm install
55
ARG env
66
COPY . .
7-
COPY ".env.${env}" .env
7+
# COPY ".env.${env}" .env
88
RUN npm run build
99

1010
FROM node:lts-alpine AS production
11-
WORKDIR /data/question-express
12-
COPY --from=build /data/question-express/package*.json ./
11+
WORKDIR /data/user-express
12+
COPY --from=build /data/user-express/package*.json ./
1313
RUN npm ci --omit=dev
14-
COPY --from=build --chown=node:node /data/question-express/dist ./dist
15-
COPY --from=build /data/question-express/.env .env
14+
COPY --from=build --chown=node:node /data/user-express/dist ./dist
15+
# COPY --from=build /data/user-express/.env .env
1616

1717
ARG port
1818
EXPOSE ${port}

backend/user/package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@
44
"main": "dist/index.js",
55
"scripts": {
66
"dev": "env-cmd -f .env.local nodemon src/index.ts | pino-pretty",
7-
"build": "env-cmd -f .env tsc && tsc-alias",
8-
"start": "env-cmd -f .env node dist/index.js",
7+
"build": "tsc && tsc-alias",
8+
"start": "node dist/index.js",
99
"build:local": "env-cmd -f .env.local tsc && tsc-alias",
1010
"start:local": "env-cmd -f .env.local node dist/index.js",
11-
"build:prod": "env-cmd -f .env.prod tsc && tsc-alias",
12-
"start:prod": "env-cmd -f .env.local node dist/index.js",
1311
"db:generate": "env-cmd -f .env.local drizzle-kit generate",
1412
"db:migrate": "env-cmd -f .env.local tsx ./src/lib/db/migrate.ts",
1513
"db:seed": "env-cmd -f .env.local tsx ./src/lib/db/seed.ts",
16-
"db:prod:migrate": "env-cmd -f .env tsx ./src/lib/db/migrate.ts",
17-
"db:prod:seed": "env-cmd -f .env tsx ./src/lib/db/seed.ts",
14+
"db:prod:migrate": "tsx ./src/lib/db/migrate.ts",
15+
"db:prod:seed": "tsx ./src/lib/db/seed.ts",
1816
"db:inspect": "env-cmd -f .env.local drizzle-kit studio",
1917
"fmt": "prettier --config .prettierrc src --write",
2018
"test": "echo \"Error: no test specified\" && exit 1"
@@ -27,6 +25,7 @@
2725
"bcrypt": "^5.1.1",
2826
"cookie-parser": "^1.4.6",
2927
"cors": "^2.8.5",
28+
"dotenv": "^16.4.5",
3029
"drizzle-orm": "^0.33.0",
3130
"env-cmd": "^10.1.0",
3231
"express": "^4.21.0",

backend/user/src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dotenv/config';
2+
13
export const JWT_SECRET_KEY = process.env.EXPRESS_JWT_SECRET_KEY!;
24

35
export const dbConfig = {

backend/user/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dotenv/config';
2+
13
import app, { dbHealthCheck } from '@/server';
24
import { logger } from '@/lib/utils';
35

backend/user/src/server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { exit } from 'process';
22

33
import cors from 'cors';
4+
import 'dotenv/config';
45
import { sql } from 'drizzle-orm';
56
import express, { json } from 'express';
67
import helmet from 'helmet';

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ services:
6767
- EXPRESS_DB_HOST=user-db
6868
- EXPRESS_DB_PORT=5432
6969
volumes:
70-
- user-service:/data/question-express
70+
- user-service:/data/user-express
7171
depends_on:
7272
- user-db
7373
networks:

package-lock.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)