fix:deploy
This commit is contained in:
@@ -17,8 +17,7 @@ const sessionSecret = process.env.SESSION_SECRET;
|
|||||||
if (!sessionSecret) throw new Error("SESSION_SECRET env var is required");
|
if (!sessionSecret) throw new Error("SESSION_SECRET env var is required");
|
||||||
|
|
||||||
const app = Fastify({
|
const app = Fastify({
|
||||||
// In prod: warn-level only to reduce noise; in dev: full pretty logging
|
logger: isProd ? { level: "info" } : true,
|
||||||
logger: isProd ? { level: "warn" } : true,
|
|
||||||
// Trust the nginx reverse proxy so secure cookies and req.ip work correctly
|
// Trust the nginx reverse proxy so secure cookies and req.ip work correctly
|
||||||
trustProxy: isProd,
|
trustProxy: isProd,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -80,7 +80,8 @@ export const authRouter: FastifyPluginAsync = async (fastify) => {
|
|||||||
|
|
||||||
req.session.user = user;
|
req.session.user = user;
|
||||||
const base = process.env.FRONTEND_APP_URL ?? "http://localhost:5173";
|
const base = process.env.FRONTEND_APP_URL ?? "http://localhost:5173";
|
||||||
reply.redirect(`${base}?login=1`);
|
const baseUrl = base.endsWith("/") ? base : `${base}/`;
|
||||||
|
reply.redirect(`${baseUrl}?login=1`);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
55
deploy.sh
55
deploy.sh
@@ -1,19 +1,54 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
echo "Pulling latest code..."
|
# Usage: ./deploy.sh [options] [target]
|
||||||
git pull
|
# Target: all (default), backend, frontend
|
||||||
|
# Options: --no-pull
|
||||||
|
|
||||||
echo "Building frontend..."
|
TARGET="all"
|
||||||
docker compose --profile build build frontend-builder
|
NO_PULL=false
|
||||||
docker compose --profile build run --rm frontend-builder
|
|
||||||
|
|
||||||
echo "Copying frontend dist to nginx..."
|
# Parse arguments
|
||||||
sudo mkdir -p /var/www/support-ticket-demo
|
for arg in "$@"; do
|
||||||
sudo cp -r frontend/dist/. /var/www/support-ticket-demo/
|
case $arg in
|
||||||
|
--no-pull)
|
||||||
|
NO_PULL=true
|
||||||
|
;;
|
||||||
|
backend|frontend|all)
|
||||||
|
TARGET=$arg
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown argument: $arg"
|
||||||
|
echo "Usage: $0 [--no-pull] [all|backend|frontend]"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
echo "Building and restarting backend..."
|
# Git pull
|
||||||
docker compose up -d --build --remove-orphans backend
|
if [ "$NO_PULL" = false ]; then
|
||||||
|
echo "Pulling latest code..."
|
||||||
|
git pull
|
||||||
|
else
|
||||||
|
echo "Skipping git pull..."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Deploy frontend
|
||||||
|
if [ "$TARGET" = "all" ] || [ "$TARGET" = "frontend" ]; then
|
||||||
|
echo "Building frontend..."
|
||||||
|
docker compose --profile build build frontend-builder
|
||||||
|
docker compose --profile build run --rm frontend-builder
|
||||||
|
|
||||||
|
echo "Copying frontend dist to nginx..."
|
||||||
|
sudo mkdir -p /var/www/support-ticket-demo
|
||||||
|
sudo cp -r frontend/dist/. /var/www/support-ticket-demo/
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Deploy backend
|
||||||
|
if [ "$TARGET" = "all" ] || [ "$TARGET" = "backend" ]; then
|
||||||
|
echo "Building and restarting backend..."
|
||||||
|
docker compose up -d --build --remove-orphans backend
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Cleaning up old images..."
|
echo "Cleaning up old images..."
|
||||||
docker image prune -f
|
docker image prune -f
|
||||||
|
|||||||
Reference in New Issue
Block a user