Restore videoreg public guide site with static isolated deployment
Production container deploy / production (push) Failing after 2m34s

This commit is contained in:
huncode committed 2026-10-26 14:26:13 +03:00
1 parent 2ce58fcbc0
commit 53e4f06486
35 files changed
+599 -355

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail
: "${IMAGE:?Provide immutable registry image tag or digest}"
DEPLOY_HOST="${DEPLOY_HOST:-zz}"
REMOTE_RELEASE="/tmp/videoreg-static-deploy"
ssh -o BatchMode=yes "$DEPLOY_HOST" "mkdir -p '$REMOTE_RELEASE'"
scp -o BatchMode=yes deploy/stack.yml "$DEPLOY_HOST:$REMOTE_RELEASE/stack.yml"
# IMAGE is validated to avoid injecting shell commands in the remote environment.
[[ "$IMAGE" =~ ^[a-zA-Z0-9._/:@-]+$ ]] || exit 2
ssh -o BatchMode=yes "$DEPLOY_HOST" "cd '$REMOTE_RELEASE' && IMAGE='$IMAGE' DOMAIN=videoreg.ru STACK_NAME=videoreg TRAEFIK_NETWORK=traefik-public docker stack deploy --with-registry-auth -c stack.yml videoreg && docker stack services videoreg"
+10 -33
View File
@@ -1,37 +1,14 @@
# syntax=docker/dockerfile:1
FROM node:22-alpine AS deps
# Legacy dynamic application image; public production uses root Dockerfile (static).
FROM node:22-alpine AS build
WORKDIR /app
COPY .npmrc package.json package-lock.json ./
RUN npm install -g npm@11.6.4 \
&& npm ci --prefer-offline --no-audit --no-fund
FROM deps AS build
WORKDIR /app
ENV NEXT_TELEMETRY_DISABLED=1
COPY package.json package-lock.json .npmrc ./
RUN npm ci --no-audit --no-fund
COPY tsconfig.json vitest.config.ts ./
COPY web-front web-front
COPY ingestion ingestion
RUN npm run ci:quality
FROM node:22-alpine AS runtime
ENV NODE_ENV=production \
APP_ENV=production \
NEXT_TELEMETRY_DISABLED=1 \
VIDEOREG_DB_FILE=/data/videoreg.json \
PORT=3000
WORKDIR /app
RUN addgroup -S nodeapp && adduser -S nodeapp -G nodeapp && mkdir -p /data && chown nodeapp:nodeapp /data
COPY --from=build /app/web-front/.next/standalone ./
COPY --from=build /app/web-front/.next/static ./.next/static
COPY --from=build /app/web-front/public ./public
USER nodeapp
EXPOSE 3000
HEALTHCHECK --interval=10s --timeout=3s --start-period=20s --retries=3 \
CMD wget -qO- http://127.0.0.1:3000/health/ready >/dev/null || exit 1
CMD ["node", "server.js"]
RUN npm run build
FROM nginx:1.28-alpine
COPY deploy/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/web-front/out/ /usr/share/nginx/html/
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=3s CMD wget -qO- http://127.0.0.1:8080/health/ready >/dev/null || exit 1
+19
View File
@@ -0,0 +1,19 @@
server {
listen 8080;
server_name _;
root /usr/share/nginx/html;
charset utf-8;
server_tokens off;
absolute_redirect off;
add_header X-Content-Type-Options nosniff always;
add_header Referrer-Policy strict-origin-when-cross-origin always;
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self'; object-src 'none'; base-uri 'self'; frame-ancestors 'none'" always;
location = /auto.shtml { return 308 /guides/choose; }
location /api/ { return 404; }
location ~ /showcase/?$ { return 404; }
location /_next/static/ { expires 1y; add_header Cache-Control "public, immutable"; }
location /health/ { default_type application/json; try_files $uri =503; }
location / { try_files $uri $uri.html $uri/ =404; }
error_page 404 /404.html;
location = /404.html { internal; }
}
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env python3
"""Preview the public static release on an OS-assigned local port."""
from http.server import ThreadingHTTPServer, SimpleHTTPRequestHandler
from pathlib import Path
import json, os
ROOT=Path(__file__).resolve().parents[1]
OUT=ROOT/'web-front/out'
class Handler(SimpleHTTPRequestHandler):
def __init__(self,*args,**kwargs):super().__init__(*args,directory=str(OUT),**kwargs)
def do_GET(self):
path=self.path.split('?',1)[0]
if path=='/auto.shtml':
self.send_response(308);self.send_header('Location','/guides/choose');self.end_headers();return
if path.startswith('/api/') or path.rstrip('/').endswith('/showcase'):
self.send_error(404);return
target=OUT/path.lstrip('/')
if path.startswith('/health/') and target.is_file():
self.send_response(200);self.send_header('Content-Type','application/json');self.end_headers();self.wfile.write(target.read_bytes());return
if target.with_suffix('.html').is_file():self.path=path+'.html'
super().do_GET()
httpd=ThreadingHTTPServer(('127.0.0.1',0),Handler)
runtime=ROOT/'.local-run';runtime.mkdir(exist_ok=True)
state=dict(port=httpd.server_port,pid=os.getpid(),url=f'http://127.0.0.1:{httpd.server_port}')
(runtime/'server.json').write_text(json.dumps(state,indent=2)+'\n')
print(json.dumps(state),flush=True)
httpd.serve_forever()
+38
View File
@@ -0,0 +1,38 @@
services:
web:
image: ${IMAGE}
networks:
- proxy
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8080/ >/dev/null || exit 1"]
interval: 30s
timeout: 3s
retries: 3
start_period: 5s
deploy:
replicas: 1
update_config:
order: start-first
parallelism: 1
failure_action: rollback
monitor: 30s
rollback_config:
order: start-first
parallelism: 1
monitor: 30s
restart_policy:
condition: on-failure
labels:
- "traefik.enable=true"
- "traefik.docker.network=${TRAEFIK_NETWORK:-traefik-public}"
- "traefik.http.routers.${STACK_NAME}.rule=Host(`${DOMAIN}`) && PathPrefix(`/`)"
- "traefik.http.routers.${STACK_NAME}.priority=100"
- "traefik.http.routers.${STACK_NAME}.entrypoints=${TRAEFIK_ENTRYPOINTS:-websecure}"
- "traefik.http.routers.${STACK_NAME}.tls=${TRAEFIK_TLS:-true}"
- "traefik.http.routers.${STACK_NAME}.tls.certresolver=${TRAEFIK_CERTRESOLVER:-le}"
- "traefik.http.services.${STACK_NAME}.loadbalancer.server.port=8080"
networks:
proxy:
external: true
name: ${TRAEFIK_NETWORK:-traefik-public}