Trying to setup Foreman dev environment from source

Hey everyone,

I am currently trying to setup a dev environment to try and work on some plugins.
Due to beeing on a corporate managed computer where I can’t do virtualization currently, I am unable to run forklift and so resorting to running from source on a RHEL8 virtual server. I am following the contribution guide, but have encountered some issues along the way.

  1. During bundle install and npm i, I saw a lot of EOL/deprecation warnings. I’ll assume you know about these and I can ignore them for now, but still wanted to mention it.
  2. npm install failed, from what I can tell it is failing to install node-sass. I get this error:
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/opt/lhm/foreman/node_modules/@theforeman/stories/node_modules/node-sass/.node-gyp'
gyp ERR! System Linux 4.18.0-372.13.1.el8_6.x86_64
gyp ERR! command "/usr/bin/node" "/opt/lhm/foreman/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /opt/lhm/foreman/node_modules/@theforeman/stories/node_modules/node-sass
gyp ERR! node -v v14.18.2
gyp ERR! node-gyp -v v7.1.2
gyp ERR! not ok

I am not sure if this is an error on my end or with the upstream library.

  1. Probably due to the above error in npm install, foreman fails to start.
09:48:41 webpack.1 | ERROR in ./webpack/assets/javascripts/react_app/components/common/ErrorBoundary/index.scss
09:48:41 webpack.1 | Module build failed: ModuleBuildError: Module build failed: Error: ENOENT: no such file or directory, scandir '/opt/lhm/foreman/node_modules/node-sass/vendor'
<stacktrace stripped>

Can someone confirm if this is in fact the current state of running from source or if it’s a problem on my end? Any pointers on getting this to run?

Regards

I’d recommend installing node version manager (nvm) and then run ‘nvm use 12’. That’s what I’ve had to do on my dev box…

I think we are trying to move soon to node 14, though. not sure of the status there.

The contribution guide explicitly tells you to enable nodejs:14 module stream, so thats what I did.
I switched to the nodejs:12 module stream just to test, but that got me the same result:

gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/opt/lhm/foreman/node_modules/@theforeman/stories/node_modules/node-sass/.node-gyp'
gyp ERR! System Linux 4.18.0-372.13.1.el8_6.x86_64
gyp ERR! command "/usr/bin/node" "/opt/lhm/foreman/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /opt/lhm/foreman/node_modules/@theforeman/stories/node_modules/node-sass
gyp ERR! node -v v12.22.12
gyp ERR! node-gyp -v v7.1.2
gyp ERR! not ok

I don’t know if using nvm would make any difference, but since nodejs12 is EOL and 12.22.12 was the last version released, I assume that should give the same results.

There are new developer docs in github repo, they are for Fedora setup mainly but maybe you’ll find some help there.

The contribution guide explicitly tells you to enable nodejs:14 module stream, so thats what I did.

For me nodejs:12 has some weird behavior, I’m running dev setup on 14 without any problems.

gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir ‘/opt/lhm/foreman/node_modules/@theforeman/stories/node_modules/node-sass/.node-gyp’

looks like you don’t have permissions for that folder

Turns out this error was caused by me trying to install as root.
I managed to get npm to install all libraries as non-priviledged user, and I managed to get foreman to start.
Now I am having trouble connecting, though. The default config seems to only allow connections from localhost and binds the application to 127.0.0.1. I managed to get the frontend service to bind to 0.0.0.0 with bundle exec rails s -b 0.0.0.0 -p 3000 as mentioned in the github repo, but I cannot find a way to do this for webpack. Are there any options or some config file I can edit to bind webpack (or everything) to 0.0.0.0?

It’s described in developer docs

It probably is, but I am completly unable to find it.
As mentioned, I found a way to make the application accept connections from host other than localhost, but I can not find anything about the webpack stuff. Maybe I am missing something essential here or I am misunderstanding the concept or what’s supposed to happen, but when I run the application like described in the docs I either can’t access the app at all (first option starting everything in a single command) or I can reach the application server, but only get a blank screen and my browser console shows a lot of “failed to load script at host.example.com:3808/webpack/xyz.js” errors (second scenario with application and webpack started in seperate processes).
By now, I am starting to think about giving up, especially since the most urgent things we need have thankfully been addressed by other people around here in the plugins I intended to do some work on.

Hmm, I’m running my foreman on foreman.network23.loc, this is my configuration:

# config/settings.yaml

:domain: 'network23.loc'
:fqdn: 'foreman.network23.loc'

Rails:

bundle exec rails s -b 0.0.0.0 -p 3000

And webpack running with following command:

env NODE_ENV=development NOTIFICATIONS_POLLING=99999999 ./node_modules/.bin/webpack-dev-server-without-h2 --config ./config/webpack.config.js --allowed-hosts foreman.network23.loc

Your post had the hint I was looking for.
I managed to get it to work by changing line 53 of webpack.config.js to read:
host: args.host || process.env.BIND || '0.0.0.0',

This seems to solve my problems with the setup, since both my local client as well as Foreman’s internal processes can now reach the webpack resources when starting the processes with your commands.

Thanks a lot for the help :slight_smile:

2 Likes