dispatch-server deploy
This commit is contained in:
@@ -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
|
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 . .
|
COPY . .
|
||||||
|
|
||||||
# Build the application
|
RUN turbo prune dispatch-server --docker
|
||||||
RUN npm run build
|
|
||||||
|
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 the application port
|
||||||
EXPOSE 3002
|
EXPOSE 3002
|
||||||
|
|
||||||
# Run container as non-root (unprivileged) user
|
CMD ["pnpm", "--dir", "apps/dispatch-server", "run", "start"]
|
||||||
# The "node" user is provided in the Node.js Alpine base image
|
|
||||||
USER node
|
|
||||||
|
|
||||||
# Command to run the application
|
|
||||||
CMD ["node", "index.js"]
|
|
||||||
@@ -7,11 +7,11 @@ import { jwtMiddleware } from "modules/socketJWTmiddleware";
|
|||||||
import { pubClient, subClient } from "modules/redis";
|
import { pubClient, subClient } from "modules/redis";
|
||||||
import { handleConnectDispatch } from "socket-events/connect-dispatch";
|
import { handleConnectDispatch } from "socket-events/connect-dispatch";
|
||||||
import router from "routes/router";
|
import router from "routes/router";
|
||||||
import cors from "cors";
|
|
||||||
import { handleSendMessage } from "socket-events/send-message";
|
import { handleSendMessage } from "socket-events/send-message";
|
||||||
import { handleConnectPilot } from "socket-events/connect-pilot";
|
import { handleConnectPilot } from "socket-events/connect-pilot";
|
||||||
import { handleConnectDesktop } from "socket-events/connect-desktop";
|
import { handleConnectDesktop } from "socket-events/connect-desktop";
|
||||||
import cookieParser from "cookie-parser";
|
import cookieParser from "cookie-parser";
|
||||||
|
import cors from "cors";
|
||||||
import { authMiddleware } from "modules/expressMiddleware";
|
import { authMiddleware } from "modules/expressMiddleware";
|
||||||
import { prisma, User } from "@repo/db";
|
import { prisma, User } from "@repo/db";
|
||||||
import { Request, Response, NextFunction } from "express";
|
import { Request, Response, NextFunction } from "express";
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { createClient } from "redis";
|
import { createClient, RedisClientType } from "redis";
|
||||||
|
|
||||||
export const pubClient = createClient();
|
export const pubClient: RedisClientType = createClient();
|
||||||
export const subClient = pubClient.duplicate();
|
export const subClient: RedisClientType = pubClient.duplicate();
|
||||||
|
|
||||||
Promise.all([pubClient.connect(), subClient.connect()]).then(() => {
|
Promise.all([pubClient.connect(), subClient.connect()]).then(() => {
|
||||||
console.log("Redis connected");
|
console.log("Redis connected");
|
||||||
|
|||||||
@@ -5,12 +5,14 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "nodemon --signal SIGINT",
|
"dev": "nodemon --signal SIGINT",
|
||||||
|
"start": "node index.js",
|
||||||
"build": "tsc"
|
"build": "tsc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@repo/db": "*",
|
"@repo/db": "*",
|
||||||
"@repo/typescript-config": "*",
|
"@repo/typescript-config": "*",
|
||||||
"@types/cookie-parser": "^1.4.8",
|
"@types/cookie-parser": "^1.4.8",
|
||||||
|
"@types/cors": "^2.8.18",
|
||||||
"@types/express": "^5.0.0",
|
"@types/express": "^5.0.0",
|
||||||
"@types/node": "^22.13.5",
|
"@types/node": "^22.13.5",
|
||||||
"@types/nodemailer": "^6.4.17",
|
"@types/nodemailer": "^6.4.17",
|
||||||
|
|||||||
@@ -1,14 +1,8 @@
|
|||||||
import {
|
import { ConnectedAircraft, getPublicUser, MissionLog, Prisma, prisma } from "@repo/db";
|
||||||
ConnectedAircraft,
|
|
||||||
getPublicUser,
|
|
||||||
MissionLog,
|
|
||||||
Prisma,
|
|
||||||
prisma,
|
|
||||||
} from "@repo/db";
|
|
||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
import { io } from "../index";
|
import { io } from "../index";
|
||||||
|
|
||||||
const router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
// Get all connectedAircrafts
|
// Get all connectedAircrafts
|
||||||
router.post("/", async (req, res) => {
|
router.post("/", async (req, res) => {
|
||||||
@@ -97,10 +91,7 @@ router.patch("/:id", async (req, res) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
io.to("dispatchers").emit(
|
io.to("dispatchers").emit("update-connectedAircraft", updatedConnectedAircraft);
|
||||||
"update-connectedAircraft",
|
|
||||||
updatedConnectedAircraft,
|
|
||||||
);
|
|
||||||
io.to(`user:${updatedConnectedAircraft.userId}`).emit(
|
io.to(`user:${updatedConnectedAircraft.userId}`).emit(
|
||||||
"aircraft-update",
|
"aircraft-update",
|
||||||
updatedConnectedAircraft,
|
updatedConnectedAircraft,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { prisma } from "@repo/db";
|
|||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
import { pubClient } from "modules/redis";
|
import { pubClient } from "modules/redis";
|
||||||
|
|
||||||
const router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
router.get("/", async (req, res) => {
|
router.get("/", async (req, res) => {
|
||||||
const user = await prisma.connectedDispatcher.findMany({
|
const user = await prisma.connectedDispatcher.findMany({
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ import { Router } from "express";
|
|||||||
import { AccessToken } from "livekit-server-sdk";
|
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_KEY) throw new Error("LIVEKIT_API_KEY not set");
|
||||||
if (!process.env.LIVEKIT_API_SECRET)
|
if (!process.env.LIVEKIT_API_SECRET) throw new Error("LIVEKIT_API_SECRET not set");
|
||||||
throw new Error("LIVEKIT_API_SECRET not set");
|
|
||||||
|
|
||||||
const createToken = async (roomName: string) => {
|
const createToken = async (roomName: string) => {
|
||||||
// If this room doesn't exist, it'll be automatically created when the first
|
// 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.
|
// Identifier to be used for participant.
|
||||||
// It's available as LocalParticipant.identity with livekit-client SDK
|
// 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
|
// TODO: Move function to dispatch nextjs app as API route to use authentication of nextAuth
|
||||||
const participantName =
|
const participantName = "quickstart-username" + Math.random().toString(36).substring(7);
|
||||||
"quickstart-username" + Math.random().toString(36).substring(7);
|
|
||||||
|
|
||||||
const at = new AccessToken(
|
const at = new AccessToken(process.env.LIVEKIT_API_KEY, process.env.LIVEKIT_API_SECRET, {
|
||||||
process.env.LIVEKIT_API_KEY,
|
identity: participantName,
|
||||||
process.env.LIVEKIT_API_SECRET,
|
// Token to expire after 10 minutes
|
||||||
{
|
ttl: "10m",
|
||||||
identity: participantName,
|
});
|
||||||
// Token to expire after 10 minutes
|
|
||||||
ttl: "10m",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
at.addGrant({ roomJoin: true, room: roomName });
|
at.addGrant({ roomJoin: true, room: roomName });
|
||||||
|
|
||||||
return await at.toJwt();
|
return await at.toJwt();
|
||||||
};
|
};
|
||||||
|
|
||||||
const router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
router.get("/token", async (req, res) => {
|
router.get("/token", async (req, res) => {
|
||||||
const roomName = req.query.roomName as string;
|
const roomName = req.query.roomName as string;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { io } from "../index";
|
|||||||
import { sendNtfyMission } from "modules/ntfy";
|
import { sendNtfyMission } from "modules/ntfy";
|
||||||
import { sendAlert } from "modules/mission";
|
import { sendAlert } from "modules/mission";
|
||||||
|
|
||||||
const router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
// Get all missions
|
// Get all missions
|
||||||
router.post("/", async (req, res) => {
|
router.post("/", async (req, res) => {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Router } from "express";
|
|||||||
|
|
||||||
import { prisma } from "@repo/db";
|
import { prisma } from "@repo/db";
|
||||||
|
|
||||||
const router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
router.put("/", async (req, res) => {
|
router.put("/", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import statusRouter from "./status";
|
|||||||
import aircraftsRouter from "./aircraft";
|
import aircraftsRouter from "./aircraft";
|
||||||
import reportRouter from "./report";
|
import reportRouter from "./report";
|
||||||
|
|
||||||
const router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
router.use("/livekit", livekitRouter);
|
router.use("/livekit", livekitRouter);
|
||||||
router.use("/dispatcher", dispatcherRotuer);
|
router.use("/dispatcher", dispatcherRotuer);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { prisma } from "@repo/db";
|
import { prisma } from "@repo/db";
|
||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
|
|
||||||
const router = Router();
|
const router: Router = Router();
|
||||||
|
|
||||||
router.get("/connected-users", async (req, res) => {
|
router.get("/connected-users", async (req, res) => {
|
||||||
const connectedDispatcher = await prisma.connectedDispatcher.findMany({
|
const connectedDispatcher = await prisma.connectedDispatcher.findMany({
|
||||||
|
|||||||
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@@ -205,6 +205,9 @@ importers:
|
|||||||
'@types/cookie-parser':
|
'@types/cookie-parser':
|
||||||
specifier: ^1.4.8
|
specifier: ^1.4.8
|
||||||
version: 1.4.8(@types/express@5.0.2)
|
version: 1.4.8(@types/express@5.0.2)
|
||||||
|
'@types/cors':
|
||||||
|
specifier: ^2.8.18
|
||||||
|
version: 2.8.18
|
||||||
'@types/express':
|
'@types/express':
|
||||||
specifier: ^5.0.0
|
specifier: ^5.0.0
|
||||||
version: 5.0.2
|
version: 5.0.2
|
||||||
|
|||||||
Reference in New Issue
Block a user