Deploy a project over ssh and rsync, and pull a database down to this machine
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Rafael Egli dd59ac6f37 Let a project include or exclude deploy paths. Version 0.1.3.
dostavka show prints the preset and dostavka.toml together. exclude adds a project skip. include ships a path the preset skips, including a protected path. Preset files are not edited.
2026-10-18 11:22:38 +03:00
presets Read the production database URL from .env. Version 0.1.2. 2026-10-07 18:22:06 +03:00
src Let a project include or exclude deploy paths. Version 0.1.3. 2026-10-18 11:22:38 +03:00
tests Let a project include or exclude deploy paths. Version 0.1.3. 2026-10-18 11:22:38 +03:00
.gitignore Initial 2026-10-03 11:05:15 +03:00
Cargo.lock Let a project include or exclude deploy paths. Version 0.1.3. 2026-10-18 11:22:38 +03:00
Cargo.toml Let a project include or exclude deploy paths. Version 0.1.3. 2026-10-18 11:22:38 +03:00
CHANGELOG.md Let a project include or exclude deploy paths. Version 0.1.3. 2026-10-18 11:22:38 +03:00
README.md Let a project include or exclude deploy paths. Version 0.1.3. 2026-10-18 11:22:38 +03:00

dostavka

Deploy a project over ssh and rsync, and pull a database down to this machine. The binary does not know Symfony, Kirby, React, or Express. A framework is a preset: build commands, rsync rules, and what to run on the server.

Phoenix stays on vps_deploy. type = "phoenix" runs mix deploy.

Nothing here uses Docker. A host can come from ~/.ssh/config, from the project file, or from both. A value in the project file wins. Changes are listed in CHANGELOG.md.

Install

From the repository root:

cargo build --release
mkdir -p "$HOME/.local/bin"
cp target/release/dostavka "$HOME/.local/bin/dostavka"
chmod +x "$HOME/.local/bin/dostavka"

Add this to ~/.zshrc once, if ~/.local/bin is not already on PATH:

export PATH="$HOME/.local/bin:$PATH"

Reload the shell and check the binary:

source ~/.zshrc
which dostavka
dostavka --version

which dostavka should print $HOME/.local/bin/dostavka. After the source changes, build and copy again. The copy is a snapshot of that build.

Cargo can install it instead. That binary lands in ~/.cargo/bin, which must be on PATH. If both copies exist, the shell runs whichever directory comes first.

cargo install --path . --force
strip ~/.cargo/bin/dostavka

Commands

Dry-run is the default. force is the only switch that writes.

dostavka deploy                         # build, then show the rsync plan
dostavka deploy --target prod force     # transfer and run remote commands
dostavka deploy --skip-build force

dostavka sync-db                        # dump only
dostavka sync-db --source prod --target local force
dostavka sync-db --file var/dumps/app-20261003-120000.sql.gz force
dostavka sync-db force --no-hooks

dostavka pull                           # content or uploads, prod → local
dostavka pull force

dostavka check
dostavka init --type react
dostavka preset kirby

dostavka show
dostavka exclude docs
dostavka exclude --remove docs
dostavka include content
dostavka include --remove content

dostavka --help
dostavka deploy --help
dostavka show --help
dostavka include --help

--force and the word force do the same thing.

A local build runs during the dry-run too, so the preview matches the files that would ship. It stops before any transfer when a build fails. --skip-build skips that step.

A project file

dostavka init --type symfony writes this. Keys you set replace the preset, except excludes and protect, which are added to the preset lists. include ships a path the preset skips. See What this project ships.

type = "symfony"
default_target = "prod"

[targets.prod]
ssh = "cyon_s129"          # alias from ~/.ssh/config, or user@host
dir = "public_html/buchs"
port = 22                  # overrides Port from the alias; leave it unset to keep that port

[build]
local = [
  "php bin/console tailwind:build --minify",
  "php bin/console asset-map:compile --env=prod",
]

[remote]
php = "/opt/alt/php84/usr/bin/php"   # substituted as {php}
run = [
  "{php} bin/console cache:clear --no-warmup --env=prod",
  "{php} bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration",
]

[hooks]
after_import = ["php bin/console app:reset-passwords"]

