Add Docker Compose deployment config

Multi-stage Dockerfile: node:22-alpine builder + nginx:alpine server.
nginx.conf sets COOP/COEP headers (required for SharedArrayBuffer/audio workers),
SPA fallback, and aggressive caching for content-hashed assets.
API credentials and BASE_URL passed as build args.
This commit is contained in:
Tianrong Zhang 2026-06-11 22:29:33 -04:00
parent 2879188020
commit 6968a7c337
3 changed files with 72 additions and 0 deletions

28
Dockerfile Normal file
View File

@ -0,0 +1,28 @@
FROM node:22-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
ARG TELEGRAM_API_ID
ARG TELEGRAM_API_HASH
ARG BASE_URL=/
ENV TELEGRAM_API_ID=$TELEGRAM_API_ID
ENV TELEGRAM_API_HASH=$TELEGRAM_API_HASH
ENV BASE_URL=$BASE_URL
ENV NODE_ENV=production
RUN npm run build:production
# ---
FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80

11
docker-compose.yml Normal file
View File

@ -0,0 +1,11 @@
services:
telegram-tt:
build:
context: .
args:
TELEGRAM_API_ID: ${TELEGRAM_API_ID}
TELEGRAM_API_HASH: ${TELEGRAM_API_HASH}
BASE_URL: ${BASE_URL:-/}
restart: unless-stopped
ports:
- "${PORT:-8080}:80"

33
nginx.conf Normal file
View File

@ -0,0 +1,33 @@
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
# WASM needs correct MIME type
types {
application/wasm wasm;
}
# SharedArrayBuffer requires these headers (used by audio/video workers)
add_header Cross-Origin-Opener-Policy "same-origin";
add_header Cross-Origin-Embedder-Policy "require-corp";
# SPA fallback
location / {
try_files $uri $uri/ /index.html;
}
# Cache static assets aggressively (content-hashed filenames)
location ~* \.(js|css|wasm|woff2|woff|ttf|png|jpg|webp|svg|ico)$ {
expires 1y;
add_header Cache-Control "public, immutable";
add_header Cross-Origin-Opener-Policy "same-origin";
add_header Cross-Origin-Embedder-Policy "require-corp";
}
gzip on;
gzip_types text/plain text/css application/javascript application/json application/wasm;
gzip_min_length 1024;
}