72 lines
2.1 KiB
Bash
72 lines
2.1 KiB
Bash
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
APP_DIR="${APP_DIR:-/opt/nomadweb}"
|
|
DOMAIN="${DOMAIN:-nomadweb.nomadro.com}"
|
|
GIT_REPO="${GIT_REPO:-https://gitea.dsx2020.com/eric/nomadweb.git}"
|
|
BRANCH="${BRANCH:-main}"
|
|
|
|
echo "==> NomadFlow production deploy"
|
|
echo " Dir: $APP_DIR"
|
|
echo " Domain: $DOMAIN"
|
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
if ! command -v docker &>/dev/null; then
|
|
echo "==> Installing Docker..."
|
|
curl -fsSL https://get.docker.com | sh
|
|
systemctl enable docker
|
|
systemctl start docker
|
|
fi
|
|
|
|
if ! command -v nginx &>/dev/null; then
|
|
echo "==> Installing Nginx..."
|
|
apt-get update -qq
|
|
apt-get install -y -qq nginx git curl
|
|
systemctl enable nginx
|
|
fi
|
|
|
|
if [ ! -d "$APP_DIR/.git" ]; then
|
|
echo "==> Cloning repository..."
|
|
mkdir -p "$(dirname "$APP_DIR")"
|
|
git clone "$GIT_REPO" "$APP_DIR"
|
|
else
|
|
echo "==> Pulling latest..."
|
|
cd "$APP_DIR"
|
|
git fetch origin
|
|
git reset --hard "origin/$BRANCH"
|
|
fi
|
|
|
|
cd "$APP_DIR"
|
|
|
|
export NEXT_PUBLIC_API_URL="https://${DOMAIN}/api/v1"
|
|
export CORS_ORIGINS="https://${DOMAIN},http://${DOMAIN}"
|
|
|
|
echo "==> Building and starting containers..."
|
|
docker compose -f docker-compose.prod.yml down 2>/dev/null || true
|
|
docker compose -f docker-compose.prod.yml build --no-cache
|
|
docker compose -f docker-compose.prod.yml up -d
|
|
|
|
echo "==> Configuring Nginx..."
|
|
cp deploy/nginx/nomadweb.conf "/etc/nginx/sites-available/${DOMAIN}"
|
|
ln -sf "/etc/nginx/sites-available/${DOMAIN}" "/etc/nginx/sites-enabled/${DOMAIN}"
|
|
rm -f /etc/nginx/sites-enabled/default 2>/dev/null || true
|
|
nginx -t
|
|
systemctl reload nginx
|
|
|
|
if command -v certbot &>/dev/null; then
|
|
echo "==> Renewing SSL certificate..."
|
|
certbot --nginx -d "$DOMAIN" --non-interactive --agree-tos --register-unsafely-without-email --redirect 2>/dev/null || \
|
|
certbot --nginx -d "$DOMAIN" --non-interactive --agree-tos -m "admin@${DOMAIN}" --redirect || true
|
|
fi
|
|
|
|
echo "==> Health check..."
|
|
sleep 5
|
|
curl -sf "http://127.0.0.1:8020/api/v1/health" && echo " API OK"
|
|
curl -sf -o /dev/null "http://127.0.0.1:3020" && echo " Frontend OK"
|
|
|
|
echo ""
|
|
echo "Deploy complete!"
|
|
echo " Site: https://${DOMAIN}"
|
|
echo " API: https://${DOMAIN}/api/v1/health"
|