Closed johannesschobel closed 1 year ago
Hi,
Technically the JS environment has access to the Rails environment, if you need to run 1 off JS commands through Rails you can do it through that container. For example that's how the test suite is invoked since it depends on assets.
If your main Rails runtime needs full access to Node outside of the Rails console (such as when folks are hitting various URLs or Sidekiq) then you'll probably want to remove the app
stage from the Dockerfile
and use the assets
stage for the web
, worker
and cable
Docker Compose services.
Then the entire Node environment will be available to everything, at the cost of your Docker image being a lot larger but if you need the environment then there's not much you can do here.
I'd suggest:
app
stage in the Dockerfileassets
stage to app
in the Dockerfiledocker-compose.yml
and .env
file to reflect the above changesDear @nickjj ,
thank you very much for helping me out. I will try your suggestion and give feedback! All the best, Johannes
Dear @nickjj and everyone that may also stumble upon this issue ;) I just got it to work (thanks a lot @nickjj !). This is, what i did:
1) in your .yarnrc
file, remove the line with --modules-folder
2) in your app/config/initializers/assets.rb
comment out the line with Rails.application.config.assets.path
3) in your docker-compose.yml
file, delete the x-assets
part and the js
and css
services
4) compare the app
and assets
build phases in your Dockerfile
and copy a few parts from the app
to the assets
part. Then remove the app
part and rename the assets
to app
(as @nickjj described above). Basically you want to copy the cmd
part from the app
to the assets
in order to start the actual rails server
5) in the bin/docker-entrypoint-web
file, comment out the cp -r /public /app
part, as your public files are now directly within the app
directory of the docker container.
Happy coding ;)
All the best, Johannes
No problem, happy to hear it helped. Thanks for listing the steps.
Dear @nickjj ,
first of all, i would like to thank you for putting together this awesome repository and project. This is a really cool starter for new rails projects.
I have started to work on a rails application and have installed
devise
for my user management. In order to send mails, i would like to usemjml
(https://mjml.io/) andmjml-rails
(https://github.com/sighmon/mjml-rails) respectively. However,mjml-rails
requires you to also install the npm packagemjml
(i.e.,yarn install mjml
)As far as i have understood,
mjml-rails
calls themjml binary
from themjml node package
in order to transform the<mjml-*>
tags to proper valid and responsive html tags .In the
docker-compose
setup of this project, however, alljs-bundling
stuff works within theNAME-js
container. The actualweb
container does not have anode-modules
folder. Hence, themjml binary
is missing.How can i get this to work? This is not only the problem with
mjml
, but rather with all node packages that are called via the console, right? I know, that the basic idea is to have all the javascript-stuff built within a dedicated container and then "move the final product" to the application container. But in this case (i.e., requiring a dedicatednode binary
that is invoked via the console) this does not work. Or am i missing something?Thank you very much for your time and effort in helping me with this issue. All the best, Johannes