Craft CMS assets handling

Published

Updated

Craft CMS assets stay out of git. Sync them between local development and fortrabbit with rsync or SFTP, or store them in S3.

Install and deploy run down

  1. Install Craft CMS locally
  2. Setup an app at fortrabbit
  3. Deploy code via Git
  4. Database syncing
  5. Assets syncing ← you are here

Assets and git

Craft CMS assets are uploaded files, mostly images, stored in volumes, see the Craft docs on assets. They stay out of git: files uploaded on the environment never reach the repository, because git deployment only goes up.

When Craft creates the folder of a local filesystem, it adds a .gitignore file to it. For a folder that existed before, add that file by hand:

*
!.gitignore
gitignore

Sync assets with rsync

rsync copies only changed files, in both directions. Replace uploads with the folder of the volume:

# UP: local to fortrabbit
rsync -av ./web/uploads/ {{app-env-id}}@ssh.{{region}}.frbit.app:web/uploads/

# DOWN: fortrabbit to local
rsync -av {{app-env-id}}@ssh.{{region}}.frbit.app:web/uploads/ ./web/uploads/
shell

Add --dry-run to see what would change first. The rsync guide covers excludes and --delete.

Sync assets with SFTP

An SFTP client works too. Many clients have a sync option that compares local and remote folders.

Store assets in S3

With the first-party Amazon S3 plugin, Craft stores uploads in an S3 bucket instead of the environment's storage, and nothing needs syncing. It adds a service to pay for and set up, so use it for many or large files, not by default.

Written by humans and AI in collaboration.

AI use & editorial processEdit on GitHub ↗