Upload assets to S3 after in-browser upgrade

After moving my site’s images and assets (js) to s3, I tried to upgrade the forum by using the /admin/upgrade interface. It upgraded fine but it seems like it didn’t upload the assets to s3 bucket, rendering by site unavailable untill I rebuilt the app from the shell.
There I have a hook which does it for me. It would be nice to have this sort of functionality in web interface aswell. I don’t know if it’s already present if it is please let me know. :slight_smile:

 after_assets_precompile:
   - exec:
       cd: $home
       cmd:
         - sudo -E -u discourse bundle exec rake s3:upload_assets

No, You can’t move assets to s3 from the admin area. You’ll have to do that through ssh Because there are additional tasks that are required at the time of this migration unless you’re doing this on a fresh install.

3 Likes

Ah I see, I liked the seemless no downtime way of upgrading until I switched to s3. Is there a way of not serving js through s3 and only images through it?

You can’t serve JS through S3. You only can upload and serve media (images/documents/videos etc.) Through S3.

For JS you’d need a CDN e.g. cloudfront.

1 Like

Yes I am not serving JS directly from S3, it’s stored in S3 then served through CDN. What I meant to ask was can I store JS locally and serve it through CDN, storing only the media on S3.

You’re getting it all wrong once again.
Discourse JS is meant to be served directly through the CDN with the Discourse installation being the pull origin. I don’t know how you’d put JS in s3 but bear in mind that JS is regenerated upon rebuild. Whatever you’d be serving through s3 would probably be outdated and you’ll be inviting more trouble.

It started happening after I configured s3 settings following this Configure an S3 compatible object storage provider for uploads

That’s why they added the after_assets_precompile hook to upload the updated assets on s3.

How do I fix this. It 404s if I try to access any asset through local server. It have to be through s3. Or I would’ve put an edge routing rule on my cdn pulling asset requests through local domain.

If You read the post title, it is “Object Storage for Uploads” says enough in the title.

What do you mean by local domain? Where is your Discourse installed?

By local domain I meant the server my discourse is installed on, like the js files were local to the nginx server and not on s3.

Unfortunately, the topic that is being mentioned doesn’t do that, even while it is indeed called “using object storage for uploads”. If you configure your forum according to the instructions in that topic, it requires the assets being pushed onto S3.

3 Likes

How can I configure it in a way that allows to me keep JS files in discourse installation server.