From a8a94d032fa8c428e98644d09899fe66b017caa5 Mon Sep 17 00:00:00 2001 From: nocnico Date: Mon, 26 May 2025 22:10:52 +0200 Subject: [PATCH 1/5] minor changes to Deployment --- .dockerignore | 6 +++ .env.prod | 12 ------ apps/dispatch/Dockerfile | 11 +---- apps/dispatch/app/api/token/route.ts | 24 ++++------- pnpm-lock.yaml | 64 +++++++++++++++++----------- 5 files changed, 55 insertions(+), 62 deletions(-) delete mode 100644 .env.prod diff --git a/.dockerignore b/.dockerignore index 3f569ce2..e6a5744f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,10 @@ node_modules +apps/dispatch/node_modules +apps/dispatch-server/node_modules +apps/hub/node_modules +apps/hub-server/node_modules +packages/database/node_modules +packages/eslint-config/node_modules Dockerfile .dockerignore .eslint.config.msj diff --git a/.env.prod b/.env.prod deleted file mode 100644 index 88b54437..00000000 --- a/.env.prod +++ /dev/null @@ -1,12 +0,0 @@ -NEXTAUTH_SECRET=dispatch -NEXTAUTH_HUB_SECRET=var -NEXTAUTH_COOKIE_PREFIX=DISPATCH -NEXT_PUBLIC_DISPATCH_SERVER_URL=http://localhost:3002 -NEXTAUTH_URL=http://localhost:3001 -NEXT_PUBLIC_HUB_URL=http://localhost:3000 -NEXT_PUBLIC_PUBLIC_URL=http://localhost:3001 -NEXT_PUBLIC_SERVICE_ID=1 -DATABASE_URL=postgresql://persistant-data:persistant-data-pw@postgres:5432/var -NEXT_PUBLIC_LIVEKIT_URL=ws://localhost:7880 -LIVEKIT_API_KEY=APIAnsGdtdYp2Ho -LIVEKIT_API_SECRET=tdPjVsYUx8ddC7K9NvdmVAeLRF9GeADD6Fedm1x63fWC \ No newline at end of file diff --git a/apps/dispatch/Dockerfile b/apps/dispatch/Dockerfile index 164f38b2..378bc68a 100644 --- a/apps/dispatch/Dockerfile +++ b/apps/dispatch/Dockerfile @@ -1,24 +1,18 @@ FROM node:22-alpine AS base - ENV PNPM_HOME="/usr/local/pnpm" ENV PATH="${PNPM_HOME}:${PATH}" RUN corepack enable && corepack prepare pnpm@latest --activate RUN pnpm add -g turbo@^2.5 -ARG DATABASE_URL -ENV DATABASE_URL=${DATABASE_URL} - FROM base AS builder RUN apk update RUN apk add --no-cache libc6-compat WORKDIR /usr/app - COPY . . -RUN cat .env.prod RUN turbo prune dispatch --docker @@ -34,9 +28,6 @@ RUN pnpm install --frozen-lockfile # Build the project COPY --from=builder /usr/app/out/full/ . -COPY --from=builder /usr/app/.env.prod ./apps/dispatch/.env -COPY --from=builder /usr/app/.env.prod ./packages/databse/.env - RUN turbo run build FROM base AS runner @@ -52,6 +43,6 @@ USER nextjs COPY --from=installer --chown=nextjs:nodejs /usr/app/ ./ # Expose the application port -EXPOSE 3000 +EXPOSE 3001 CMD ["pnpm", "--dir", "apps/dispatch", "run", "start"] \ No newline at end of file diff --git a/apps/dispatch/app/api/token/route.ts b/apps/dispatch/app/api/token/route.ts index 7ca4d8cb..396730ea 100644 --- a/apps/dispatch/app/api/token/route.ts +++ b/apps/dispatch/app/api/token/route.ts @@ -4,20 +4,18 @@ import { AccessToken } from "livekit-server-sdk"; import { NextRequest } from "next/server"; import { prisma } from "@repo/db"; -if (!process.env.LIVEKIT_API_KEY) throw new Error("LIVEKIT_API_KEY not set"); +/* if (!process.env.LIVEKIT_API_KEY) throw new Error("LIVEKIT_API_KEY not set"); if (!process.env.LIVEKIT_API_SECRET) - throw new Error("LIVEKIT_API_SECRET not set"); + throw new Error("LIVEKIT_API_SECRET not set"); */ export const GET = async (request: NextRequest) => { const roomName = request.nextUrl.searchParams.get("roomName"); - if (!roomName) - return Response.json({ message: "Missing roomName" }, { status: 400 }); + if (!roomName) return Response.json({ message: "Missing roomName" }, { status: 400 }); const session = await getServerSession(); - if (!session) - return Response.json({ message: "Unauthorized" }, { status: 401 }); + if (!session) return Response.json({ message: "Unauthorized" }, { status: 401 }); const user = await prisma.user.findUnique({ where: { id: session.user.id, @@ -29,15 +27,11 @@ export const GET = async (request: NextRequest) => { const participantName = user.publicId; - const at = new AccessToken( - process.env.LIVEKIT_API_KEY, - process.env.LIVEKIT_API_SECRET, - { - identity: participantName, - // Token to expire after 10 minutes - ttl: "1d", - }, - ); + const at = new AccessToken(process.env.LIVEKIT_API_KEY, process.env.LIVEKIT_API_SECRET, { + identity: participantName, + // Token to expire after 10 minutes + ttl: "1d", + }); at.addGrant({ room: roomName, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 75f62fac..eae1dacd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -31,7 +31,7 @@ importers: version: 1.1.6 '@livekit/track-processors': specifier: ^0.5.6 - version: 0.5.6(livekit-client@2.13.3(@types/dom-mediacapture-record@1.0.22)) + version: 0.5.7(@types/dom-mediacapture-transform@0.1.11)(livekit-client@2.13.3(@types/dom-mediacapture-record@1.0.22)) '@next-auth/prisma-adapter': specifier: ^1.0.7 version: 1.0.7(@prisma/client@6.8.2(prisma@6.8.2(typescript@5.8.3))(typescript@5.8.3))(next-auth@4.24.11(next@15.3.2(@babel/core@7.27.1)(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(nodemailer@6.10.1)(react-dom@19.1.0(react@19.1.0))(react@19.1.0)) @@ -46,7 +46,7 @@ importers: version: 4.1.7 '@tanstack/react-query': specifier: ^5.75.4 - version: 5.77.0(react@19.1.0) + version: 5.77.2(react@19.1.0) '@types/jsonwebtoken': specifier: ^9.0.9 version: 9.0.9 @@ -234,7 +234,7 @@ importers: version: link:../../packages/database '@tanstack/react-query': specifier: ^5.67.2 - version: 5.77.0(react@19.1.0) + version: 5.77.2(react@19.1.0) '@tanstack/react-table': specifier: ^8.20.6 version: 8.21.3(react-dom@19.1.0(react@19.1.0))(react@19.1.0) @@ -282,7 +282,7 @@ importers: version: 19.1.0 react-datepicker: specifier: ^8.1.0 - version: 8.3.0(react-dom@19.1.0(react@19.1.0))(react@19.1.0) + version: 8.4.0(react-dom@19.1.0(react@19.1.0))(react@19.1.0) react-day-picker: specifier: ^9.6.2 version: 9.7.0(react@19.1.0) @@ -634,8 +634,8 @@ packages: react: '>=16.8.0' react-dom: '>=16.8.0' - '@floating-ui/react@0.27.8': - resolution: {integrity: sha512-EQJ4Th328y2wyHR3KzOUOoTW2UKjFk53fmyahfwExnFQ8vnsMYqKc+fFPOkeYtj5tcp1DUMiNJ7BFhed7e9ONw==} + '@floating-ui/react@0.27.9': + resolution: {integrity: sha512-Y0aCJBNtfVF6ikI1kVzA0WzSAhVBz79vFWOhvb5MLCRNODZ1ylGSLTuncchR7JsLyn9QzV6JD44DyZhhOtvpRw==} peerDependencies: react: '>=17.0.0' react-dom: '>=17.0.0' @@ -839,9 +839,10 @@ packages: '@livekit/protocol@1.38.0': resolution: {integrity: sha512-XX6ulvsE1XCN18LVf3ydHN7Ri1Z1M1P5dQdjnm5nVDsSqUL12Vbo/4RKcRlCEXAg2qB62mKjcaVLXVwkfXggkg==} - '@livekit/track-processors@0.5.6': - resolution: {integrity: sha512-TlzObrSlp2PKor4VXqg6iefLRFVEb2T1lXwddBFdkPod60XVgYoMOj7V5xJm+UTE2MEtlE0003vUli9PyQGB1g==} + '@livekit/track-processors@0.5.7': + resolution: {integrity: sha512-/2SkuVAF+YiPNtOi9zQJz/yH1WGaK53XZ3PaESpLOiEYUBsYky13BrriXCXUf6kwn5R5+7ZsYWc2k3XSsAuLtg==} peerDependencies: + '@types/dom-mediacapture-transform': ^0.1.9 livekit-client: ^1.12.0 || ^2.1.0 '@mediapipe/tasks-vision@0.10.14': @@ -1249,11 +1250,11 @@ packages: '@tailwindcss/postcss@4.1.7': resolution: {integrity: sha512-88g3qmNZn7jDgrrcp3ZXEQfp9CVox7xjP1HN2TFKI03CltPVd/c61ydn5qJJL8FYunn0OqBaW5HNUga0kmPVvw==} - '@tanstack/query-core@5.77.0': - resolution: {integrity: sha512-PFeWjgMQjOsnxBwnW/TJoO0pCja2dzuMQoZ3Diho7dPz7FnTUwTrjNmdf08evrhSE5nvPIKeqV6R0fvQfmhGeg==} + '@tanstack/query-core@5.77.2': + resolution: {integrity: sha512-1lqJwPsR6GX6nZFw06erRt518O19tWU6Q+x0fJUygl4lxHCYF2nhzBPwLKk2NPjYOrpR0K567hxPc5K++xDe9Q==} - '@tanstack/react-query@5.77.0': - resolution: {integrity: sha512-jX52ot8WxWzWnAknpRSEWj6PTR/7nkULOfoiaVPk6nKu0otwt30UMBC9PTg/m1x0uhz1g71/imwjViTm/oYHxA==} + '@tanstack/react-query@5.77.2': + resolution: {integrity: sha512-BRHxWdy1mHmgAcYA/qy2IPLylT81oebLgkm9K85viN2Qol/Vq48t1dzDFeDIVQjTWDV96AmqsLNPlH5HjyKCxA==} peerDependencies: react: ^18 || ^19 @@ -1294,6 +1295,12 @@ packages: '@types/dom-mediacapture-record@1.0.22': resolution: {integrity: sha512-mUMZLK3NvwRLcAAT9qmcK+9p7tpU2FHdDsntR3YI4+GY88XrgG4XiE7u1Q2LAN2/FZOz/tdMDC3GQCR4T8nFuw==} + '@types/dom-mediacapture-transform@0.1.11': + resolution: {integrity: sha512-Y2p+nGf1bF2XMttBnsVPHUWzRRZzqUoJAKmiP10b5umnO6DDrWI0BrGDJy1pOHoOULVmGSfFNkQrAlC5dcj6nQ==} + + '@types/dom-webcodecs@0.1.15': + resolution: {integrity: sha512-omOlCPvTWyPm4ZE5bZUhlSvnHM2ZWM2U+1cPiYFL/e8aV5O9MouELp+L4dMKNTON0nTeHqEg+KWDfFQMY5Wkaw==} + '@types/eslint-scope@3.7.7': resolution: {integrity: sha512-MzMFlSLBqNF2gcHWO0G1vP/YQyfvrxZ0bF+u7mzUdZ1/xK4A4sru+nraZz5i3iEIk1l1uyicaDVTB4QbbEkAYg==} @@ -3594,8 +3601,8 @@ packages: resolution: {integrity: sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==} engines: {node: '>= 0.8'} - react-datepicker@8.3.0: - resolution: {integrity: sha512-DhfrIJnTPJTUVRtXU7c7zooug40rD6q+Fc8UTCt19dYEotLpDQgTN98MfocY6Rc4S99oOFFEoxyanOM/TKauuw==} + react-datepicker@8.4.0: + resolution: {integrity: sha512-6nPDnj8vektWCIOy9ArS3avus9Ndsyz5XgFCJ7nBxXASSpBdSL6lG9jzNNmViPOAOPh6T5oJyGaXuMirBLECag==} peerDependencies: react: ^16.9.0 || ^17 || ^18 || ^19 || ^19.0.0-rc react-dom: ^16.9.0 || ^17 || ^18 || ^19 || ^19.0.0-rc @@ -4027,8 +4034,8 @@ packages: engines: {node: '>=10'} hasBin: true - tinyglobby@0.2.13: - resolution: {integrity: sha512-mEwzpUgrLySlveBwEVDMKk5B57bhLPYovRfPAXD5gA/98Opn0rCDj3GtLwFvCvH5RK9uPCExUROW5NjDwvqkxw==} + tinyglobby@0.2.14: + resolution: {integrity: sha512-tX5e7OM1HnYr2+a2C/4V0htOcSQcoSTH9KgJnVvNm5zm/cyEWKJ7j7YutsH9CxMdtOkkLFy2AHrMci9IM8IPZQ==} engines: {node: '>=12.0.0'} to-regex-range@5.0.1: @@ -4622,7 +4629,7 @@ snapshots: react: 19.1.0 react-dom: 19.1.0(react@19.1.0) - '@floating-ui/react@0.27.8(react-dom@19.1.0(react@19.1.0))(react@19.1.0)': + '@floating-ui/react@0.27.9(react-dom@19.1.0(react@19.1.0))(react@19.1.0)': dependencies: '@floating-ui/react-dom': 2.1.2(react-dom@19.1.0(react@19.1.0))(react@19.1.0) '@floating-ui/utils': 0.2.9 @@ -4783,9 +4790,10 @@ snapshots: dependencies: '@bufbuild/protobuf': 1.10.1 - '@livekit/track-processors@0.5.6(livekit-client@2.13.3(@types/dom-mediacapture-record@1.0.22))': + '@livekit/track-processors@0.5.7(@types/dom-mediacapture-transform@0.1.11)(livekit-client@2.13.3(@types/dom-mediacapture-record@1.0.22))': dependencies: '@mediapipe/tasks-vision': 0.10.14 + '@types/dom-mediacapture-transform': 0.1.11 livekit-client: 2.13.3(@types/dom-mediacapture-record@1.0.22) '@mediapipe/tasks-vision@0.10.14': {} @@ -5136,11 +5144,11 @@ snapshots: postcss: 8.5.3 tailwindcss: 4.1.7 - '@tanstack/query-core@5.77.0': {} + '@tanstack/query-core@5.77.2': {} - '@tanstack/react-query@5.77.0(react@19.1.0)': + '@tanstack/react-query@5.77.2(react@19.1.0)': dependencies: - '@tanstack/query-core': 5.77.0 + '@tanstack/query-core': 5.77.2 react: 19.1.0 '@tanstack/react-table@8.21.3(react-dom@19.1.0(react@19.1.0))(react@19.1.0)': @@ -5181,6 +5189,12 @@ snapshots: '@types/dom-mediacapture-record@1.0.22': {} + '@types/dom-mediacapture-transform@0.1.11': + dependencies: + '@types/dom-webcodecs': 0.1.15 + + '@types/dom-webcodecs@0.1.15': {} + '@types/eslint-scope@3.7.7': dependencies: '@types/eslint': 9.6.1 @@ -6218,7 +6232,7 @@ snapshots: get-tsconfig: 4.10.1 is-bun-module: 2.0.0 stable-hash: 0.0.5 - tinyglobby: 0.2.13 + tinyglobby: 0.2.14 unrs-resolver: 1.7.2 optionalDependencies: eslint-plugin-import: 2.31.0(@typescript-eslint/parser@8.32.1(eslint@9.27.0(jiti@2.4.2))(typescript@5.8.3))(eslint-import-resolver-typescript@3.10.1)(eslint@9.27.0(jiti@2.4.2)) @@ -7897,9 +7911,9 @@ snapshots: iconv-lite: 0.4.24 unpipe: 1.0.0 - react-datepicker@8.3.0(react-dom@19.1.0(react@19.1.0))(react@19.1.0): + react-datepicker@8.4.0(react-dom@19.1.0(react@19.1.0))(react@19.1.0): dependencies: - '@floating-ui/react': 0.27.8(react-dom@19.1.0(react@19.1.0))(react@19.1.0) + '@floating-ui/react': 0.27.9(react-dom@19.1.0(react@19.1.0))(react@19.1.0) clsx: 2.1.1 date-fns: 4.1.0 react: 19.1.0 @@ -8530,7 +8544,7 @@ snapshots: commander: 2.20.3 source-map-support: 0.5.21 - tinyglobby@0.2.13: + tinyglobby@0.2.14: dependencies: fdir: 6.4.4(picomatch@4.0.2) picomatch: 4.0.2 From 03acaa052f73787637aec5ed2d288cadfc330b1e Mon Sep 17 00:00:00 2001 From: nocnico Date: Mon, 26 May 2025 23:03:04 +0200 Subject: [PATCH 2/5] dispatch-server deploy --- apps/dispatch-server/Dockerfile | 59 +++++++++++++++-------- apps/dispatch-server/index.ts | 2 +- apps/dispatch-server/modules/redis.ts | 6 +-- apps/dispatch-server/package.json | 2 + apps/dispatch-server/routes/aircraft.ts | 15 ++---- apps/dispatch-server/routes/dispatcher.ts | 2 +- apps/dispatch-server/routes/livekit.ts | 22 +++------ apps/dispatch-server/routes/mission.ts | 2 +- apps/dispatch-server/routes/report.ts | 2 +- apps/dispatch-server/routes/router.ts | 2 +- apps/dispatch-server/routes/status.ts | 2 +- pnpm-lock.yaml | 3 ++ 12 files changed, 64 insertions(+), 55 deletions(-) diff --git a/apps/dispatch-server/Dockerfile b/apps/dispatch-server/Dockerfile index ae216d30..233b8c34 100644 --- a/apps/dispatch-server/Dockerfile +++ b/apps/dispatch-server/Dockerfile @@ -1,29 +1,48 @@ -FROM node:22-alpine +FROM node:22-alpine AS base + +ENV PNPM_HOME="/usr/local/pnpm" +ENV PATH="${PNPM_HOME}:${PATH}" +RUN corepack enable && corepack prepare pnpm@latest --activate + +RUN pnpm add -g turbo@^2.5 + +FROM base AS builder +RUN apk update +RUN apk add --no-cache libc6-compat -# Set the working directory WORKDIR /usr/app -# Copy package.json and package-lock.json -COPY package*.json ./ - -# Install dependencies -RUN npm install - -# Change ownership to the non-root user -RUN chown -R node:node /usr/app - -# Copy the rest of the application code COPY . . -# Build the application -RUN npm run build +RUN turbo prune dispatch-server --docker + +FROM base AS installer +RUN apk update +RUN apk add --no-cache libc6-compat + +WORKDIR /usr/app + +COPY --from=builder /usr/app/out/json/ . +RUN pnpm install --frozen-lockfile + +# Build the project +COPY --from=builder /usr/app/out/full/ . + +RUN turbo run build + +FROM base AS runner +WORKDIR /usr/app + +# Don't run production as root +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs +USER nextjs + +# Automatically leverage output traces to reduce image size +# https://nextjs.org/docs/advanced-features/output-file-tracing +COPY --from=installer --chown=nextjs:nodejs /usr/app/ ./ # Expose the application port EXPOSE 3002 -# Run container as non-root (unprivileged) user -# The "node" user is provided in the Node.js Alpine base image -USER node - -# Command to run the application -CMD ["node", "index.js"] \ No newline at end of file +CMD ["pnpm", "--dir", "apps/dispatch-server", "run", "start"] \ No newline at end of file diff --git a/apps/dispatch-server/index.ts b/apps/dispatch-server/index.ts index bac7492e..09581c3e 100644 --- a/apps/dispatch-server/index.ts +++ b/apps/dispatch-server/index.ts @@ -7,11 +7,11 @@ import { jwtMiddleware } from "modules/socketJWTmiddleware"; import { pubClient, subClient } from "modules/redis"; import { handleConnectDispatch } from "socket-events/connect-dispatch"; import router from "routes/router"; -import cors from "cors"; import { handleSendMessage } from "socket-events/send-message"; import { handleConnectPilot } from "socket-events/connect-pilot"; import { handleConnectDesktop } from "socket-events/connect-desktop"; import cookieParser from "cookie-parser"; +import cors from "cors"; import { authMiddleware } from "modules/expressMiddleware"; import { prisma, User } from "@repo/db"; import { Request, Response, NextFunction } from "express"; diff --git a/apps/dispatch-server/modules/redis.ts b/apps/dispatch-server/modules/redis.ts index 48b2e034..e31cab05 100644 --- a/apps/dispatch-server/modules/redis.ts +++ b/apps/dispatch-server/modules/redis.ts @@ -1,7 +1,7 @@ -import { createClient } from "redis"; +import { createClient, RedisClientType } from "redis"; -export const pubClient = createClient(); -export const subClient = pubClient.duplicate(); +export const pubClient: RedisClientType = createClient(); +export const subClient: RedisClientType = pubClient.duplicate(); Promise.all([pubClient.connect(), subClient.connect()]).then(() => { console.log("Redis connected"); diff --git a/apps/dispatch-server/package.json b/apps/dispatch-server/package.json index b5c753aa..24189b39 100644 --- a/apps/dispatch-server/package.json +++ b/apps/dispatch-server/package.json @@ -5,12 +5,14 @@ }, "scripts": { "dev": "nodemon --signal SIGINT", + "start": "node index.js", "build": "tsc" }, "devDependencies": { "@repo/db": "*", "@repo/typescript-config": "*", "@types/cookie-parser": "^1.4.8", + "@types/cors": "^2.8.18", "@types/express": "^5.0.0", "@types/node": "^22.13.5", "@types/nodemailer": "^6.4.17", diff --git a/apps/dispatch-server/routes/aircraft.ts b/apps/dispatch-server/routes/aircraft.ts index 86e7b59c..e3e97c21 100644 --- a/apps/dispatch-server/routes/aircraft.ts +++ b/apps/dispatch-server/routes/aircraft.ts @@ -1,14 +1,8 @@ -import { - ConnectedAircraft, - getPublicUser, - MissionLog, - Prisma, - prisma, -} from "@repo/db"; +import { ConnectedAircraft, getPublicUser, MissionLog, Prisma, prisma } from "@repo/db"; import { Router } from "express"; import { io } from "../index"; -const router = Router(); +const router: Router = Router(); // Get all connectedAircrafts router.post("/", async (req, res) => { @@ -97,10 +91,7 @@ router.patch("/:id", async (req, res) => { }); } - io.to("dispatchers").emit( - "update-connectedAircraft", - updatedConnectedAircraft, - ); + io.to("dispatchers").emit("update-connectedAircraft", updatedConnectedAircraft); io.to(`user:${updatedConnectedAircraft.userId}`).emit( "aircraft-update", updatedConnectedAircraft, diff --git a/apps/dispatch-server/routes/dispatcher.ts b/apps/dispatch-server/routes/dispatcher.ts index b56eab9b..ab38ab3a 100644 --- a/apps/dispatch-server/routes/dispatcher.ts +++ b/apps/dispatch-server/routes/dispatcher.ts @@ -2,7 +2,7 @@ import { prisma } from "@repo/db"; import { Router } from "express"; import { pubClient } from "modules/redis"; -const router = Router(); +const router: Router = Router(); router.get("/", async (req, res) => { const user = await prisma.connectedDispatcher.findMany({ diff --git a/apps/dispatch-server/routes/livekit.ts b/apps/dispatch-server/routes/livekit.ts index f48b97cd..1fb3acc9 100644 --- a/apps/dispatch-server/routes/livekit.ts +++ b/apps/dispatch-server/routes/livekit.ts @@ -2,8 +2,7 @@ import { Router } from "express"; import { AccessToken } from "livekit-server-sdk"; if (!process.env.LIVEKIT_API_KEY) throw new Error("LIVEKIT_API_KEY not set"); -if (!process.env.LIVEKIT_API_SECRET) - throw new Error("LIVEKIT_API_SECRET not set"); +if (!process.env.LIVEKIT_API_SECRET) throw new Error("LIVEKIT_API_SECRET not set"); const createToken = async (roomName: string) => { // If this room doesn't exist, it'll be automatically created when the first @@ -11,24 +10,19 @@ const createToken = async (roomName: string) => { // Identifier to be used for participant. // It's available as LocalParticipant.identity with livekit-client SDK // TODO: Move function to dispatch nextjs app as API route to use authentication of nextAuth - const participantName = - "quickstart-username" + Math.random().toString(36).substring(7); + const participantName = "quickstart-username" + Math.random().toString(36).substring(7); - const at = new AccessToken( - process.env.LIVEKIT_API_KEY, - process.env.LIVEKIT_API_SECRET, - { - identity: participantName, - // Token to expire after 10 minutes - ttl: "10m", - }, - ); + const at = new AccessToken(process.env.LIVEKIT_API_KEY, process.env.LIVEKIT_API_SECRET, { + identity: participantName, + // Token to expire after 10 minutes + ttl: "10m", + }); at.addGrant({ roomJoin: true, room: roomName }); return await at.toJwt(); }; -const router = Router(); +const router: Router = Router(); router.get("/token", async (req, res) => { const roomName = req.query.roomName as string; diff --git a/apps/dispatch-server/routes/mission.ts b/apps/dispatch-server/routes/mission.ts index 5d1b4852..11785685 100644 --- a/apps/dispatch-server/routes/mission.ts +++ b/apps/dispatch-server/routes/mission.ts @@ -12,7 +12,7 @@ import { io } from "../index"; import { sendNtfyMission } from "modules/ntfy"; import { sendAlert } from "modules/mission"; -const router = Router(); +const router: Router = Router(); // Get all missions router.post("/", async (req, res) => { diff --git a/apps/dispatch-server/routes/report.ts b/apps/dispatch-server/routes/report.ts index 00ea447c..325ffb92 100644 --- a/apps/dispatch-server/routes/report.ts +++ b/apps/dispatch-server/routes/report.ts @@ -2,7 +2,7 @@ import { Router } from "express"; import { prisma } from "@repo/db"; -const router = Router(); +const router: Router = Router(); router.put("/", async (req, res) => { try { diff --git a/apps/dispatch-server/routes/router.ts b/apps/dispatch-server/routes/router.ts index 968cf6cd..695e3d60 100644 --- a/apps/dispatch-server/routes/router.ts +++ b/apps/dispatch-server/routes/router.ts @@ -6,7 +6,7 @@ import statusRouter from "./status"; import aircraftsRouter from "./aircraft"; import reportRouter from "./report"; -const router = Router(); +const router: Router = Router(); router.use("/livekit", livekitRouter); router.use("/dispatcher", dispatcherRotuer); diff --git a/apps/dispatch-server/routes/status.ts b/apps/dispatch-server/routes/status.ts index b6beb8bc..539b1e8b 100644 --- a/apps/dispatch-server/routes/status.ts +++ b/apps/dispatch-server/routes/status.ts @@ -1,7 +1,7 @@ import { prisma } from "@repo/db"; import { Router } from "express"; -const router = Router(); +const router: Router = Router(); router.get("/connected-users", async (req, res) => { const connectedDispatcher = await prisma.connectedDispatcher.findMany({ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index eae1dacd..d69b54a9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -205,6 +205,9 @@ importers: '@types/cookie-parser': specifier: ^1.4.8 version: 1.4.8(@types/express@5.0.2) + '@types/cors': + specifier: ^2.8.18 + version: 2.8.18 '@types/express': specifier: ^5.0.0 version: 5.0.2 From 724a0249757430a0c3e0caec57123e7058347c1f Mon Sep 17 00:00:00 2001 From: nocnico Date: Mon, 26 May 2025 23:21:58 +0200 Subject: [PATCH 3/5] redis / livekit --- docker-compose.mini.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 docker-compose.mini.yml diff --git a/docker-compose.mini.yml b/docker-compose.mini.yml new file mode 100644 index 00000000..eb00514d --- /dev/null +++ b/docker-compose.mini.yml @@ -0,0 +1,27 @@ +services: + redis: + container_name: redis + image: redis/redis-stack:latest + ports: + - "6379:6379" + volumes: + - "redis_data:/data" + # Für den Zugriff auf den Host + livekit-server: + image: livekit/livekit-server + container_name: livekit_server + restart: unless-stopped + ports: + - "7880:7880" + - "7881:7881" + - "7882:7882/udp" + volumes: + - "./livekit.yaml:/livekit.yaml" + command: + - "--config" + - "/livekit.yaml" + - "--node-ip=127.0.0.1" + +volumes: + redis_data: + driver: local From 6c5b2f89c684c5511deea6d014fb90db754e5582 Mon Sep 17 00:00:00 2001 From: nocnico Date: Mon, 26 May 2025 23:50:29 +0200 Subject: [PATCH 4/5] deploy hub --- apps/hub/Dockerfile | 59 ++++++++++++++++++++++++++++--------------- apps/hub/package.json | 3 +++ pnpm-lock.yaml | 9 +++++++ tsconfig.json | 0 4 files changed, 51 insertions(+), 20 deletions(-) create mode 100644 tsconfig.json diff --git a/apps/hub/Dockerfile b/apps/hub/Dockerfile index 3ad34206..7c402f9f 100644 --- a/apps/hub/Dockerfile +++ b/apps/hub/Dockerfile @@ -1,29 +1,48 @@ -FROM node:22-alpine +FROM node:22-alpine AS base + +ENV PNPM_HOME="/usr/local/pnpm" +ENV PATH="${PNPM_HOME}:${PATH}" +RUN corepack enable && corepack prepare pnpm@latest --activate + +RUN pnpm add -g turbo@^2.5 + +FROM base AS builder +RUN apk update +RUN apk add --no-cache libc6-compat -# Set the working directory WORKDIR /usr/app -# Copy package.json and package-lock.json -COPY package*.json ./ - -# Install dependencies -RUN npm install - -# Change ownership to the non-root user -RUN chown -R node:node /usr/app - -# Copy the rest of the application code COPY . . -# Build the application -RUN npm run build +RUN turbo prune hub --docker + +FROM base AS installer +RUN apk update +RUN apk add --no-cache libc6-compat + +WORKDIR /usr/app + +COPY --from=builder /usr/app/out/json/ . +RUN pnpm install --frozen-lockfile + +# Build the project +COPY --from=builder /usr/app/out/full/ . + +RUN turbo run build + +FROM base AS runner +WORKDIR /usr/app + +# Don't run production as root +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs +USER nextjs + +# Automatically leverage output traces to reduce image size +# https://nextjs.org/docs/advanced-features/output-file-tracing +COPY --from=installer --chown=nextjs:nodejs /usr/app/ ./ # Expose the application port EXPOSE 3000 -# Run container as non-root (unprivileged) user -# The "node" user is provided in the Node.js Alpine base image -USER node - -# Command to run the application -CMD ["npm", "start"] \ No newline at end of file +CMD ["pnpm", "--dir", "apps/hub", "run", "start"] \ No newline at end of file diff --git a/apps/hub/package.json b/apps/hub/package.json index db52032b..30068323 100644 --- a/apps/hub/package.json +++ b/apps/hub/package.json @@ -11,6 +11,7 @@ "dependencies": { "@hookform/resolvers": "^4.1.3", "@next-auth/prisma-adapter": "^1.0.7", + "@radix-ui/react-icons": "^1.3.2", "@repo/db": "*", "@tanstack/react-query": "^5.67.2", "@tanstack/react-table": "^8.20.6", @@ -40,6 +41,8 @@ }, "devDependencies": { "@eslint/eslintrc": "^3", + "@repo/eslint-config": "*", + "@repo/typescript-config": "*", "@tailwindcss/postcss": "^4.0.8", "@types/bcryptjs": "^2.4.6", "@types/jsonwebtoken": "^9.0.8", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d69b54a9..32073e91 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -232,6 +232,9 @@ importers: '@next-auth/prisma-adapter': specifier: ^1.0.7 version: 1.0.7(@prisma/client@6.8.2(prisma@6.8.2(typescript@5.8.3))(typescript@5.8.3))(next-auth@4.24.11(next@15.3.2(@babel/core@7.27.1)(react-dom@19.1.0(react@19.1.0))(react@19.1.0))(nodemailer@6.10.1)(react-dom@19.1.0(react@19.1.0))(react@19.1.0)) + '@radix-ui/react-icons': + specifier: ^1.3.2 + version: 1.3.2(react@19.1.0) '@repo/db': specifier: '*' version: link:../../packages/database @@ -314,6 +317,12 @@ importers: '@eslint/eslintrc': specifier: ^3 version: 3.3.1 + '@repo/eslint-config': + specifier: '*' + version: link:../../packages/eslint-config + '@repo/typescript-config': + specifier: '*' + version: link:../../packages/typescript-config '@tailwindcss/postcss': specifier: ^4.0.8 version: 4.1.7 diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..e69de29b From e925315293b7414b99dd2e3680fe43ff71de7874 Mon Sep 17 00:00:00 2001 From: nocnico Date: Mon, 26 May 2025 23:57:21 +0200 Subject: [PATCH 5/5] hub-server deploy --- apps/hub-server/Dockerfile | 59 ++++++++++++++++++++------------ apps/hub-server/package.json | 4 +++ apps/hub-server/routes/mail.ts | 2 +- apps/hub-server/routes/router.ts | 2 +- pnpm-lock.yaml | 9 +++++ 5 files changed, 53 insertions(+), 23 deletions(-) diff --git a/apps/hub-server/Dockerfile b/apps/hub-server/Dockerfile index cfce4bee..26bee520 100644 --- a/apps/hub-server/Dockerfile +++ b/apps/hub-server/Dockerfile @@ -1,31 +1,48 @@ -FROM node:22-alpine +FROM node:22-alpine AS base -ENV NODE_ENV=production +ENV PNPM_HOME="/usr/local/pnpm" +ENV PATH="${PNPM_HOME}:${PATH}" +RUN corepack enable && corepack prepare pnpm@latest --activate + +RUN pnpm add -g turbo@^2.5 + +FROM base AS builder +RUN apk update +RUN apk add --no-cache libc6-compat -# Set the working directory WORKDIR /usr/app -# Copy package.json and package-lock.json -COPY package*.json ./ - -# Install dependencies -RUN npm install - -# Change ownership to the non-root user -RUN chown -R node:node /usr/app - -# Copy the rest of the application code COPY . . -# Build the application -RUN npm run build +RUN turbo prune hub-server --docker + +FROM base AS installer +RUN apk update +RUN apk add --no-cache libc6-compat + +WORKDIR /usr/app + +COPY --from=builder /usr/app/out/json/ . +RUN pnpm install --frozen-lockfile + +# Build the project +COPY --from=builder /usr/app/out/full/ . + +RUN turbo run build + +FROM base AS runner +WORKDIR /usr/app + +# Don't run production as root +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs +USER nextjs + +# Automatically leverage output traces to reduce image size +# https://nextjs.org/docs/advanced-features/output-file-tracing +COPY --from=installer --chown=nextjs:nodejs /usr/app/ ./ # Expose the application port EXPOSE 3003 -# Run container as non-root (unprivileged) user -# The "node" user is provided in the Node.js Alpine base image -USER node - -# Command to run the application -CMD ["node", "index.js"] \ No newline at end of file +CMD ["pnpm", "--dir", "apps/hub-server", "run", "start"] \ No newline at end of file diff --git a/apps/hub-server/package.json b/apps/hub-server/package.json index 6625cc67..68a82b21 100644 --- a/apps/hub-server/package.json +++ b/apps/hub-server/package.json @@ -5,13 +5,17 @@ }, "scripts": { "dev": "nodemon --signal SIGINT", + "start": "node index.js", "build": "tsc" }, "devDependencies": { "@repo/db": "*", "@repo/typescript-config": "*", + "@types/cors": "^2.8.18", + "@types/express": "^5.0.2", "@types/node": "^22.13.5", "@types/nodemailer": "^6.4.17", + "@types/react": "^19.1.5", "concurrently": "^9.1.2", "typescript": "latest" }, diff --git a/apps/hub-server/routes/mail.ts b/apps/hub-server/routes/mail.ts index 2ef4c4b1..0c0629bb 100644 --- a/apps/hub-server/routes/mail.ts +++ b/apps/hub-server/routes/mail.ts @@ -2,7 +2,7 @@ import { Router } from "express"; import { sendMail } from "modules/mail"; import { sendPasswordChanged, sendCourseCompletedEmail } from "modules/mail"; -const router = Router(); +const router: Router = Router(); router.post("/send", async (req, res) => { const { to, subject, html } = req.body; diff --git a/apps/hub-server/routes/router.ts b/apps/hub-server/routes/router.ts index cc322f43..49dd5d77 100644 --- a/apps/hub-server/routes/router.ts +++ b/apps/hub-server/routes/router.ts @@ -1,7 +1,7 @@ import { Router } from "express"; import mailRouter from "./mail"; -const router = Router(); +const router: Router = Router(); router.use("/mail", mailRouter); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 32073e91..1f05d412 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -393,12 +393,21 @@ importers: '@repo/typescript-config': specifier: '*' version: link:../../packages/typescript-config + '@types/cors': + specifier: ^2.8.18 + version: 2.8.18 + '@types/express': + specifier: ^5.0.2 + version: 5.0.2 '@types/node': specifier: ^22.13.5 version: 22.15.21 '@types/nodemailer': specifier: ^6.4.17 version: 6.4.17 + '@types/react': + specifier: ^19.1.5 + version: 19.1.5 concurrently: specifier: ^9.1.2 version: 9.1.2