Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NODE_ENV not working for different build environments #244

Open
droidscout opened this issue Jul 2, 2020 · 3 comments
Open

NODE_ENV not working for different build environments #244

droidscout opened this issue Jul 2, 2020 · 3 comments

Comments

@droidscout
Copy link

Hi there!

I've noticed that setting the NODE_ENV variable to something other than "production" doesn't takes the nodejs runtime mode into account.

My package.json has the following scripts added:
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"production": "ng build --configuration=production",
"integration": "ng build --configuration=integration",
"development": "ng build --configuration=dev",
"run_dev": "ng serve --configuration=dev"
}

When passing either NODE_ENV=integration or event NODE_ENV=development it just downloads the package dependencies but never builds the source.

Is this an intended use case for the sources not being built? If that's the case, then s2i build would only create a container with the source code and it's dependencies.

Stay safe and all the best,
Ralph

@droidscout
Copy link
Author

Code snippet from 12/s2i/bin/assemble:

if [ "$NODE_ENV" != "production" ]; then
	echo "---> Building your Node application from source"
	npm install

else

	echo "---> Installing all dependencies"
	NODE_ENV=development npm install

	#do not fail when there is no build script
	echo "---> Building in production mode"
	npm run build --if-present

	echo "---> Pruning the development dependencies"
	npm prune

	# Clear the npm's cache and tmp directories only if they are not a docker volumes
	NPM_CACHE=$(npm config get cache)
	if ! mountpoint $NPM_CACHE; then
		echo "---> Cleaning the npm cache $NPM_CACHE"
		#As of npm@5 even the 'npm cache clean --force' does not fully remove the cache directory
		# instead of $NPM_CACHE* use $NPM_CACHE/*.
		# We do not want to delete .npmrc file.
		rm -rf "${NPM_CACHE:?}/"
	fi
	NPM_TMP=$(npm config get tmp)
	if ! mountpoint $NPM_TMP; then
		echo "---> Cleaning the $NPM_TMP/npm-*"
		rm -rf $NPM_TMP/npm-*
	fi

fi

Fix source directory permissions

fix-permissions ./

@ryanj
Copy link
Contributor

ryanj commented May 14, 2021

This definitely looks like a bug to me: https://github.com/sclorg/s2i-nodejs-container/blob/master/14/s2i/bin/assemble#L89

if [ "$NODE_ENV" != "production" ]; then your NODE_ENV settings end up getting overwritten with "development"

@stankurek
Copy link

stankurek commented Apr 11, 2022

@ryanj exactly. I also found it. I guess it's kind of a hack to install both dependencies and dev dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants