deploy(backend): add prod Dockerfiles, compose stack, nginx configs, deploy scripts
Multi-stage Dockerfiles for accounts-service/configs-service/gateway, a docker-compose.prod.yml wiring fresh Postgres+MinIO+the three services on a private network, nginx site templates for visual.loki-code.dev (static SPA + /api proxy) and bekend.loki-code.dev (full gateway proxy for the mod), and idempotent setup.sh/deploy.sh scripts for the VDS. Claude-Session: https://claude.ai/code/session_01F1M1Jic1wTSn4igUENynmZ
This commit is contained in:
parent
484adaaf52
commit
2735a1c161
9 changed files with 263 additions and 0 deletions
29
backend/deploy/deploy.sh
Executable file
29
backend/deploy/deploy.sh
Executable file
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/bash
|
||||
# Idempotent redeploy for LoVisual. Run as: /opt/lovisual/deploy.sh
|
||||
set -euo pipefail
|
||||
|
||||
REPO_DIR=/opt/lovisual
|
||||
FRONTEND_ROOT=/var/www/visual.loki-code.dev/html
|
||||
|
||||
cd "$REPO_DIR"
|
||||
git pull --ff-only
|
||||
|
||||
echo "==> Building & (re)starting backend services"
|
||||
cd "$REPO_DIR/backend"
|
||||
docker compose -f docker-compose.prod.yml up -d --build
|
||||
|
||||
echo "==> Building frontend"
|
||||
cd "$REPO_DIR/frontend"
|
||||
npm ci
|
||||
npm run build
|
||||
|
||||
echo "==> Syncing frontend build to $FRONTEND_ROOT"
|
||||
mkdir -p "$FRONTEND_ROOT"
|
||||
rsync -a --delete dist/ "$FRONTEND_ROOT/"
|
||||
|
||||
echo "==> Reloading nginx"
|
||||
nginx -t
|
||||
systemctl reload nginx
|
||||
|
||||
echo "==> Done"
|
||||
docker compose -f "$REPO_DIR/backend/docker-compose.prod.yml" ps
|
||||
14
backend/deploy/nginx-bekend.loki-code.dev.conf
Normal file
14
backend/deploy/nginx-bekend.loki-code.dev.conf
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
server {
|
||||
server_name bekend.loki-code.dev;
|
||||
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:8080;
|
||||
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;
|
||||
}
|
||||
|
||||
listen 80;
|
||||
}
|
||||
20
backend/deploy/nginx-visual.loki-code.dev.conf
Normal file
20
backend/deploy/nginx-visual.loki-code.dev.conf
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
server {
|
||||
server_name visual.loki-code.dev;
|
||||
root /var/www/visual.loki-code.dev/html;
|
||||
index index.html;
|
||||
|
||||
location /api/ {
|
||||
proxy_pass http://127.0.0.1:8080/;
|
||||
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;
|
||||
}
|
||||
|
||||
location / {
|
||||
try_files $uri /index.html;
|
||||
}
|
||||
|
||||
listen 80;
|
||||
}
|
||||
6
backend/deploy/pg-init/01-create-databases.sh
Executable file
6
backend/deploy/pg-init/01-create-databases.sh
Executable file
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "postgres" <<-EOSQL
|
||||
SELECT 'CREATE DATABASE accounts_db OWNER lovisual' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'accounts_db')\gexec
|
||||
SELECT 'CREATE DATABASE configs_db OWNER lovisual' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'configs_db')\gexec
|
||||
EOSQL
|
||||
22
backend/deploy/setup.sh
Executable file
22
backend/deploy/setup.sh
Executable file
|
|
@ -0,0 +1,22 @@
|
|||
#!/bin/bash
|
||||
# One-time first-install setup for LoVisual on this VDS. Safe to re-run.
|
||||
# Assumes: repo already cloned to /opt/lovisual, backend/.env already created (chmod 600).
|
||||
set -euo pipefail
|
||||
|
||||
REPO_DIR=/opt/lovisual
|
||||
|
||||
echo "==> nginx site configs"
|
||||
cp "$REPO_DIR/backend/deploy/nginx-visual.loki-code.dev.conf" /etc/nginx/sites-available/visual.loki-code.dev
|
||||
cp "$REPO_DIR/backend/deploy/nginx-bekend.loki-code.dev.conf" /etc/nginx/sites-available/bekend.loki-code.dev
|
||||
ln -sf /etc/nginx/sites-available/visual.loki-code.dev /etc/nginx/sites-enabled/visual.loki-code.dev
|
||||
ln -sf /etc/nginx/sites-available/bekend.loki-code.dev /etc/nginx/sites-enabled/bekend.loki-code.dev
|
||||
mkdir -p /var/www/visual.loki-code.dev/html
|
||||
nginx -t
|
||||
systemctl reload nginx
|
||||
|
||||
echo "==> certbot"
|
||||
certbot --nginx -d visual.loki-code.dev --non-interactive --agree-tos -m mauhhhh7@gmail.com --redirect || true
|
||||
certbot --nginx -d bekend.loki-code.dev --non-interactive --agree-tos -m mauhhhh7@gmail.com --redirect || true
|
||||
|
||||
echo "==> First deploy"
|
||||
"$REPO_DIR/backend/deploy/deploy.sh"
|
||||
Loading…
Add table
Add a link
Reference in a new issue