From 780335d35c903da0ca47e98ce9dbe635ab203d18 Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Tue, 13 Jan 2026 17:05:23 -0600 Subject: [PATCH] feat(docker): added in docker build stuff to run this in docker as well as windows service --- .dockerignore | 5 +++- .gitignore | 1 + Dockerfile | 41 ++++++++++++++++++++++------- Dockerfile-bak | 42 ------------------------------ docker-compose.yml | 65 +++++++++++++++++++++++----------------------- 5 files changed, 69 insertions(+), 85 deletions(-) delete mode 100644 Dockerfile-bak diff --git a/.dockerignore b/.dockerignore index e953a2b..d11b3a6 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,7 @@ node_modules +.git +.env dist Dockerfile -docker-compose.yml \ No newline at end of file +docker-compose.yml +npm-debug.log \ No newline at end of file diff --git a/.gitignore b/.gitignore index 2309cc8..88b5148 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # ---> Node +testFiles # Logs logs *.log diff --git a/Dockerfile b/Dockerfile index 32b2c7f..ca4565e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,44 @@ -FROM node:24.12-alpine +########### +# Stage 1 # +########### +# Build stage with all dependencies +FROM node:24.12-alpine as build WORKDIR /app # Copy package files -COPY package*.json ./ +COPY . . # Install production dependencies only RUN npm ci -RUN npm build:app +RUN npm run build -# Copy built app from builder stage -COPY --from=builder /app/dist ./dist +########### +# Stage 2 # +########### +# Small final image with only what’s needed to run +FROM node:24.12-alpine AS production -# Environment variables with defaults -ENV PORT=3000 -ENV DB_USER=admin -ENV DB_PASSWORD=changeme +WORKDIR /app +# Copy package files first to install runtime deps +COPY package*.json ./ + +# curl install +RUN apk add --no-cache curl + +# Only install production dependencies +RUN npm ci --omit=dev + + +COPY --from=build /app/dist ./dist + +ENV RUNNING_IN_DOCKER=true EXPOSE 3000 +# start the app up +CMD ["npm", "run", "start:docker"] -CMD ["node", "dist/index.js"] \ No newline at end of file +# Add health check +HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ + CMD curl -f http://localhost:3000/lst/api/stats || exit 1 \ No newline at end of file diff --git a/Dockerfile-bak b/Dockerfile-bak deleted file mode 100644 index c5413ae..0000000 --- a/Dockerfile-bak +++ /dev/null @@ -1,42 +0,0 @@ -FROM node:24-alpine AS deps -WORKDIR /app -COPY package.json ./ -RUN ls -la /app -#RUN mkdir frontend -#RUN mkdir lstDocs -#RUN mkdir controller -#COPY frontend/package*.json ./frontend -#COPY lstDocs/package*.json ./lstDocs -#COPY controller/index.html ./controller - -RUN npm install -#RUN npm run install:front -#RUN npm run install:docs - -# 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 --from=deps /app/controller/index.html ./controller/index.html -#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 -#COPY --from=deps /app/controller/index.html ./controller/index.html - - -ENV NODE_ENV=production -ENV RUNNING_IN_DOCKER=true -ENV PORT=3000 -EXPOSE 3000 -CMD ["node", "dist/index.js"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index bd7fe00..570e44c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,44 +6,45 @@ services: container_name: lst_app ports: #- "${VITE_PORT:-4200}:4200" - - "4000:4200" + - "3600:3000" environment: - - NODE_ENV=development - # - DATABASE_HOST=host.docker.internal - # - DATABASE_PORT=${DATABASE_PORT} - # - DATABASE_USER=${DATABASE_USER} - # - DATABASE_PASSWORD=${DATABASE_PASSWORD} - # - DATABASE_DB=${DATABASE_DB} + - NODE_ENV=production + - LOG_LEVEL=info + - DATABASE_HOST=host.docker.internal + - DATABASE_PORT=5433 + - DATABASE_USER=${DATABASE_USER} + - DATABASE_PASSWORD=${DATABASE_PASSWORD} + - DATABASE_DB=${DATABASE_DB} - PROD_SERVER=${PROD_SERVER} - PROD_PLANT_TOKEN=${PROD_PLANT_TOKEN} - PROD_USER=${PROD_USER} - PROD_PASSWORD=${PROD_PASSWORD} - # - BETTER_AUTH_SECRET=${BETTER_AUTH_SECRET} - # - BETTER_AUTH_URL=${BETTER_AUTH_URL} + - BETTER_AUTH_SECRET=${BETTER_AUTH_SECRET} + - BETTER_AUTH_URL=${URL} restart: unless-stopped # for all host including prod servers, plc's, printers, or other de - extra_hosts: - - "${PROD_SERVER}:${PROD_IP}" +# extra_hosts: +# - "${PROD_SERVER}:${PROD_IP}" - networks: - - default - - logisticsNetwork - - mlan1 -networks: - logisticsNetwork: - driver: macvlan - driver_opts: - parent: eth0 - ipam: - config: - - subnet: ${LOGISTICS_NETWORK} - gateway: ${LOGISTICS_GATEWAY} +# networks: +# - default +# - logisticsNetwork +# #- mlan1 +# networks: +# logisticsNetwork: +# driver: macvlan +# driver_opts: +# parent: eth0 +# ipam: +# config: +# - subnet: ${LOGISTICS_NETWORK} +# gateway: ${LOGISTICS_GATEWAY} - mlan1: - driver: macvlan - driver_opts: - parent: eth0 - ipam: - config: - - subnet: ${MLAN1_NETWORK} - gateway: ${MLAN1_GATEWAY} +# mlan1: +# driver: macvlan +# driver_opts: +# parent: eth0 +# ipam: +# config: +# - subnet: ${MLAN1_NETWORK} +# gateway: ${MLAN1_GATEWAY}