The default for Forgejo is to use local storage but I wanted to migrate to Linode (Referral ) Object Storage for better scaling since I am using a lower spec VM for my instance. I found the post Upgrading Forgejo with S3 Object Storage which gave me a good starting point.
Configuration
From the Linode Object Storage
page, I needed to Create a new bucket in the region I want.
After creating it, I went to the settings and enabled Public Read for the ACL settings.
Since I am using saltstack
for my deployment, the next step was to add entries for Storage to my app.ini file.
I am using my vars.get method which does a bit of wrapping around grains.get,pillar.get, and defaults.get.
# https://forgejo.org/docs/latest/admin/setup/storage/
[storage]
STORAGE_TYPE = minio
MINIO_ENDPOINT = {{ salt['vars.get']('forgejo:s3:endpoint') }}
MINIO_ACCESS_KEY_ID = {{ salt['vars.get']('forgejo:s3:access_key') }}
MINIO_SECRET_ACCESS_KEY = {{ salt['vars.get']('forgejo:s3:secret_key') }}
MINIO_BUCKET = {{ salt['vars.get']('forgejo:s3:bucket') }}
MINIO_LOCATION = us-east-1
SERVE_DIRECT = true
Then I used my pillar-tool to set the values I need.
# From the bucket I created
pillar set forgejo:s3:endpoint
pillar set forgejo:s3:bucket
# From the access key I created
pillar set forgejo:s3:access_key
pillar set forgejo:s3:secret_key
After this I can apply my configuration.
salt-call state.apply forgjeo.docker
With Forgjo back up, I need to copy over my data files.
This can easily be done with the s3cmd tool
Syncing Data
# Install using apt (or yum or whatever your package manager is)
apt-get install s3cmd
# Configure with your Linode Object Storage credentials
s3cmd --configure
After that, we can use the sync sub command to push our local files to our remote buckets.
We need to ensure we use the path as /folder instead of /folder/ so that we sync the folder instead of just the contents.
s3cmd sync /path/to/gitea/avatars s3://my-forgejo-bucket/
s3cmd sync /path/to/gitea/packages s3://my-forgejo-bucket/
s3cmd sync /path/to/gitea/repo-archive s3://my-forgejo-bucket/
s3cmd sync /path/to/gitea/repo-avatars s3://my-forgejo-bucket/
Notes
I am currently using SERVE_DIRECT = true to save some bandwith (hit the bucket directly instead of proxying via Forgejo) though I have also considered configuring that for packages only.
That would result in a ‘friendier’ link for most files like avatars, but hit the bucket directly for any larger files.