ci(docker): updated docker to correctly build and run
This commit is contained in:
69
Dockerfile
69
Dockerfile
@@ -1,49 +1,38 @@
|
|||||||
# Stage 1: Build the Express.js app
|
FROM node:24-alpine AS deps
|
||||||
FROM node:24-alpine AS app-builder
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY package*.json ./
|
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 install
|
||||||
RUN npm run build:app
|
RUN npm run install:front
|
||||||
|
RUN npm run install:docs
|
||||||
|
|
||||||
#--------------------
|
# Build the Next.js app
|
||||||
|
FROM node:24-alpine AS builder
|
||||||
# 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
|
|
||||||
WORKDIR /app
|
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 NODE_ENV=production
|
||||||
ENV RUNNING_IN_DOCKER=true
|
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
|
EXPOSE 4200
|
||||||
CMD ["node", "dist/main.js"]
|
CMD ["node", "dist/main.js"]
|
||||||
@@ -1,15 +1,18 @@
|
|||||||
import type { Express, Request, Response } from "express";
|
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) => {
|
export const setupRoutes = (app: Express, basePath: string) => {
|
||||||
// Root / health check
|
// Root / health check
|
||||||
app.use(basePath + "/health", healthRoutes);
|
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
|
// Fallback 404 handler
|
||||||
app.use((req: Request, res: Response) => {
|
app.use((req: Request, res: Response) => {
|
||||||
res.status(404).json({ error: "Not Found" });
|
res.status(404).json({ error: "Not Found" });
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|||||||
11
docker-compose.yml
Normal file
11
docker-compose.yml
Normal 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
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
"dev:app": "dotenvx run -f .env -- tsx watch app/src/main.ts",
|
"dev:app": "dotenvx run -f .env -- tsx watch app/src/main.ts",
|
||||||
"dev:docs": "cd lstDocs && npm start",
|
"dev:docs": "cd lstDocs && npm start",
|
||||||
"dev:front": "cd frontend && npm run dev",
|
"dev:front": "cd frontend && npm run dev",
|
||||||
|
"dev": "npm run dev:app",
|
||||||
"copy:docs": "node scripts/lstDocCopy.mjs",
|
"copy:docs": "node scripts/lstDocCopy.mjs",
|
||||||
"build:app": "rimraf dist && npx tsc",
|
"build:app": "rimraf dist && npx tsc",
|
||||||
"build:front": "cd frontend && rimraf dist && npm run build",
|
"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:wrapper": "cd lstWrapper && rimraf publish && dotnet publish -c Release -o ./publish",
|
||||||
"build": "npm run build:docs && npm run build:front && npm run build:app",
|
"build": "npm run build:docs && npm run build:front && npm run build:app",
|
||||||
"install:front": "cd frontend && npm i",
|
"install:front": "cd frontend && npm i",
|
||||||
"install:doc": "cd lstDocs && npm i",
|
"install:docs": "cd lstDocs && npm i",
|
||||||
"install:app": "npm i",
|
"install:app": "npm i",
|
||||||
"start:app": "set NODE_ENV=production && node dist/main.js",
|
"start:app": "set NODE_ENV=production && node dist/main.js",
|
||||||
"start": "dotenvx run -f .env -- npm run start:app",
|
"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",
|
"commit": "cz",
|
||||||
"deploy": "standard-version --conventional-commits && npm run build"
|
"deploy": "standard-version --conventional-commits && npm run build"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user