app:reset-passwords is the app's hasher. dostavka does not write UPDATE users SET password. Set that hook to the command that stores superSecret123. Until the hook is there, an import leaves the production hashes in the local database.

Connection is where host, user, port, and identity override that alias.

An empty list replaces the preset. A maintenance tree that only copies files:

[remote]
run = []

Per-target fields override the shared build, source, remote commands, and file list. One repo can ship a Vite client and an Express API:

type = "express"

[targets.web]
ssh = "vps"
dir = "/var/www/web"
build = ["npm --prefix client run build"]
source = "client/dist"
remote = []

[targets.api]
ssh = "vps"
dir = "/var/www/api"
source = "server"
remote = ["npm ci --omit=dev", "systemctl restart {service}"]

[remote]
service = "my-api"

dostavka deploy --target web and dostavka deploy --target api then do different work. Two directories with two dostavka.toml files are the other way, and --config points at a file.

What this project ships

The preset is the safe list. dostavka.toml is where this project changes it. The preset file is not edited.

dostavka show prints both, and says which lines come from the preset.

dostavka exclude docs appends docs to rsync.excludes. Excludes are added to the preset list. A folder the preset already skips is left as it is.

dostavka include content appends content to rsync.include. That path is deployed even though the preset skips it. The preset's protect entry and the dry-run check are lifted for that path. With rsync.delete on, a copy that exists only on the server can be removed. That is this project's decision.

dostavka include site/config/menu.php ships that file and leaves the rest of site/config/ skipped.

[rsync]
excludes = ["docs"]
include = ["content/"]

A path in both lists is an error. .git, .env, .env.local, dostavka.toml, and .dostavka.lock stay skipped. dostavka exclude --remove docs and dostavka include --remove content take a project entry back out.

Connection

~/.ssh/config and the project file are read together. A value in the project file wins.

ssh names a Host block, or it is user@host. host, user, port, and identity are written in this file. Set the alias, the fields, or both. ssh still loads ~/.ssh/config, so ProxyJump and every option left unset in the project keep working. host, user, and port go out on the ssh command line, which overrides HostName, User, and Port.

[targets.prod]
ssh = "cyon_s129"              # Host block: ProxyJump and the rest
host = "203.0.113.10"          # overrides HostName
user = "deploy"                # overrides User
port = 22                      # overrides Port
identity = "~/.ssh/id_ed25519" # offered first
dir = "/var/www/app"

The same fields are enough when the server has no Host block:

[targets.prod]
host = "203.0.113.10"
user = "deploy"
port = 22
identity = "~/.ssh/id_ed25519"
dir = "/var/www/app"

~/ in identity expands from $HOME. That key is offered first, and ssh does not take other keys from the agent. An IdentityFile for the same host in ~/.ssh/config can still be tried after the project key. The host is a name or an IPv4 address, and the port stays in port. When ssh is already user@host, leave user unset.

A plain alias leaves rsync on its own ssh. Once the project sets host, user, port, or identity, rsync receives them through -e, and that ssh still reads ~/.ssh/config. The key path cannot contain a space, because rsync splits the remote shell on spaces.

dostavka opens ssh with BatchMode. It will not ask for a password or accept a new host key. The key has to be in the agent when it has a passphrase, and the host key has to already be in known_hosts (one manual ssh to the host, or ssh-keyscan).

Presets

Type What it does
symfony Rsync src/, templates/, public/, and the usual project dirs. Exclude var/, vendor/, uploads. Remote cache clear and migrations. MariaDB pull.
kirby Rsync the project. content/, accounts, sessions, cache, media, kirby/, and vendor/ stay on the server. dostavka include content ships content/ for this project. Pulls content/ and site/accounts/.
react npm run build, then rsync dist/. Create React App: set rsync.source to build.
express Rsync the source without node_modules. The server runs npm ci --omit=dev. Add the restart command yourself.
static Rsync only.
phoenix mix deploy --dry-run, or mix deploy with force.

dostavka preset express prints the file that is actually used.

Add a framework

Copy a preset and edit it. No rebuild.

mkdir -p ~/.config/dostavka/presets
dostavka preset express > ~/.config/dostavka/presets/fastify.toml

A file with the same name as a built-in replaces that built-in. dostavka init --type fastify writes a project file whose defaults come from that preset.

