r2
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
services:
|
||||
app:
|
||||
build:
|
||||
context: ../app
|
||||
dockerfile: Dockerfile
|
||||
image: vitfit:latest
|
||||
container_name: vitfit-app
|
||||
restart: unless-stopped
|
||||
|
||||
# Load .env from the app directory; values below override specific keys
|
||||
env_file:
|
||||
- ../app/.env
|
||||
environment:
|
||||
NODE_ENV: production
|
||||
DB_PATH: /data/vitfit.sqlite
|
||||
UPLOADS_DIR: /data/uploads
|
||||
UPLOAD_TEMP_DIR: /data/tmp
|
||||
|
||||
volumes:
|
||||
# Bind-mount host directory so DB + uploads survive container rebuilds.
|
||||
# Create on first deploy: sudo mkdir -p /var/vitfit/data && sudo chown 1000:1000 /var/vitfit/data
|
||||
- /var/vitfit/data:/data
|
||||
|
||||
# Only expose to localhost — nginx proxies inbound HTTPS traffic
|
||||
ports:
|
||||
- "127.0.0.1:3000:3000"
|
||||
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-qO-", "http://localhost:3000/health"]
|
||||
interval: 30s
|
||||
timeout: 5s
|
||||
retries: 3
|
||||
start_period: 20s
|
||||
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: "20m"
|
||||
max-file: "5"
|
||||
@@ -0,0 +1,4 @@
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: vitfit
|
||||
@@ -0,0 +1,18 @@
|
||||
# Persistent storage for SQLite database + uploaded videos.
|
||||
# SQLite requires ReadWriteOnce — this limits the Deployment to a single replica.
|
||||
# If you need horizontal scaling in the future, migrate to PostgreSQL and use
|
||||
# a separate object store (S3-compatible) for uploads.
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: vitfit-data
|
||||
namespace: vitfit
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 20Gi
|
||||
# Set storageClassName to match your cluster's provisioner.
|
||||
# Leave blank to use the default StorageClass.
|
||||
# storageClassName: standard
|
||||
@@ -0,0 +1,19 @@
|
||||
# Non-sensitive environment variables.
|
||||
# Sensitive values (JWT_SECRET, etc.) go in 03-secret.yaml.
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: vitfit-config
|
||||
namespace: vitfit
|
||||
data:
|
||||
NODE_ENV: "production"
|
||||
PORT: "3000"
|
||||
DB_PATH: "/data/vitfit.sqlite"
|
||||
UPLOADS_DIR: "/data/uploads"
|
||||
UPLOAD_TEMP_DIR: "/data/tmp"
|
||||
LOG_LEVEL: "info"
|
||||
# Set to your domain: https://your.domain.com
|
||||
CORS_ORIGIN: "https://your.domain.com"
|
||||
# Storage warning threshold in bytes (default 10 GB)
|
||||
STORAGE_WARN_BYTES: "10737418240"
|
||||
UPLOAD_MAX_BYTES: "2147483648"
|
||||
@@ -0,0 +1,18 @@
|
||||
# TEMPLATE — do not commit real values.
|
||||
# Generate and apply this manually:
|
||||
#
|
||||
# kubectl create secret generic vitfit-secrets \
|
||||
# --namespace=vitfit \
|
||||
# --from-literal=JWT_SECRET="$(openssl rand -hex 64)" \
|
||||
# --dry-run=client -o yaml | kubectl apply -f -
|
||||
#
|
||||
# Or fill in base64-encoded values below (echo -n 'value' | base64):
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: vitfit-secrets
|
||||
namespace: vitfit
|
||||
type: Opaque
|
||||
data:
|
||||
# base64-encoded values — replace before applying
|
||||
JWT_SECRET: REPLACE_WITH_BASE64_ENCODED_SECRET
|
||||
@@ -0,0 +1,76 @@
|
||||
# Single replica required — SQLite (ReadWriteOnce PVC) cannot be shared across pods.
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: vitfit
|
||||
namespace: vitfit
|
||||
labels:
|
||||
app: vitfit
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: vitfit
|
||||
# Recreate ensures the old pod releases the PVC before the new one starts.
|
||||
strategy:
|
||||
type: Recreate
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: vitfit
|
||||
spec:
|
||||
securityContext:
|
||||
runAsNonRoot: true
|
||||
runAsUser: 1000
|
||||
runAsGroup: 1000
|
||||
fsGroup: 1000
|
||||
|
||||
containers:
|
||||
- name: app
|
||||
image: vitfit:latest # replace with your registry path
|
||||
imagePullPolicy: Always
|
||||
|
||||
ports:
|
||||
- containerPort: 3000
|
||||
name: http
|
||||
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: vitfit-config
|
||||
- secretRef:
|
||||
name: vitfit-secrets
|
||||
|
||||
volumeMounts:
|
||||
- name: data
|
||||
mountPath: /data
|
||||
|
||||
resources:
|
||||
requests:
|
||||
cpu: "250m"
|
||||
memory: "256Mi"
|
||||
limits:
|
||||
cpu: "1000m"
|
||||
memory: "512Mi"
|
||||
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: 3000
|
||||
initialDelaySeconds: 20
|
||||
periodSeconds: 30
|
||||
timeoutSeconds: 5
|
||||
failureThreshold: 3
|
||||
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: 3000
|
||||
initialDelaySeconds: 10
|
||||
periodSeconds: 10
|
||||
timeoutSeconds: 3
|
||||
failureThreshold: 3
|
||||
|
||||
volumes:
|
||||
- name: data
|
||||
persistentVolumeClaim:
|
||||
claimName: vitfit-data
|
||||
@@ -0,0 +1,15 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: vitfit
|
||||
namespace: vitfit
|
||||
labels:
|
||||
app: vitfit
|
||||
spec:
|
||||
type: ClusterIP
|
||||
selector:
|
||||
app: vitfit
|
||||
ports:
|
||||
- name: http
|
||||
port: 80
|
||||
targetPort: 3000
|
||||
@@ -0,0 +1,42 @@
|
||||
# cert-manager ClusterIssuers — requires cert-manager to be installed in the cluster.
|
||||
# Install cert-manager: https://cert-manager.io/docs/installation/
|
||||
#
|
||||
# Apply staging first to verify ACME account + DNS, then switch Ingress to prod.
|
||||
#
|
||||
# Usage:
|
||||
# kubectl apply -f 06-cluster-issuer.yaml
|
||||
# # verify: kubectl describe clusterissuer letsencrypt-staging
|
||||
|
||||
---
|
||||
# Staging — safe for testing (not trusted by browsers, no rate limits)
|
||||
apiVersion: cert-manager.io/v1
|
||||
kind: ClusterIssuer
|
||||
metadata:
|
||||
name: letsencrypt-staging
|
||||
spec:
|
||||
acme:
|
||||
server: https://acme-staging-v02.api.letsencrypt.org/directory
|
||||
email: admin@your.domain.com # replace with your email
|
||||
privateKeySecretRef:
|
||||
name: letsencrypt-staging-key
|
||||
solvers:
|
||||
- http01:
|
||||
ingress:
|
||||
ingressClassName: nginx
|
||||
|
||||
---
|
||||
# Production — real trusted certs, rate-limited (5 failures/hour per domain)
|
||||
apiVersion: cert-manager.io/v1
|
||||
kind: ClusterIssuer
|
||||
metadata:
|
||||
name: letsencrypt-prod
|
||||
spec:
|
||||
acme:
|
||||
server: https://acme-v02.api.letsencrypt.org/directory
|
||||
email: admin@your.domain.com # replace with your email
|
||||
privateKeySecretRef:
|
||||
name: letsencrypt-prod-key
|
||||
solvers:
|
||||
- http01:
|
||||
ingress:
|
||||
ingressClassName: nginx
|
||||
@@ -0,0 +1,54 @@
|
||||
# Nginx Ingress with TLS.
|
||||
#
|
||||
# ── Option A: Let's Encrypt (cert-manager) ────────────────────────────────────
|
||||
# Requires cert-manager + ClusterIssuer from 06-cluster-issuer.yaml.
|
||||
# Switch between staging and prod by changing the annotation value.
|
||||
# cert-manager will auto-create the Secret named in tls.secretName.
|
||||
#
|
||||
# ── Option B: Custom / uploaded certificate ───────────────────────────────────
|
||||
# 1. Remove (or comment out) the cert-manager annotation.
|
||||
# 2. Pre-create the TLS Secret:
|
||||
# kubectl create secret tls vitfit-tls \
|
||||
# --namespace=vitfit \
|
||||
# --cert=/path/to/your.crt \
|
||||
# --key=/path/to/your.key
|
||||
# 3. The tls.secretName below stays the same — no other changes needed.
|
||||
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: vitfit
|
||||
namespace: vitfit
|
||||
annotations:
|
||||
# ── [LE] cert-manager — comment out for custom cert (Option B)
|
||||
cert-manager.io/cluster-issuer: "letsencrypt-prod"
|
||||
|
||||
# WebSocket support (socket.io)
|
||||
nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
|
||||
nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"
|
||||
nginx.ingress.kubernetes.io/proxy-buffering: "off"
|
||||
|
||||
# Video upload size — match UPLOAD_MAX_BYTES
|
||||
nginx.ingress.kubernetes.io/proxy-body-size: "2100m"
|
||||
|
||||
# Force HTTPS
|
||||
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
|
||||
nginx.ingress.kubernetes.io/ssl-redirect: "true"
|
||||
|
||||
spec:
|
||||
ingressClassName: nginx
|
||||
tls:
|
||||
- hosts:
|
||||
- your.domain.com # replace with your domain
|
||||
secretName: vitfit-tls # cert-manager creates this (LE) or you create it (custom)
|
||||
rules:
|
||||
- host: your.domain.com # replace with your domain
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: vitfit
|
||||
port:
|
||||
name: http
|
||||
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
# Renew Let's Encrypt certificates and reload nginx only when a cert was renewed.
|
||||
# Run via cron or systemd timer twice daily (certbot skips certs with >30 days left).
|
||||
#
|
||||
# Recommended cron entry (as root):
|
||||
# 0 3,15 * * * /path/to/vitfit/deploy/nginx/certbot-renew.sh >> /var/log/certbot-renew.log 2>&1
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
certbot renew --quiet --deploy-hook "nginx -s reload"
|
||||
@@ -0,0 +1,8 @@
|
||||
# Add this block to the http{} section of your main nginx.conf
|
||||
# (typically /etc/nginx/nginx.conf), NOT inside vitfit.conf.
|
||||
# It enables WebSocket upgrade pass-through for socket.io.
|
||||
|
||||
map $http_upgrade $connection_upgrade {
|
||||
default upgrade;
|
||||
'' close;
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
# VitFit — Nginx reverse proxy
|
||||
# Replace 'your.domain.com' with your actual domain before deploying.
|
||||
#
|
||||
# TLS mode — only one block should be active at a time:
|
||||
# Option A (Let's Encrypt via certbot) → lines marked [LE] — ACTIVE by default
|
||||
# Option B (custom / uploaded cert) → lines marked [CUSTOM] — commented out
|
||||
#
|
||||
# To switch to Option B:
|
||||
# 1. Comment out all [LE] lines
|
||||
# 2. Uncomment all [CUSTOM] lines
|
||||
# 3. Copy your cert to /etc/nginx/ssl/vitfit.crt and key to /etc/nginx/ssl/vitfit.key
|
||||
# 4. nginx -t && nginx -s reload
|
||||
|
||||
# ── HTTP: ACME challenge pass-through + redirect ───────────────────────────────
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name your.domain.com;
|
||||
|
||||
# [LE] certbot HTTP-01 challenge files
|
||||
location /.well-known/acme-challenge/ {
|
||||
root /var/www/certbot;
|
||||
}
|
||||
|
||||
location / {
|
||||
return 301 https://$host$request_uri;
|
||||
}
|
||||
}
|
||||
|
||||
# ── HTTPS ──────────────────────────────────────────────────────────────────────
|
||||
server {
|
||||
listen 443 ssl;
|
||||
listen [::]:443 ssl;
|
||||
http2 on;
|
||||
server_name your.domain.com;
|
||||
|
||||
# ── [LE] Let's Encrypt certificate (managed by certbot) ───────────────────
|
||||
ssl_certificate /etc/letsencrypt/live/your.domain.com/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/your.domain.com/privkey.pem;
|
||||
include /etc/letsencrypt/options-ssl-nginx.conf;
|
||||
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
|
||||
|
||||
# ── [CUSTOM] Uploaded / self-signed certificate ───────────────────────────
|
||||
# ssl_certificate /etc/nginx/ssl/vitfit.crt;
|
||||
# ssl_certificate_key /etc/nginx/ssl/vitfit.key;
|
||||
# ssl_protocols TLSv1.2 TLSv1.3;
|
||||
# ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384;
|
||||
# ssl_prefer_server_ciphers off;
|
||||
# ssl_session_cache shared:SSL:10m;
|
||||
# ssl_session_timeout 1d;
|
||||
|
||||
# ── Security headers ──────────────────────────────────────────────────────
|
||||
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
|
||||
add_header X-Frame-Options SAMEORIGIN always;
|
||||
add_header X-Content-Type-Options nosniff always;
|
||||
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
||||
|
||||
# ── Video upload size — match UPLOAD_MAX_BYTES in .env ───────────────────
|
||||
client_max_body_size 2100m;
|
||||
|
||||
# ── Proxy to Node app ─────────────────────────────────────────────────────
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
proxy_http_version 1.1;
|
||||
|
||||
# WebSocket upgrade (required for socket.io)
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection $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;
|
||||
|
||||
# Long timeouts keep socket.io connections alive through the proxy
|
||||
proxy_read_timeout 3600s;
|
||||
proxy_send_timeout 3600s;
|
||||
|
||||
# Disable buffering for streaming video responses (Range requests)
|
||||
proxy_buffering off;
|
||||
}
|
||||
}
|
||||
|
||||
# ── WebSocket connection upgrade map ──────────────────────────────────────────
|
||||
# Place this in the http{} block of your nginx.conf (not inside server{}).
|
||||
# If you're using a separate conf.d include, add a map-only file instead.
|
||||
#
|
||||
# map $http_upgrade $connection_upgrade {
|
||||
# default upgrade;
|
||||
# '' close;
|
||||
# }
|
||||
Reference in New Issue
Block a user