Creating a repo on S3
To really make Sprout work for your team, you’ll probably want to store your content somewhere central. Amazon S3 (or other S3 compatible services) can be a great choice. Let’s set up a new repo on S3!
1. Create the repo definition
Let’s create a new repo definition. Let’s call it something unique, like my-s3-repo…
sprout repo new my-s3-repoSprout will now fire up an editor, allowing you to modify the repo definition. As we’re going to use S3, we need to use opendal:s3 as our repository, and set some other options:
repo_key: ''repository: opendal:s3repo-hot: nulloptions: {}options: access_key_id: <YOUR S3 ACCESS KEY> endpoint: <YOUR S3 ENDPOINT> region: <YOUR S3 REGION> secret_access_key: <YOUR S3 SECRET> bucket: <YOUR S3 BUCKET NAME>options-hot: {}options-cold: {}Make sure to save and exit the editor when you’re done.
2. Initialise the repo
Now initialise the repo by running:
sprout repo init my-s3-repoLet Sprout create and set a repo key for you. This is your encryption key for your repo, not your S3 access key. They should be unique.
If all goes well, you should see success.
3. Test!
Now everything is set up, let’s push a snapshot.
Switch to an existing Sprout project (or initialise a new one with sprout init), then edit the sprout.yaml file to point to our new repo definition.
It’s also a good idea to clear the snapshot ID field too when changing repo:
name: my-existing-projectbranch: mainsnapshot: ''uploads_path: public/content/uploadsrepo: my-s3-repoNow we are ready to snapshot. Let’s run:
sprout snapThe initial snapshot should complete - it may take a little while. There is no parent present, so the first snapshot will need to upload all of your content. Subsequent snapshots will be faster.
Let’s check and see if we can see the snapshot in our repo. List the snapshots by running:
sprout lsYou should see your new snapshot! That’s all there is to it.
4. Sharing your repo definition
When using a remote storage backend for a repo, we often want to share our repo definitions with the rest of our team. All your repo definitions exist at ~/.sprout/repos.
It’s not a good idea to send our S3 access keys and secrets around as part of the definition, so you should replace any sensitive keys with an environment variable. For example:
repo_key: Kheq43pnuJGdidIY0uItHinKIIl34kedImyIs3cr3tsL5l4hCBketjqcjNrepository: opendal:s3repo-hot: nulloptions: access_key_id: ${S3_ACCESS_KEY} endpoint: https://s3.amazonaws.com region: eu-west-1 secret_access_key: ${S3_SECRET} bucket: sprout-testoptions-hot: {}options-cold: {}