The engine understands these ideas:

  • build.local — shell commands on this machine
  • rsync.source — one directory, such as dist/
  • rsync.paths and rsync.files — several directories, files without --delete
  • rsync.rules — ordered include ... and exclude ... patterns. A project rules list replaces the preset rules
  • rsync.excludes — added to the preset excludes. dostavka exclude writes this
  • rsync.include — project paths that ship even when the preset skips them. dostavka include writes this
  • remote.run — shell commands on the server, with {php}, {service}, and {dir}
  • delegate.deploy — hand the whole deploy to another command

build.local, remote.run, and delegate commands are shell. dostavka.toml is trusted the same way the old bash scripts were. Do not commit secrets in it.

Database pull

sync-db reads DATABASE_URL from remote_env on the server (.env by default, and for the Symfony preset) and runs mariadb-dump or pg_dump there. The host in that URL is the address as the SSH server sees it, often 127.0.0.1. The production password stays in that remote script's environment. It is not an ssh argument and it is not written into dostavka.toml.

That is access = "remote", the default. Some databases accept connections only from a jump host. access = "tunnel" opens ssh -N -L and runs the dump on this machine, against 127.0.0.1 and the forwarded port. The password is MYSQL_PWD or PGPASSWORD on the local dump, still not an argument.

The SSH host is the sync-db source target, another target named with via, or the endpoint in [databases.main.ssh]. Use one of those.

[databases.main]
engine = "postgres"
access = "tunnel"          # default is "remote": the dump runs on the SSH host
# via = "prod"             # a deploy target. Leave this out when the ssh table below is set.
url_file = ".env.db-sync"  # optional local file; otherwise remote_env is read on the server
# remote_dir = "/var/www/app"

[databases.main.ssh]       # when the database is not on a deploy target
host = "db.example"
user = "backup"
port = 22
identity = "~/.ssh/db"

url_file is a project-relative file, usually gitignored. It holds DATABASE_URL (or url_var), or a single line that is the URL. The host in it is still the address as seen from the SSH server. With url_file set, the remote env file is not read. Keep the password in that file, not in dostavka.toml.

remote_dir is where remote_env lives when that directory is not the target dir. An absolute path is allowed.

The dump is stored under dump_dir. Without force, that is the whole command.

force recreates the local database, imports, and runs hooks.after_import. The local URL comes from the environment variable local_url_env, then from .env.local when that file sets it, otherwise from local_env (.env). A local_env other than .env is the only file read. The host must be localhost, 127.0.0.1, or ::1. There is no target that uploads a database.

MariaDB dumps are gzipped SQL. DEFINER clauses and the MariaDB sandbox line are stripped on import. Postgres dumps are pg_dump --format=custom and come back through pg_restore --no-owner.

Set engine = "postgres" on a Symfony-shaped config when the URL is Postgres. The URL scheme is checked against engine.

Kirby has no SQL database. dostavka pull copies content/ and site/accounts/. media/ stays on the server. Kirby rebuilds it.

What the transfer refuses to do

  • --delete-excluded. macOS openrsync ignores protect filters, and that flag deletes the paths an exclude is keeping. An exclude is the shield. .git, .DS_Store, .env, .env.local, dostavka.toml, and .dostavka.lock are always excluded. rsync.include cannot put them back.
  • A dry-run that mentions a protected path this project did not include. content/, uploads, and the Kirby account files abort the deploy before the real rsync. rsync.include lifts that check for the path you name.
  • --max-delete. Rsync exits 25 and dostavka stops. Raise the number only after the dry-run looks right.
  • A second deploy. force creates .dostavka.lock on the server and removes it afterwards. Delete that directory by hand if a deploy dies and leaves it.
  • An import into a host that is not this machine.

dostavka check opens ssh with BatchMode. A key passphrase has to be in the agent already, and the host key has to already be in known_hosts. dostavka will not prompt. For access = "tunnel" it looks for mariadb-dump or pg_dump on this machine. For access = "remote" it looks for that tool on the SSH host.

Layout

presets/     built-in frameworks, also printed by `dostavka preset`
src/         the CLI
dostavka.toml   written in each project by `dostavka init`

Search for dostavka.toml starts in the current directory and walks up. --config path skips the walk.