ci(docker): updated docker to correctly build and run

This commit is contained in:
2025-08-31 09:07:06 -05:00
parent e75883e587
commit f348e4e053
4 changed files with 55 additions and 51 deletions

View File

@@ -1,49 +1,38 @@
# Stage 1: Build the Express.js app
FROM node:24-alpine AS app-builder
FROM node:24-alpine AS deps
WORKDIR /app
COPY package*.json ./
COPY app ./app
RUN mkdir frontend
RUN mkdir lstDocs
COPY frontend/package*.json ./frontend
COPY lstDocs/package*.json ./lstDocs
RUN npm install
RUN npm run build:app
RUN npm run install:front
RUN npm run install:docs
#--------------------
# Stage 2: Build the Docusaurus docs
FROM node:24-alpine AS docs-builder
WORKDIR /app/lstDocs
COPY lstDocs/package*.json ./
COPY --from=app-builder /app/node_modules /app/node_modules
COPY lstDocs ./
RUN npm install
RUN npm run build
#--------------------
# Stage 3: Build the Vite frontend
FROM node:24-alpine AS front-builder
WORKDIR /app/frontend
COPY frontend/package*.json ./
COPY --from=app-builder /app/node_modules /app/node_modules
COPY frontend ./
RUN npm install
RUN npm run build
#--------------------
# Stage 4: Create the final production image
FROM node:24-alpine AS runner
# Build the Next.js app
FROM node:24-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY --from=deps /app/frontend/node_modules ./frontend/node_modules
COPY --from=deps /app/lstDocs/node_modules ./lstDocs/node_modules
COPY . ./
RUN npm run build:app
RUN npm run build:front
RUN npm run build:docs
# Final stage
FROM node:24-alpine
WORKDIR /app
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/frontend/dist ./frontend/dist
COPY --from=builder /app/lstDocs/build ./lstDocs/build
ENV NODE_ENV=production
ENV RUNNING_IN_DOCKER=true
# Copy production dependencies for the main app
COPY package*.json ./
RUN npm install --omit=dev --ignore-scripts
# Copy the built artifacts from each builder stage
COPY --from=app-builder /app/dist ./dist
COPY --from=docs-builder /app/lstDocs/build ./lstDocs/build
COPY --from=front-builder /app/frontend/dist ./frontend/dist
EXPOSE 4200
CMD ["node", "dist/main.js"]

View File

@@ -1,15 +1,18 @@
import type { Express, Request, Response } from "express";
import healthRoutes from './routes/healthRoutes.js'
import healthRoutes from "./routes/healthRoutes.js";
export const setupRoutes = (app: Express, basePath: string) => {
// Root / health check
app.use(basePath + "/health", healthRoutes);
// Root / health check
app.use(basePath + "/health", healthRoutes);
// always try to go to the app weather we are in dev or in production.
app.get(basePath + "/", (req: Request, res: Response) => {
res.redirect(basePath + "/app");
});
// Fallback 404 handler
app.use((req: Request, res: Response) => {
res.status(404).json({ error: "Not Found" });
});
}
// Fallback 404 handler
app.use((req: Request, res: Response) => {
res.status(404).json({ error: "Not Found" });
});
};

11
docker-compose.yml Normal file
View File

@@ -0,0 +1,11 @@
services:
app:
build:
context: .
dockerfile: Dockerfile
container_name: lst
ports:
- "${VITE_PORT:-4200}:4200"
environment:
- NODE_ENV=devolpment
restart: unless-stopped

View File

@@ -8,6 +8,7 @@
"dev:app": "dotenvx run -f .env -- tsx watch app/src/main.ts",
"dev:docs": "cd lstDocs && npm start",
"dev:front": "cd frontend && npm run dev",
"dev": "npm run dev:app",
"copy:docs": "node scripts/lstDocCopy.mjs",
"build:app": "rimraf dist && npx tsc",
"build:front": "cd frontend && rimraf dist && npm run build",
@@ -15,11 +16,11 @@
"build:wrapper": "cd lstWrapper && rimraf publish && dotnet publish -c Release -o ./publish",
"build": "npm run build:docs && npm run build:front && npm run build:app",
"install:front": "cd frontend && npm i",
"install:doc": "cd lstDocs && npm i",
"install:docs": "cd lstDocs && npm i",
"install:app": "npm i",
"start:app": "set NODE_ENV=production && node dist/main.js",
"start": "dotenvx run -f .env -- npm run start:app",
"docker": "docker build --no-cache -t lst-test .",
"docker": "docker compose up --build --force-recreate -d",
"commit": "cz",
"deploy": "standard-version --conventional-commits && npm run build"
},