hub-server deploy

This commit is contained in:
nocnico
2025-05-26 23:57:21 +02:00
parent 6c5b2f89c6
commit e925315293
5 changed files with 53 additions and 23 deletions

View File

@@ -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 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 hub-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 3003 EXPOSE 3003
# Run container as non-root (unprivileged) user CMD ["pnpm", "--dir", "apps/hub-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"]

View File

@@ -5,13 +5,17 @@
}, },
"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/cors": "^2.8.18",
"@types/express": "^5.0.2",
"@types/node": "^22.13.5", "@types/node": "^22.13.5",
"@types/nodemailer": "^6.4.17", "@types/nodemailer": "^6.4.17",
"@types/react": "^19.1.5",
"concurrently": "^9.1.2", "concurrently": "^9.1.2",
"typescript": "latest" "typescript": "latest"
}, },

View File

@@ -2,7 +2,7 @@ import { Router } from "express";
import { sendMail } from "modules/mail"; import { sendMail } from "modules/mail";
import { sendPasswordChanged, sendCourseCompletedEmail } from "modules/mail"; import { sendPasswordChanged, sendCourseCompletedEmail } from "modules/mail";
const router = Router(); const router: Router = Router();
router.post("/send", async (req, res) => { router.post("/send", async (req, res) => {
const { to, subject, html } = req.body; const { to, subject, html } = req.body;

View File

@@ -1,7 +1,7 @@
import { Router } from "express"; import { Router } from "express";
import mailRouter from "./mail"; import mailRouter from "./mail";
const router = Router(); const router: Router = Router();
router.use("/mail", mailRouter); router.use("/mail", mailRouter);

9
pnpm-lock.yaml generated
View File

@@ -393,12 +393,21 @@ importers:
'@repo/typescript-config': '@repo/typescript-config':
specifier: '*' specifier: '*'
version: link:../../packages/typescript-config 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': '@types/node':
specifier: ^22.13.5 specifier: ^22.13.5
version: 22.15.21 version: 22.15.21
'@types/nodemailer': '@types/nodemailer':
specifier: ^6.4.17 specifier: ^6.4.17
version: 6.4.17 version: 6.4.17
'@types/react':
specifier: ^19.1.5
version: 19.1.5
concurrently: concurrently:
specifier: ^9.1.2 specifier: ^9.1.2
version: 9.1.2 version: 9.1.2