Thatās what I assumed, but I get nowhere unless I set both DISCOURSE_S3_UPLOAD_BUCKET and DISCOURSE_S3_BUCKET. As you can see from the code snippet posted above use_s3? is still looking for s3_bucket and not s3_upload_bucket.
Setting DISCOURSE_BACKUP_BUCKET doesnāt resolve that as far as I can tell.
If I set both bucket environment variables I get one step further, but now Iāve come across a new issue, where Discourse is ignoring my S3 CDN url and trying to load assets from my base path. This is causing CSP errors as the Content Security Policy only includes the asset path from my S3 CDN.
It should be DISCOURSE_S3_BACKUP_BUCKET instead of DISCOURSE_BACKUP_BUCKET. Other than that if you are setting all the variables with the two Cloudfront distributions should work. If you see our settings we are not defining DISCOURSE_S3_BUCKET
@Falco As far as I remember one thing that made this very counterintuitive is that there is a difference in behavior between setting DISCOURSE_S3_CDN_URL as an environment variable / GlobalSetting and configuring it as a SiteSetting. Maybe that is something you want to pay attention to in your howto.
Yep sorry that was a typo just in my previous post. DISCOURSE_S3_BACKUP_BUCKET doesnāt set s3_bucket in GlobalSetting for me. Iām not sure how youāre running that rake task without setting DISCOURSE_S3_BUCKET.
I really appreciate your help btw and realise this isnāt your problem to solve, so thanks.
def ensure_s3_configured!
unless GlobalSetting.use_s3? || use_db_s3_config
STDERR.puts "ERROR: Ensure S3 is configured in config/discourse.conf or environment vars"
exit 1
end
end
use_db_s3_config is saving you from having to set that extra variable. That must be a bug in global_setting.rb because I should be able to just set DISCOURSE_S3_UPLOAD_BUCKET unless there is a difference between that and DISCOURSE_S3_BUCKET, but I think youāre right that the latter is supposed to be deprecated.
Irrespective of a bug in global_setting.rb Iām still seeing an issue where Discourse is looking for assets in their usual place and not on my S3 CDN, even though Iāve declared all my variables and DISCOURSE_ENABLE_S3_UPLOADS is set to true.
Thereās a task for this bundle exec rake uploads:migrate_to_s3 . Once you have configured your buckets you should run that task to move uploads to s3. S3/CDN has changed in the recent few months and documentation is not up to date, so make sure you backup and prepare in case something goes wrong.
When I was enabling this for the first time we had some downtime while we figure everything out/
I guess this is because you are missing DISCOURSE_CDN_URL. We have it like this in our config
DISCOURSE_CDN_URL: 'https://d16zv78c963s69.cloudfront.net' # this points to the server
DISCOURSE_S3_CDN_URL: 'https://community-cdn-prod.debtcollective.org' # this points to S3 bucket
Stylesheets are fetched from the server so they use DISCOURSE_CDN_URL. JavaScript itās uploaded to the S3 bucket and uses DISCOURSE_S3_CDN_URL. @Falco explained this to me here.
Yep I saw that. Iāve set DISCOURSE_CDN_URL but I still get the same issue. However Iām tired so maybe I missed something with all the messing around. Will pick this back up tomorrow. Thanks for the help.
bundle exec rake uploads:migrate_to_s3 will upload only attachments to S3, this task needs to be run once. After you enable S3 new uploads will be saved in the S3 buckets.
To upload assets you need to use bundle exec rake s3:upload_assets and this needs to run after every rebuild/upgrade.
i did what you mentioned and uploads to s3 (images etc ) are successful but but for assets i get below error
ERROR: Ensure S3 is configured in config/discourse.conf or environment vars
i set both
DISCOURSE_CDN_URL: 'https://d16zv78c963s69.cloudfront.net' # this points to the server
DISCOURSE_S3_CDN_URL: 'https://community-cdn-prod.debtcollective.org' # this points to S3 bucket
there is an interesting problem, discourse trying to reach asset files from wrong path. it tries to reach from brotli_asset path but there is no this path in S3 bucket.
Also it tries to reach javascripts and stylesheet files from cdn url. But there are not these files in bucket also.
By setting the data in admin panels to S3 everything works properly and everything loads to S3. I do not have any settings in ENV. Is that bad ? Is it necessary if everything works ?
The second example is different because I canāt migrate the old data to S3 (only new ones work) But here entering this data in app.yml (DISCOURSE_S3_ACCESS_KEY_ID: ākeyā etc) file doesnāt change anything and it still doesnāt work (i.e.