# Deploying With SSH and `rsync`

`mkblog` generates a static site, so deployment can be as simple as:

1. build locally
2. copy `public/` to the remote host
3. delete files on the remote host that no longer exist locally

That is a good fit for `rsync --delete` over SSH.

## Quick Command

```bash
go run ./cmd/mkblog build
rsync -av --delete public/ user@example.com:/var/www/mkblog/current/
```

This assumes `/var/www/mkblog/current/` is dedicated to the generated site.

## Safe Use of `--delete`

`--delete` is the right choice when the destination directory contains only the deployed site output.

Do not use `--delete` against:

- a shared directory
- a parent directory containing unrelated files
- a directory you are not prepared to fully synchronize to the current local build

If you are unsure, deploy into a dedicated path such as `/var/www/mkblog/current/`.

## Deployment Script

This repo includes a wrapper script at [scripts/deploy.sh](/usr/home/code/ssg/scripts/deploy.sh).

Example:

```bash
DEPLOY_TARGET=user@example.com \
DEPLOY_PATH=/var/www/mkblog/current \
./scripts/deploy.sh
```

What it does:

- builds the site locally
- creates the remote directory with `mkdir -p`
- runs `rsync -av --delete public/ user@example.com:/var/www/mkblog/current/`

Optional environment variables:

- `DEPLOY_TARGET`: SSH target such as `user@example.com`
- `DEPLOY_PATH`: remote directory to sync into
- `DEPLOY_OUT_DIR`: local build output directory, defaults to `public`
- `DEPLOY_SKIP_BUILD=1`: skip the local build step and sync the existing output

## Remote Web Server

The remote host should serve the synchronized directory directly with nginx or another static file server.

For the full nginx-oriented deployment walkthrough, including example config and validation steps, see [BLOG_DEPLOY.md](/usr/home/code/ssg/BLOG_DEPLOY.md).
