Add supervisor + Postgres/Redis integration for TrueNAS deployment
This commit is contained in:
+35
-1
@@ -1,17 +1,51 @@
|
|||||||
|
# ---------------------------------------------------------
|
||||||
|
# Builder stage
|
||||||
|
# ---------------------------------------------------------
|
||||||
FROM node:20-alpine AS builder
|
FROM node:20-alpine AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
RUN npm install
|
RUN npm install
|
||||||
|
|
||||||
|
# FIX: Install TypeScript so "tsc" exists
|
||||||
|
RUN npm install -g typescript
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
|
# ---------------------------------------------------------
|
||||||
|
# Final runtime image
|
||||||
|
# ---------------------------------------------------------
|
||||||
FROM node:20-alpine
|
FROM node:20-alpine
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Install system packages needed for Postgres, Redis, Supervisor
|
||||||
|
RUN apk update && apk add --no-cache \
|
||||||
|
supervisor \
|
||||||
|
postgresql16 \
|
||||||
|
postgresql16-client \
|
||||||
|
redis \
|
||||||
|
bash
|
||||||
|
|
||||||
|
# Create directories for Postgres, Redis, and Supervisor logs
|
||||||
|
RUN mkdir -p /var/lib/postgresql/data \
|
||||||
|
&& mkdir -p /var/lib/redis \
|
||||||
|
&& mkdir -p /var/log/supervisor
|
||||||
|
|
||||||
|
# FIX OWNERSHIP (required for Alpine Postgres + Redis to start)
|
||||||
|
RUN chown -R postgres:postgres /var/lib/postgresql \
|
||||||
|
&& chown -R redis:redis /var/lib/redis
|
||||||
|
|
||||||
|
# Copy built app from builder
|
||||||
COPY --from=builder /app/node_modules ./node_modules
|
COPY --from=builder /app/node_modules ./node_modules
|
||||||
COPY --from=builder /app/dist ./dist
|
COPY --from=builder /app/dist ./dist
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
|
|
||||||
CMD ["node", "dist/index.js"]
|
# Copy supervisor config
|
||||||
|
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
||||||
|
|
||||||
|
# Expose API port
|
||||||
|
EXPOSE 3333
|
||||||
|
|
||||||
|
# Start supervisor (which starts Postgres, Redis, API, Worker)
|
||||||
|
CMD ["/usr/bin/supervisord", "-n"]
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
[supervisord]
|
||||||
|
nodaemon=true
|
||||||
|
logfile=/var/log/supervisor/supervisord.log
|
||||||
|
|
||||||
|
[program:postgres]
|
||||||
|
command=/usr/bin/postgres -D /var/lib/postgresql/data
|
||||||
|
autostart=true
|
||||||
|
autorestart=true
|
||||||
|
priority=10
|
||||||
|
|
||||||
|
[program:redis]
|
||||||
|
command=/usr/bin/redis-server --appendonly yes
|
||||||
|
autostart=true
|
||||||
|
autorestart=true
|
||||||
|
priority=20
|
||||||
|
|
||||||
|
[program:api]
|
||||||
|
command=node dist/index.js
|
||||||
|
directory=/app
|
||||||
|
autostart=true
|
||||||
|
autorestart=true
|
||||||
|
priority=30
|
||||||
|
environment=NODE_ENV="production"
|
||||||
|
|
||||||
|
[program:worker]
|
||||||
|
command=node dist/worker.js
|
||||||
|
directory=/app
|
||||||
|
autostart=true
|
||||||
|
autorestart=true
|
||||||
|
priority=40
|
||||||
|
environment=NODE_ENV="production"
|
||||||
Reference in New Issue
Block a user