Set up Docker environment for local development and deployment

Configure Docker Compose, Dockerfiles for API and web servers, and a startup script to enable local development and deployment of the application.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 77cfe984-2c65-4152-bb7a-0df28274fe66
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: 9b39e228-74f1-466d-ab5c-87a1e5e7ed07
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/c3c252e4-c83d-40ca-9fff-99a3ea60701e/77cfe984-2c65-4152-bb7a-0df28274fe66/kI0sxlu
Replit-Helium-Checkpoint-Created: true
This commit is contained in:
riyadhafraa
2026-05-13 19:47:05 +00:00
parent 3af737186d
commit d70ee83a63
8 changed files with 403 additions and 185 deletions
+57
View File
@@ -0,0 +1,57 @@
FROM node:24-bookworm-slim AS base
ENV PNPM_HOME=/pnpm
ENV PATH=$PNPM_HOME:$PATH
RUN corepack enable && corepack prepare pnpm@10.26.1 --activate
RUN apt-get update && apt-get install -y --no-install-recommends \
chromium \
fonts-noto \
fonts-noto-color-emoji \
fonts-noto-cjk \
ca-certificates \
curl \
tini \
&& rm -rf /var/lib/apt/lists/*
ENV PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium
ENV PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
WORKDIR /app
FROM base AS deps
COPY pnpm-workspace.yaml pnpm-lock.yaml package.json ./
COPY artifacts/api-server/package.json artifacts/api-server/
COPY artifacts/tx-os/package.json artifacts/tx-os/
COPY lib/api-client-react/package.json lib/api-client-react/
COPY lib/api-spec/package.json lib/api-spec/
COPY lib/api-zod/package.json lib/api-zod/
COPY lib/db/package.json lib/db/
COPY lib/object-storage-web/package.json lib/object-storage-web/
COPY scripts/package.json scripts/
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install --frozen-lockfile --ignore-scripts
FROM deps AS build
COPY tsconfig.base.json* tsconfig.json* ./
COPY lib lib
COPY scripts scripts
COPY artifacts/api-server artifacts/api-server
RUN pnpm --filter @workspace/api-server run build
FROM base AS runtime
WORKDIR /app
ENV NODE_ENV=production
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/pnpm-workspace.yaml /app/pnpm-lock.yaml /app/package.json ./
COPY --from=build /app/lib ./lib
COPY --from=build /app/scripts ./scripts
COPY --from=build /app/artifacts/api-server/package.json ./artifacts/api-server/package.json
COPY --from=build /app/artifacts/api-server/dist ./artifacts/api-server/dist
COPY --from=build /app/artifacts/api-server/assets ./artifacts/api-server/assets
COPY --from=build /app/artifacts/api-server/node_modules ./artifacts/api-server/node_modules
COPY docker/migrate.sh /usr/local/bin/migrate.sh
RUN chmod +x /usr/local/bin/migrate.sh
RUN mkdir -p /app/storage && chown -R node:node /app/storage
USER node
ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["node", "--enable-source-maps", "/app/artifacts/api-server/dist/index.mjs"]
+27
View File
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -euo pipefail
echo "[migrate] waiting for postgres at $DATABASE_URL ..."
for i in {1..60}; do
if node -e "
import('pg').then(({ default: pg }) => {
const c = new pg.Client({ connectionString: process.env.DATABASE_URL });
c.connect().then(() => c.end()).then(() => process.exit(0)).catch(() => process.exit(1));
});
" 2>/dev/null; then
echo "[migrate] postgres is ready."
break
fi
sleep 1
done
echo "[migrate] pushing schema with drizzle-kit ..."
cd /app
pnpm --filter @workspace/db run push-force
echo "[migrate] seeding database ..."
pnpm --filter @workspace/scripts run seed || {
echo "[migrate] seed reported a non-zero exit (often safe if data already exists). Continuing."
}
echo "[migrate] done."
+46 -49
View File
@@ -1,56 +1,53 @@
# Tx OS web — serves the built React/Vite SPA and reverse-proxies the
# API + Socket.IO traffic to the api container on the private network.
upstream tx_api {
server api:8080;
server api:8080;
}
server {
listen 80;
server_name _;
listen 80;
server_name _;
client_max_body_size 50m;
# WebSocket / Socket.IO upgrade for /api/socket.io
location /api/socket.io/ {
proxy_pass http://tx_api;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
}
# Forward all /api requests to the Node API server
location /api/ {
proxy_pass http://tx_api;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
}
# Static SPA assets with hashed filenames — cache aggressively
location /assets/ {
root /usr/share/nginx/html;
expires 1y;
access_log off;
add_header Cache-Control "public, immutable";
try_files $uri =404;
}
# SPA fallback — every unknown path returns index.html
location / {
root /usr/share/nginx/html;
index index.html;
# Health endpoint for compose / load balancer probes.
location = /healthz {
access_log off;
return 200 "ok\n";
add_header Content-Type text/plain;
}
# Socket.IO upgrade — must come before the generic /api/ block so the
# WebSocket handshake gets the upgrade headers it needs.
location /api/socket.io/ {
proxy_pass http://tx_api;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 1h;
}
# All other API calls.
location /api/ {
proxy_pass http://tx_api;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 25m;
}
# SPA: serve hashed assets with long-cache; fall back to index.html.
location ~* \.(?:js|css|woff2?|png|jpg|jpeg|gif|svg|ico|webp|map)$ {
expires 30d;
add_header Cache-Control "public, immutable";
try_files $uri =404;
}
location / {
try_files $uri $uri/ /index.html;
add_header Cache-Control "no-cache";
}
try_files $uri $uri/ /index.html;
add_header Cache-Control "no-cache";
}
}
+33
View File
@@ -0,0 +1,33 @@
FROM node:24-bookworm-slim AS base
ENV PNPM_HOME=/pnpm
ENV PATH=$PNPM_HOME:$PATH
RUN corepack enable && corepack prepare pnpm@10.26.1 --activate
WORKDIR /app
FROM base AS deps
COPY pnpm-workspace.yaml pnpm-lock.yaml package.json ./
COPY artifacts/api-server/package.json artifacts/api-server/
COPY artifacts/tx-os/package.json artifacts/tx-os/
COPY lib/api-client-react/package.json lib/api-client-react/
COPY lib/api-spec/package.json lib/api-spec/
COPY lib/api-zod/package.json lib/api-zod/
COPY lib/db/package.json lib/db/
COPY lib/object-storage-web/package.json lib/object-storage-web/
COPY scripts/package.json scripts/
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install --frozen-lockfile --ignore-scripts
FROM deps AS build
COPY tsconfig.base.json* tsconfig.json* ./
COPY lib lib
COPY artifacts/tx-os artifacts/tx-os
ENV PORT=80
ENV BASE_PATH=/
RUN pnpm --filter @workspace/tx-os run build
FROM nginx:1.27-alpine AS runtime
RUN rm -rf /usr/share/nginx/html/* /etc/nginx/conf.d/default.conf
COPY --from=build /app/artifacts/tx-os/dist/public /usr/share/nginx/html
COPY docker/nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]