Error when doing "bundle exec rake s3:upload_assets" - Could not locate Gemfile or .bundle/ directory

I am trying to do "bundle exec rake s3:upload_assets" as root and it yields the following erros: Could not locate Gemfile or .bundle/ directory.

I also tried doing it without root, using "sudo -E -u discourse bundle exec rake s3:upload_assets" and it yielded the following error: sudo: unknown user discourse sudo: error initializing audit plugin sudoers_audit

  • I did both commands in the following directory: /var/discourse
  • This is a normal installation, not using docker or anything.

How can I fix this so I am able to run this?

Thank you.

You need to run it inside the container.

cd /var/discourse
./launcher enter app

And then run that command

1 Like

Thank you! That got me further, I am now at this error:

root@redacted:/var/www/discourse# sudo -E -u discourse bundle exec rake s3:upload_assets
/root is not writable.
Bundler will use `/tmp/bundler20250409-510203-w6snye510203' as your home directory temporarily.
ERROR: Ensure S3 is configured in config/discourse.conf or environment vars```

I do have everything configured in the Discourse site settings. I am not using Docker so I would not need environment vars?

I tried to add the environment vars in app.yml, rebuild, and re-entered app and ran command and gives this:

`/root` is not writable.
Bundler will use `/tmp/bundler20250409-1393-48ek5u1393' as your home directory temporarily.
Installing CORS rules...
Attempting to apply ASSETS S3 CORS ruleset in bucket biohacking-forum.
rake aborted!
Seahorse::Client::NetworkingError: Empty or incomplete response body (Seahorse::Client::NetworkingError)
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/aws-sdk-core-3.219.0/lib/seahorse/client/plugins/raise_response_errors.rb:17:in `call'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/aws-sdk-s3-1.182.0/lib/aws-sdk-s3/plugins/sse_cpk.rb:24:in `call'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/aws-sdk-s3-1.182.0/lib/aws-sdk-s3/plugins/dualstack.rb:21:in `call'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/aws-sdk-s3-1.182.0/lib/aws-sdk-s3/plugins/accelerate.rb:43:in `call'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/aws-sdk-core-3.219.0/lib/aws-sdk-core/plugins/checksum_algorithm.rb:169:in `call'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/aws-sdk-core-3.219.0/lib/aws-sdk-core/plugins/jsonvalue_converter.rb:16:in `call'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/aws-sdk-core-3.219.0/lib/aws-sdk-core/plugins/invocation_id.rb:16:in `call'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/aws-sdk-core-3.219.0/lib/aws-sdk-core/plugins/idempotency_token.rb:19:in `call'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/aws-sdk-core-3.219.0/lib/aws-sdk-core/plugins/param_converter.rb:26:in `call'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/aws-sdk-core-3.219.0/lib/seahorse/client/plugins/request_callback.rb:89:in `call'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/aws-sdk-core-3.219.0/lib/aws-sdk-core/plugins/response_paging.rb:12:in `call'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/aws-sdk-core-3.219.0/lib/seahorse/client/plugins/response_target.rb:24:in `call'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/aws-sdk-core-3.219.0/lib/aws-sdk-core/plugins/telemetry.rb:39:in `block in call'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/aws-sdk-core-3.219.0/lib/aws-sdk-core/telemetry/no_op.rb:29:in `in_span'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/aws-sdk-core-3.219.0/lib/aws-sdk-core/plugins/telemetry.rb:53:in `span_wrapper'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/aws-sdk-core-3.219.0/lib/aws-sdk-core/plugins/telemetry.rb:39:in `call'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/aws-sdk-core-3.219.0/lib/seahorse/client/request.rb:72:in `send_request'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/aws-sdk-s3-1.182.0/lib/aws-sdk-s3/client.rb:6359:in `get_bucket_cors'
/var/www/discourse/lib/s3_helper.rb:401:in `fetch_bucket_cors_rules'
/var/www/discourse/lib/s3_helper.rb:168:in `ensure_cors!'
/var/www/discourse/lib/s3_cors_rulesets.rb:60:in `sync'
/var/www/discourse/lib/tasks/s3.rake:183:in `block in <main>'
/var/www/discourse/vendor/bundle/ruby/3.3.0/gems/rake-13.2.1/exe/rake:27:in `<top (required)>'
/usr/local/bin/bundle:25:in `load'
/usr/local/bin/bundle:25:in `<main>'
Tasks: TOP => s3:upload_assets => s3:ensure_cors_rules
(See full trace by running task with --trace)

Still unable to figure this out :frowning:

You do need environment vars, that’s why it’s documented that way at Configure an S3 compatible object storage provider for uploads and why the error message tells you to do that.

All of the S3 variables should be moved to hidden settings, as mostly no good can come from configuring them in the settings.

Sorry, and I forgot that you’re not using Docker. But yes, you still need to set them in the ENV variables. I do that in my development environment to restore databases from S3.

If you’re not doing this for a development environment, you’re very likely making a big mistakes.

@Eviepayne

Fixed it by doing the following - there were two errors.

First, I fixed the second error by doing the following:

rails c
Upload.find(386).destroy!
exit

This fixed the corrupt post(malformatted text or something)

Then the red errors on the screen were from using the random subdomain(provided by cloudflare) and uploading to that. I had to upload the files to the new domain(which includes my connected domain)

Using:

sudo -E -u discourse bundle exec rake s3:upload_assets

Then:

sudo -E -u discourse bundle exec rake uploads:migrate_to_s3

Then the forum properly loaded and right clicking and opening images in a new tab shows they are hosted on the R2. Then I did a backup.

Finally, I cleaned everything up using:

sudo -E -u discourse bundle exec rake uploads:clean_up

Which freed the respective storage space of the files(note I still have a local backup of both files(OS level) and discourse level before migration.

Now everything works perfectly!

3 Likes