Closed joelahoover closed 7 years ago
Have you tried setting the NPM_RUN
environment variable to "build"?
If npm
doesn't provide the functionality that you need, you can always use it to run a Makefile
, or a bash or ruby or python script, or anything else :+1:
If I understand correctly, NPM_RUN
defines what is run to start the application, so if we set that to "build", then we would end up running npm run build
every time we deploy the image. But since the build step only needs to happen once, it would be nice if we could just commit the changes into the image itself.
I noticed in the linked article that one of the example start script is npm run build && node server.js
. I am rather new to the nodejs scene so I am interested: is this a standard way of handling cases where you need to build, even though it causes the build to run every time the application is started?
Would renaming your package.json's build
entry to postinstall
do the job? See https://docs.npmjs.com/misc/scripts
I think there may be a way to provide your own s2i assemble script (in your repo), allowing for additional customization (without needing to patch the base image)
Let me know if the postinstall
hook works for you
I've just tested with the postinstall script set to "npm run build", and the result worked flawlessly. This is what I am going to use in my project going forward.
Also (for completeness/future visitors), it seems you are correct in that it is possible to override the s2i assemble script by simply placing it in .s2i/bin
in the applications code (see this article), so even if I wanted to separate the build stage as in this pull request, it could be done purely in the application repository.
Thanks for your help!
For many use cases, it is convenient (and somethimes necessary) to have a script called at build time. We should do something in the assemble script to support these cases. As such, I have added a few lines that detects if the package defines a build script, and will call it if it does.