---
name: sailor-bar-site-deploy
description: "Build and deploy Sailor.bar Vite+React site from /app, fix TS errors, deploy dist/ to /var/www/sailor.bar, verify HTTP 200."
category: devops
version: 2.0
---

## When to use
When you need to build and deploy the Sailor.bar website from the GitHub repo. The site is a Vite + React + TypeScript + Tailwind (shadcn/ui) app located in `/app`. Use this when:
- The source code at `https://github.com/valldun1/Sailor-bar.git` has been updated
- You need to build the frontend and deploy static files to `/var/www/sailor.bar` on the Contabo VPS (157.173.122.51)
- DNS (sailor.bar) is already set up at GoDaddy

## Prerequisites
- Node.js >= 20.11.0, npm >= 10.8.2
- Git
- On the target server: nginx, systemctl access to reload

## Workflow

### Option A: Build in sandbox, deliver archive (no SSH available)
Use when you have clone + build tools but no direct SSH access to the Contabo server.

1. **Clone the repo** (using PAT if needed):
   ```bash
   git clone https://github.com/valldun1/Sailor-bar.git /tmp/sailor-build
   cd /tmp/sailor-build/app
   ```

2. **Install dependencies** (npm, not pnpm):
   ```bash
   npm install
   ```
   Note: may show `EBADENGINE` warning about npm version — harmless.

3. **Fix TypeScript errors before building**:
   Build command: `tsc -b && vite build`. Common errors and fixes:

   | Error | Fix |
   |-------|-----|
   | `'isHome' is declared but its value is never read (TS6133)` | Remove unused `const isHome = location.pathname === '/'` in `src/components/Layout.tsx` |
   | Other TS6133 unused vars | Remove the declaration or prefix with `_` |

   Use the `patch` tool to fix source files before building.

4. **Build**:
   ```bash
   npm run build
   ```
   Output in `dist/`:
   - `index.html` (~1 KB)
   - `assets/index-*.css` (~86 KB)
   - `assets/index-*.js` (~292 KB)
   - `images/` (article thumbs, avatars)

5. **Package and deliver**:
   ```bash
   cd /tmp/sailor-build
   mkdir -p /tmp/sailor-dist
   cp -r app/dist/* /tmp/sailor-dist/
   cp CNAME /tmp/sailor-dist/
   tar -czf sailor-bar-site.tar.gz -C /tmp sailor-dist/
   ```
   Send the archive via MEDIA: path. User copies to server and runs:
   ```bash
   # First clean old files on server
   cd /var/www/sailor.bar && find . -maxdepth 1 -not -name CNAME -not -name . -exec rm -rf {} +
   # Then extract new build
   tar -xzf sailor-bar-site.tar.gz -C /var/www/sailor.bar/ --strip-components=1
   chown -R www-data:www-data /var/www/sailor.bar/
   find /var/www/sailor.bar -type d -exec chmod 755 {} \;
   find /var/www/sailor.bar -type f -exec chmod 644 {} \;
   systemctl reload nginx
   ```

### Option B: Direct deploy on server (SSH or user terminal)
1. SSH into server or switch to user terminal
2. Clone/pull repo into work directory
3. Follow steps 2-4 from Option A
4. Deploy:
   ```bash
   cp -r /tmp/sailor-build/app/dist/* /var/www/sailor.bar/
   cp /tmp/sailor-build/CNAME /var/www/sailor.bar/
   chown -R www-data:www-data /var/www/sailor.bar/
   find /var/www/sailor.bar -type d -exec chmod 755 {} \;
   find /var/www/sailor.bar -type f -exec chmod 644 {} \;
   systemctl reload nginx
   ```

## What NOT to touch
- `CNAME` – changing it will break domain pointing
- `nginx` config outside of this skill – rely on reload only
- `.git` directory – preserve version control

## Verification
```bash
curl -s -o /dev/null -w "%{http_code}\n" https://sailor.bar
# Expected: 200

curl -s https://sailor.bar | grep -i "sailor\|маринист"
```

## Pitfalls
- **TS6133 errors**: The project uses `tsc -b` (strict checks). Unused variables will break the build. Always check for and fix these before building.
- **npm version warning**: Node.js 20 with npm 9 gives EBADENGINE warnings — ignore them, build succeeds.
- **No SSH**: The Hermes sandbox has no SSH client and cannot install packages (non-root). Use Option A (archive) instead.
- **CNAME required**: Always copy CNAME file to dist or the domain mapping breaks on the next nginx reload.
