This commit is contained in:
Meghdad committed 2026-07-14 12:51:36 +03:30
commit f035fcef4f
134 files changed
+18678

No files matched your search

+77
View File
@@ -0,0 +1,77 @@
FROM node:24-bookworm-slim AS build
ENV PNPM_HOME=/pnpm
ENV PATH=$PNPM_HOME:$PATH
WORKDIR /workspace
RUN corepack enable
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml tsconfig.base.json ./
COPY apps ./apps
COPY packages ./packages
RUN corepack pnpm install --frozen-lockfile
RUN corepack pnpm build
FROM node:24-bookworm-slim AS ffmpeg-build
ARG FFMPEG_VERSION=8.1.2
ARG FFMPEG_SHA256=464beb5e7bf0c311e68b45ae2f04e9cc2af88851abb4082231742a74d97b524c
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential ca-certificates curl libass-dev libfontconfig1-dev \
libfreetype6-dev libfribidi-dev libharfbuzz-dev libssl-dev libx264-dev \
nasm pkg-config xz-utils yasm zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /tmp/ffmpeg
RUN curl --fail --location --silent --show-error \
"https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.xz" \
--output ffmpeg.tar.xz \
&& echo "${FFMPEG_SHA256} ffmpeg.tar.xz" | sha256sum --check --strict \
&& tar --extract --file ffmpeg.tar.xz --strip-components=1 \
&& ./configure \
--prefix=/opt/ffmpeg \
--disable-debug \
--disable-doc \
--disable-ffplay \
--disable-static \
--enable-shared \
--enable-gpl \
--enable-version3 \
--enable-libass \
--enable-libfontconfig \
--enable-libfreetype \
--enable-libx264 \
--enable-openssl \
&& make -j"$(nproc)" \
&& make install
FROM node:24-bookworm-slim AS api
ENV NODE_ENV=production
WORKDIR /app
COPY --from=build /workspace /app
USER node
CMD ["node", "apps/api/dist/server.js"]
FROM node:24-bookworm-slim AS worker
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates libass9 libfontconfig1 libfreetype6 libfribidi0 \
libharfbuzz0b libssl3 libx264-164 zlib1g \
&& rm -rf /var/lib/apt/lists/*
COPY --from=ffmpeg-build /opt/ffmpeg /opt/ffmpeg
ENV NODE_ENV=production
ENV PATH=/opt/ffmpeg/bin:$PATH
ENV LD_LIBRARY_PATH=/opt/ffmpeg/lib
WORKDIR /app
COPY --from=build /workspace /app
USER node
CMD ["node", "apps/worker/dist/index.js", "work"]
FROM nginx:1.28-alpine AS gateway
RUN apk add --no-cache ca-certificates \
&& addgroup -g 1000 easy-stream \
&& adduser -D -H -u 1000 -G easy-stream easy-stream \
&& sed -i 's/^user[[:space:]][[:space:]]*nginx;/user easy-stream;/' /etc/nginx/nginx.conf \
&& chown -R easy-stream:easy-stream /var/cache/nginx
COPY infra/nginx/default.conf.template /etc/nginx/templates/default.conf.template
COPY infra/nginx/security-headers.conf /etc/nginx/security-headers.conf
COPY --from=build /workspace/apps/web/dist /usr/share/nginx/html
+118
View File
@@ -0,0 +1,118 @@
map $uri $media_cache_control {
default "no-store";
~*\.m3u8$ "private, no-cache, no-store, must-revalidate";
# Safe origin default: browsers may retain immutable generation assets, but a
# shared CDN must not cache them until it enforces playback authorization at
# the edge before cache lookup.
~*\.(m4s|mp4|vtt|ass|ttf|otf)$ "private, max-age=31536000, immutable";
}
upstream easy_stream_api {
server api:3000;
keepalive 64;
}
server {
listen 8080;
server_name _;
server_tokens off;
root /usr/share/nginx/html;
include /etc/nginx/security-headers.conf;
# Cache bookkeeping is mounted beside public generations but is never media.
location ~ (^|/)\. {
deny all;
}
location /api/ {
proxy_http_version 1.1;
proxy_set_header Host $host;
# Never trust a client-supplied forwarding chain. Configure real_ip_from
# for the selected CDN at deployment time if end-user IPs are required.
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://easy_stream_api;
add_header Cache-Control "no-store" always;
include /etc/nginx/security-headers.conf;
}
location = /_media_auth {
internal;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Media-Auth-Secret "${MEDIA_AUTH_SHARED_SECRET}";
proxy_pass http://easy_stream_api/internal/media-auth;
}
# Offline compatibility encodes are durable and live on a separate disk.
# Keep the more-specific prefix ahead of the bounded JIT cache route.
location /media/derived/ {
auth_request /_media_auth;
alias /srv/easy-stream/derived/;
disable_symlinks on;
types {
application/vnd.apple.mpegurl m3u8;
video/iso.segment m4s;
video/mp4 mp4;
text/vtt vtt;
text/x-ssa ass;
font/ttf ttf;
font/otf otf;
}
add_header Cache-Control $media_cache_control always;
include /etc/nginx/security-headers.conf;
}
location /media/ {
auth_request /_media_auth;
alias /srv/easy-stream/cache/;
disable_symlinks on;
types {
application/vnd.apple.mpegurl m3u8;
video/iso.segment m4s;
video/mp4 mp4;
text/vtt vtt;
text/x-ssa ass;
font/ttf ttf;
font/otf otf;
}
add_header Cache-Control $media_cache_control always;
include /etc/nginx/security-headers.conf;
}
# TMDB artwork stays same-origin for CSP/COEP and can be cached by the outer CDN.
location /images/tmdb/ {
limit_except GET HEAD { deny all; }
rewrite ^/images/tmdb/(w500|w1280)(/.*)$ /t/p/$1$2 break;
proxy_ssl_server_name on;
proxy_ssl_verify on;
proxy_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
proxy_ssl_verify_depth 3;
proxy_set_header Host image.tmdb.org;
proxy_hide_header Set-Cookie;
proxy_hide_header Cache-Control;
proxy_pass https://image.tmdb.org;
add_header Cache-Control "public, max-age=86400, stale-while-revalidate=604800" always;
include /etc/nginx/security-headers.conf;
}
location /healthz {
access_log off;
return 200 "ok\n";
}
location /assets/ {
try_files $uri =404;
add_header Cache-Control "public, max-age=31536000, immutable" always;
include /etc/nginx/security-headers.conf;
}
location / {
try_files $uri $uri/ /index.html;
add_header Cache-Control "no-cache";
include /etc/nginx/security-headers.conf;
}
}
+8
View File
@@ -0,0 +1,8 @@
add_header X-Content-Type-Options nosniff always;
add_header Referrer-Policy no-referrer always;
add_header X-Frame-Options DENY always;
add_header Cross-Origin-Opener-Policy same-origin always;
add_header Cross-Origin-Embedder-Policy require-corp always;
add_header Cross-Origin-Resource-Policy same-origin always;
add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; media-src 'self' blob:; connect-src 'self'; worker-src 'self' blob:; font-src 'self' data:; frame-ancestors 'none'; base-uri 'none'; form-action 'self'" always;