diff options
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/.dockerignore | 10 | ||||
| -rw-r--r-- | backend/.env.docker | 11 | ||||
| -rw-r--r-- | backend/.env.sample | 2 | ||||
| -rw-r--r-- | backend/Dockerfile | 43 | ||||
| -rw-r--r-- | backend/package.json | 2 | ||||
| -rw-r--r-- | backend/src/controllers/moveAllRobots.ts | 2 | ||||
| -rw-r--r-- | backend/src/controllers/moveRobot.ts | 2 | ||||
| -rw-r--r-- | backend/src/controllers/stopAllRobots.ts | 2 | ||||
| -rw-r--r-- | backend/src/controllers/stopRobot.ts | 2 |
9 files changed, 70 insertions, 6 deletions
diff --git a/backend/.dockerignore b/backend/.dockerignore new file mode 100644 index 0000000..9f8fe0e --- /dev/null +++ b/backend/.dockerignore @@ -0,0 +1,10 @@ +**/.env +**/.git +**/.gitignore +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/build +**/dist +LICENSE +README.md
\ No newline at end of file diff --git a/backend/.env.docker b/backend/.env.docker new file mode 100644 index 0000000..88fdf64 --- /dev/null +++ b/backend/.env.docker @@ -0,0 +1,11 @@ +DB_DATABASE=robot_tracker_db +DB_HOST=postgres +DB_PASSWORD=roboMaster123 +DB_PORT=5432 +DB_USER=robot_master +JWT_SECRET="Secret_JWT-Secret_strinG" +PORT=3000 +REDIS_HOST=redis +REDIS_USER=default +REDIS_PASSWORD=redispassword +REDIS_PORT=6379
\ No newline at end of file diff --git a/backend/.env.sample b/backend/.env.sample index 027003e..3045036 100644 --- a/backend/.env.sample +++ b/backend/.env.sample @@ -5,7 +5,7 @@ DB_PORT=5432 DB_USER=db_user_name JWT_SECRET="yourJWTstr1ng" PORT=3000 -REDIS_HOST=einfac-redis-oder-url-zur-cloud +REDIS_HOST=redis-oder-url-zur-cloud REDIS_USER=default REDIS_PASSWORD=redisPw REDIS_PORT=6379
\ No newline at end of file diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..47a96e6 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,43 @@ +# syntax=docker/dockerfile:1 + +# BUILD STAGE +FROM node:22-alpine AS builder + +WORKDIR /app + +COPY package*.json ./ + +# Install all dependencies, dev dependencies needed for build +RUN npm ci + +COPY . . + +# Build TypeScript +RUN npm run build + +# PRODUCTION STAGE +FROM node:22-alpine AS production + +WORKDIR /app + +COPY package*.json ./ + +# Install only production dependencies +RUN npm ci --omit=dev + +# Copy .env.docker to .env to silence Docker warning +COPY .env.docker .env + +# Copy compiled code from builder stage +COPY --from=builder /app/dist ./dist + +# Create non-root user for security +RUN addgroup -g 1001 -S nodejs && \ + adduser -S nodejs -u 1001 && \ + chown -R nodejs:nodejs /app + +USER nodejs + +EXPOSE 3000 + +CMD ["npm", "start"]
\ No newline at end of file diff --git a/backend/package.json b/backend/package.json index 73f22a7..ff53313 100644 --- a/backend/package.json +++ b/backend/package.json @@ -8,7 +8,7 @@ "main": "dist/server.js", "scripts": { "dev": "tsx watch --env-file=.env src/server.ts", - "start": "node dist/server.js", + "start": "node --env-file=.env dist/server.js", "build": "tsc", "type-check": "tsc --noEmit", "test": "echo \"Error: no test specified\" && exit 1" diff --git a/backend/src/controllers/moveAllRobots.ts b/backend/src/controllers/moveAllRobots.ts index e4d1252..e7291b6 100644 --- a/backend/src/controllers/moveAllRobots.ts +++ b/backend/src/controllers/moveAllRobots.ts @@ -1,6 +1,6 @@ import { Request, Response } from "express"; import { Server } from "socket.io"; -import { setAllRobotsMoving } from "../simulation/robotMovementSimulator"; +import { setAllRobotsMoving } from "../simulation/robotMovementSimulator.js"; import { ErrorResponse } from "../types/error"; import { SimulationResponse } from "../types/robot"; diff --git a/backend/src/controllers/moveRobot.ts b/backend/src/controllers/moveRobot.ts index 1b53f17..a26b56c 100644 --- a/backend/src/controllers/moveRobot.ts +++ b/backend/src/controllers/moveRobot.ts @@ -1,6 +1,6 @@ import { Request, Response } from "express"; import { Server } from "socket.io"; -import { setRobotMoving } from "../simulation/robotMovementSimulator"; +import { setRobotMoving } from "../simulation/robotMovementSimulator.js"; import { ErrorResponse } from "../types/error"; import { SimulationResponse } from "../types/robot"; diff --git a/backend/src/controllers/stopAllRobots.ts b/backend/src/controllers/stopAllRobots.ts index 7218e66..a0680b2 100644 --- a/backend/src/controllers/stopAllRobots.ts +++ b/backend/src/controllers/stopAllRobots.ts @@ -1,5 +1,5 @@ import { Request, Response } from "express"; -import { setAllRobotsIdle } from "../simulation/robotMovementSimulator"; +import { setAllRobotsIdle } from "../simulation/robotMovementSimulator.js"; import { ErrorResponse } from "../types/error"; import { SimulationResponse } from "../types/robot"; diff --git a/backend/src/controllers/stopRobot.ts b/backend/src/controllers/stopRobot.ts index d0d7c4f..af98329 100644 --- a/backend/src/controllers/stopRobot.ts +++ b/backend/src/controllers/stopRobot.ts @@ -1,5 +1,5 @@ import { Request, Response } from "express"; -import { setRobotIdle } from "../simulation/robotMovementSimulator"; +import { setRobotIdle } from "../simulation/robotMovementSimulator.js"; import { ErrorResponse } from "../types/error"; import { SimulationResponse } from "../types/robot"; |
