Error: "Could not locate Gemfile"


(Jonathan Juan) #1

I’m trying to run bundle exec RAILS_ENV=production rake assets:precompile, but it gives me a Could not locate Gemfile error. I’ve looked at other topics and the solution seems to be to cd to the directory that Discourse was installed into, but I am in /var/discourse and I’m still getting this error.

I’m running a Docker install on Digital Ocean, for the record.


(Dave McClure) #2

You need to run that from inside the docker container.

Try:

launcher enter app


(Jonathan Juan) #3

I used ./launcher enter app, and tried it again, but I got the same error.


(Dave McClure) #4

Sorry, missed a step. After entering the container you need to get into the right directory:

$ cd /var/www/discourse

then it should work.


(Jonathan Juan) #5

Thanks! That solved my previous problem…but I’m now having another issue with it returning bundler: command not found: RAILS_ENV=production Install missing bundles with 'bundle install'


(Dave McClure) #6

Try bundle install first.

And try your command this way instead:

RAILS_ENV=production bundle exec rake assets:precompile

Also, I never asked. What are you trying to accomplish? Did you install a custom plugin or something?


(Jonathan Juan) #7

Yep, custom plugins. I was just having some issues with that. It looks like this worked, so thanks so much for your help!


(Jens Maier) #8

Be aware that when you use ./launcher enter app, you enter the container as the root user. Any gems you install and any files you create in the Discourse app will be owned by root and you may run into issues with automated upgrades through the docker manager plugin later down the line.

As a rule of thumb, you should never run any rake or rails command as root. If you want to run these commands interactively, switch to the unprivileged user first with su - discourse, or type su -c '<command>' discourse to run a single command (be sure to remove the angle brackets but leave the single quotes).


(Sam Saffron) #9

FYI, we have shims in place for rails and rake (but clearly not for bundle):


(Jonathan Juan) #10

As someone who doesn’t know too much about terminology, does this mean that the steps elberet gave me should still be followed, or does Discourse have stuff coded to make sure what he says doesn’t happen?


(Jens Maier) #11

Not working as root is good advice for any Linux admin under any circumstances. :smiley:

You’ll do yourself and your system a huge favour if you adopt this as a general practice – Linux assumes that if you’re root, you know exactly what you’re doing and will do what you tell it to do without question, much like a literal Genie. A single space (rm -rf ./ tmp instead of rm -rf ./tmp) can mean the difference between removing a few unimportant files and potentially turning your server into a fancy paperweight. :wink:


(Jonathan Juan) #12

It worked beforehand, but now when I try to enter su - discourse it gives me the error No passwd entry for user 'discourse'.


(Jens Maier) #13

You should run that command inside the container…

  1. While on the host, do become root (because nsenter requires privileges).
  2. Run ./launcher enter app. This brings you into the container and you’ll still be root.
  3. Become the unprivileged Discourse user with su - discourse.
  4. Run whatever commands you wish to run in your Discourse forum.
  5. Type exit once to drop back to root inside the container, then exit again to drop out of the container.