Deploy Statamic with Git and rsync
Reviewedbyfl
Markdown ↓Deploy Statamic on fortrabbit using Git for code and rsync for user-generated content, keeping your version control clean.
Get ready
You should have Statamic running on your local machine, have a good understanding of Git and rsync, have an app on fortrabbit ready. Read our Statamic intro first.
Setup GitHub at least once
To enable git deployments, init git and add GitHub as remote repo. The Statamic CLI has some helpers for GitHub already. You can use any GUI or the GitHub CLI. Here is an example:
Configure Statamic for Git with rsync
To separate code from content, configure .gitignore at the project root to exclude user-generated files. Add the following folders to ensure only application code is version controlled:
…
# Exclude stuff you are creating from Git
/content
/users
/resources/blueprints
/resources/fieldsets
/resources/forms
/resources/users
/storage/forms
/public/assets
Note: this is our recommended approach. It separates code from content. You'll need to run dedicated rsync commands to deploy and update user-generated content (see below). Alternatively, you can skip modifying .gitignore and deploy everything via Git, but then you cannot pull new content from your app (see workflows above).
At that point you should be able to run the project in your local development environment already. We highly recommend developing the site locally, using fortrabbit for staging and production.
Push to GitHub
You must have a GitHub repository created and connected to your local codebase, with at least one successful git push executed to sync your repository.
Connect GitHub with fortrabbit
To connect your GitHub repo with an app on fortrabbit, you first need to install the fortrabbit GitHub app. In many cases, this done during boarding. See your account settings if GitHub is connected:
Create an app or connect an existing app to a Git repo.
Depending on the steps and some configuration, this may already have deployed the initial state. In any case, once the connection is made, going further, new code can be deployed by git push.
Synchronize content with rsync
As mentioned above, deployment of your code base (templates and configuration) and dependencies (Statamic and Composer) is done via Git deployment. Deploying the content is a separate step. We recommend using rsync to upload or download new content to and from your remote fortrabbit app (see also our rsync article). On your local computer in the terminal in the Statamic project folder execute:
# SYNC UP: from local to remote
$ rsync -avR ./content ./users ./resources/blueprints ./resources/fieldsets ./resources/forms ./resources/users ./storage/forms ./public/assets {{app-env-id}}@ssh.{{region}}.frbit.app:./
(You may not have all these folders on your local system: Only include folders which you do have.)
It works also the other way around. For example, if you have some edits done online and want them to be reflected in your local development environment:
# SYNC DOWN: from remote to local
rsync -av '{{app-env-id}}@ssh.{{region}}.frbit.app:./content' ./
rsync -av '{{app-env-id}}@ssh.{{region}}.frbit.app:./users' ./
rsync -av '{{app-env-id}}@ssh.{{region}}.frbit.app:./resources/blueprints' ./resources/
rsync -av '{{app-env-id}}@ssh.{{region}}.frbit.app:./resources/fieldsets' ./resources/
rsync -av '{{app-env-id}}@ssh.{{region}}.frbit.app:./resources/forms' ./resources/
rsync -av '{{app-env-id}}@ssh.{{region}}.frbit.app:./resources/users' ./resources/
rsync -av '{{app-env-id}}@ssh.{{region}}.frbit.app:./storage/forms' ./storage/
rsync -av '{{app-env-id}}@ssh.{{region}}.frbit.app:./public/assets' ./public/