Deploying
motabhai deploy builds the site and publishes it to a target named in motabhai.toml: GitHub Pages, a directory or server over rsync, or S3-compatible storage.
Deploy targets
Each place the site is published to is a [deploy.<name>] table in
motabhai.toml, with a type and that type's settings:
[deploy.github-pages]
type = "github-pages"
[deploy.server]
type = "rsync"
target = "deploy@example.com:/var/www/site"
[deploy.bucket]
type = "s3"
bucket = "www.example.com"
region = "eu-west-1"
motabhai deploy NAME builds the site, running its
build hooks, and then publishes the output to the target NAME:
motabhai deploy github-pages motabhai deploy server --output dist # build into dist/ first
The name can be left out when the site has exactly one target. With
several, or none, motabhai deploy alone fails with
motabhai::deploy::no_target and lists the targets there are; an unknown
name is motabhai::deploy::unknown_target. Both are reported before
anything is built. A site that fails to build, or whose hook fails, is not
deployed. When it is done the command says what it did, such as
deployed to github-pages: pushed a new commit to gh-pages.
--output and the other flags are in the
command line reference.
The settings are checked when the project is opened, like the rest of the config:
| Code | Meaning |
|---|---|
motabhai::config::invalid_deploy_type | type is not github-pages, rsync or s3. |
motabhai::config::invalid_deploy_key | A key that belongs to another type, such as bucket on an rsync target. |
motabhai::config::missing_deploy_key | A required key is missing, such as an rsync target without target. |
motabhai::config::invalid_deploy_value | A value is not valid, such as an empty remote, a branch that is not a branch name, or a cname with https://. |
Problems while deploying, such as a remote that is not a repository or a
request the server refuses, are motabhai::deploy::failed, with the
underlying error.
Deploying from the admin
While motabhai serve runs, the dashboard of the admin at
/admin/ lists these targets with a Deploy button each. It asks first,
then runs motabhai deploy <name> in the project, so the hooks, checks and
build are the same as on the command line, and shows its output as it
runs. Credentials still come from the environment motabhai serve was
started in; the admin never shows them.
GitHub Pages
[deploy.github-pages]
type = "github-pages"
remote = "origin" # the default
branch = "gh-pages" # the default
cname = "www.example.com"
| Key | Default | Meaning |
|---|---|---|
remote | "origin" | Where to push: the name of a git remote of the project's repository, or a repository URL or path. A relative path is relative to the project root. |
branch | "gh-pages" | The branch the site is committed to. |
cname | none | A custom domain. If set, a CNAME file with it is added to the site. |
The deploy commits the output as a new commit on top of the branch,
creating the branch if it does not exist, and pushes it. It never
force-pushes, so commits others made on the branch are kept. Each commit
holds the whole site plus a .nojekyll file, so GitHub serves paths
starting with _ as they are instead of running Jekyll. Every file of the
output is committed, whatever .gitignore says. If the output is the same
as what the branch already holds, nothing is committed or pushed, and if
the branch moved while the site was being deployed the push fails rather
than overwrite it.
The commit's message is Deploy <site name>, and in a git repository it
names the commit the site was built from. Its author is the one git is configured with,
or motabhai <motabhai@localhost> where git has none, as on a CI runner.
It needs git on your PATH (motabhai::deploy::missing_tool
otherwise), and it uses the project's own repository and its credentials,
so whatever lets you git push lets you deploy. Git is not allowed to ask
for a password, so a push that would need one fails. With the default
remote = "origin", the project must be inside a git repository with that
remote. A project that is not in a git repository can still deploy to a
remote that is a URL or a path. No gh-pages branch is created in your
local repository, and its working tree is not touched.
Setting up a GitHub Pages site
motabhai new already includes the [deploy.github-pages] target above
(without cname) and a GitHub Actions workflow,
.github/workflows/deploy.yml, that deploys on every push to main:
name: Deploy on: push: branches: [main] workflow_dispatch: permissions: contents: write concurrency: group: deploy cancel-in-progress: false jobs: deploy: runs-on: ubuntu-latest env: MOTABHAI_VERSION: "0.2.0" steps: - uses: actions/checkout@v5 - name: Install motabhai run: | mkdir -p "$HOME/.local/bin" curl --proto '=https' --tlsv1.2 -fsSL \ "https://github.com/gamesbrainiac/motabhai/releases/download/v$MOTABHAI_VERSION/motabhai-x86_64-unknown-linux-musl.tar.gz" \ | tar -xz -C "$HOME/.local/bin" motabhai echo "$HOME/.local/bin" >> "$GITHUB_PATH" - name: Build and deploy run: motabhai deploy github-pages
The workflow installs the release of motabhai that created the site; change
MOTABHAI_VERSION to upgrade. actions/checkout leaves credentials for
the repository in its git config, and contents: write lets them push, so
motabhai deploy pushes to gh-pages of the same repository with no
secrets to set up.
To publish a site:
- Set
project.url. A project site is served athttps://<user>.github.io/<repository>/, so set
and every link gets the[project] url = "https://<user>.github.io/<repository>/"/<repository>/base path. A user site (a repository named<user>.github.io) or a site on a custom domain is served from the root; seturlto that address. - Push to
main. The workflow's first run creates thegh-pagesbranch. - Turn on Pages. In the repository's Settings → Pages, under Build
and deployment, set Source to Deploy from a branch, and choose the
gh-pagesbranch and the/ (root)folder.
For a custom domain, set cname in the target and project.url to the
domain, and point the domain's DNS at GitHub Pages as GitHub's
documentation describes.
You can deploy from your own machine the same way: motabhai deploy
pushes to origin with your own git credentials.
rsync
[deploy.server]
type = "rsync"
target = "deploy@example.com:/var/www/site"
delete = true
args = ["--compress", "--exclude=.well-known"]
| Key | Default | Meaning |
|---|---|---|
target | required | Where to copy the site: user@host:/path for a server over SSH, or a local directory. A relative directory is relative to the project root. |
delete | true | Remove files on the target that the build no longer has. |
args | [] | Extra arguments for rsync, as a list of strings. |
The output directory's contents are copied into target, by running
rsync -rltz, with --delete unless delete = false, and then args.
This needs rsync on your PATH (motabhai::deploy::missing_tool
otherwise), and for a server, SSH access with your usual keys and
~/.ssh/config.
S3 and S3-compatible storage
[deploy.bucket]
type = "s3"
bucket = "www.example.com"
region = "eu-west-1"
| Key | Default | Meaning |
|---|---|---|
bucket | required | The bucket name. On AWS, a name with a dot in it is addressed by path. |
region | "us-east-1" | The bucket's region. |
endpoint | AWS | The endpoint of S3-compatible storage, such as Cloudflare R2, MinIO or Backblaze B2: an http:// or https:// URL. The bucket is then addressed by path. |
prefix | none | A key prefix, so the site lives in part of the bucket: with prefix = "www", index.html is stored as www/index.html. Slashes around it make no difference. |
delete | true | Delete objects (under the prefix) that the build no longer has. |
Credentials come from the environment:
| Variable | |
|---|---|
AWS_ACCESS_KEY_ID | Required. |
AWS_SECRET_ACCESS_KEY | Required. |
AWS_SESSION_TOKEN | Optional, for temporary credentials. |
Without them the deploy fails with motabhai::deploy::credentials before
the site is built. Requests are signed with AWS Signature Version 4. Only
files whose content changed are uploaded: each file's MD5 hash is compared
with the object's ETag. Every upload gets a Content-Type from the file's
extension, such as text/html; charset=utf-8. The command reports how
many files were uploaded, deleted and unchanged.
For Cloudflare R2, for example:
[deploy.r2]
type = "s3"
bucket = "my-site"
region = "auto"
endpoint = "https://<account id>.r2.cloudflarestorage.com"
Serving the bucket as a website (an index document, public access, a CDN in front) is set up with your storage provider, not by motabhai.