Deploy Kirby with Git and rsync

This is the recommended workflow to deploy Kirby using Git. It's a bit more advanced, but worth the mile when maintaining a project.

Get ready

Rundown

  1. Start Git and integrate with GitHub
  2. Connect your GitHub repo with fortrabbit
  3. Synchronize contents with rsync

Configure Kirby for git deployment with rsync

Open the (hidden) .gitignore file at the top level of the Kirby project folder. Add these three ignore rules if not already present:

# .gitignore

# Kirby itself, managed by composer
/kirby

# Composer, managed
/vendor

# To be synced by rsync not Git
# Can also be included, to keep an extra copy
# Will not be deployed (default exclude patterns)
/content
shell

This keeps the repo tidy by separating code and content, but requires rsync for content updates (see below). If you prefer, leave .gitignore unchanged and deploy everything with Git.

At this point you should be able to run the project in your local development environment already. We recommend developing the site locally and using fortrabbit for staging and production.

Init Git and add GitHub

See the git deployment intro to get an idea how to connect a local repo to the GitHub remote and enable automatic deployment by installing the fortrabbit GitHub App with GitHub account.

Here is an example creating a repo from your local code base and using git command line and GitHub CLI to set up a local repo, and connect it to GitHub.

# Setup local git repo
$ git init
$ git add -A
$ git commit -am 'Init'

# GitHub CLI to create/connect remote Git repo
$ gh repo new
# Follow the steps
# Push an existing local repository to github.com
# Add as remote and assign current branch as 'origin'
shell

At the end, the Git repo at GitHub is created and content already pushed. From now on you only need to run add, commit and git push to send code changes to GitHub.

Connect your GitHub repo with fortrabbit

Now, the last step is to set up and connect an app on fortrabbit. Start the process in the fortrabbit dashboard:

https://dash.fortrabbit.com/new/app

Choose Kirby as software preset. Use Git deployment and select the Git repo that you have created previously. At the end of the process, start the first deployment and lean back. At this stage you have deployed a semi-broken Kirby installation. That's expected because the content is missing. See next step.

If you already created a new empty app at fortrabbit, connect the repo branch through dashboard settings.

Deployment settings

https://dash.fortrabbit.com/environments/{{app-env-id}}/deployment

You should be all set when choosing Kirby CMS as software with the app at fortrabbit. The software template will be preconfigure deployment settings. The replace deployment strategy is set, with content and media folders to be excluded. Adjusting those settings is required when using Composerkit.

Synchronize contents with rsync

As mentioned, deployment of code (templates and configuration) and dependencies (Kirby and Composer) is done via Git deployment. Deploying the content is a separate step. We recommend using rsync to upload or download new contents to and from your remote fortrabbit environment. See also our rsync article. In a terminal, from the Kirby project folder, run:

# SYNC UP: from local content folder and its files to remote
$ rsync -av ./content/ {{app-env-id}}@ssh.{{region}}.frbit.app:content/
shell

It also works the other way around. For example, if you have done some edits online and want those changes to be reflected in your local development environment:

# SYNC DOWN: from files from remote content folder to local folder
$ rsync -av {{app-env-id}}@ssh.{{region}}.frbit.app:content/ ./content/
bash

You can also use SFTP to synchronize the content folder.

Going forward

From now on you can git push to trigger a deployment to fortrabbit via GitHub.

Found a tpyo?Edit