Deploy Statamic with Git and rsync
Deploy Statamic with Git and rsync to fortrabbit.
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
Open your local Statamic project folder with your text editor or IDE. Within it open the .gitignore file at the root level to tell Git to ignore all content. We need to add any folders to .gitignore which contain user-generated content:
… # Exclude stuff you are creating from Git /content /users /resources/blueprints /resources/fieldsets /resources/forms /resources/users /storage/forms /public/assetsshell
PLEASE NOTE: This is our recommended way of doing it. It separates code from content. You will need to run dedicated rsync commands to deploy and update this user-generated content (see below). You can also decide to not touch the .gitignore file so that you can deploy everything with Git all together. Keep in mind that you can not pull in new contents from the fortrabbit App this way (see on work-flows 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
It's assumed that you have a repo created at GitHub and it's connected to your local code base. At least once, you should have run git push.
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 and 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 up- or down-load new contents 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:/shell
(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 ./ $ rsync -av '{{app-env-id}}@ssh.{{region}}.frbit.app:/resources/fieldsets ./ $ rsync -av '{{app-env-id}}@ssh.{{region}}.frbit.app:/resources/forms ./ $ rsync -av '{{app-env-id}}@ssh.{{region}}.frbit.app:/resources/users ./ $ rsync -av '{{app-env-id}}@ssh.{{region}}.frbit.app:/storage/forms ./ $ rsync -av '{{app-env-id}}@ssh.{{region}}.frbit.app:/public/assets' ./shell