heartsucker / node-deb Goto Github PK
View Code? Open in Web Editor NEWDebian packaging for Node.js projects
Home Page: https://www.npmjs.com/package/node-deb
License: MIT License
Debian packaging for Node.js projects
Home Page: https://www.npmjs.com/package/node-deb
License: MIT License
Currently they are in /etc/systemd.
I came at this from Ansible-land where everything has to be prefixed because of the global namespace. This isn't the case here, so deprecate the old variables and start using new ones.
I'm getting a spurios error printout whe installing my package using dpkg --install myapp_0.3.15_all.deb
See below
(Reading database ... 178426 files and directories currently installed.)
Preparing to unpack myapp_0.3.15_all.deb ...
Removed symlink /etc/systemd/system/multi-user.target.wants/myapp.service.
Failed to stop myapp.service\x7d.service: Unit myapp.service\x7d.service not loaded.
myapp wasn't even running!
Unpacking myapp (0.3.15) over (0.3.14) ...
Setting up myapp (0.3.15) ...
Directory 'node_modules' exists. Running 'npm rebuild'
> [email protected] install /usr/share/myapp/app/node_modules/websocket
> (node-gyp rebuild 2> builderror.log) || (exit 0)
sh: 1: cannot create builderror.log: Permission denied
[email protected] /usr/share/myapp/app/node_modules/minimist
[email protected] /usr/share/myapp/app/node_modules/websocket
[email protected] /usr/share/myapp/app/node_modules/websocket/node_modules/debug
[email protected] /usr/share/myapp/app/node_modules/websocket/node_modules/debug/node_modules/ms
[email protected] /usr/share/myapp/app/node_modules/websocket/node_modules/nan
[email protected] /usr/share/myapp/app/node_modules/websocket/node_modules/typedarray-to-buffer
[email protected] /usr/share/myapp/app/node_modules/websocket/node_modules/typedarray-to-buffer/node_modules/is-typedarray
[email protected] /usr/share/myapp/app/node_modules/websocket/node_modules/yaeti
[email protected] /usr/share/myapp/app/node_modules/node-deb
Created symlink from /etc/systemd/system/multi-user.target.wants/myapp.service to /etc/systemd/system/myapp.service.
Note the sh: 1: cannot create builderror.log: Permission denied
. What is it trying to build? Why can't it write to the log, etc. Everything seems to work fine in spite of this error message. Normally I try to build things so that no errors are emitted when everything works as expected. Please advice.
When fixing a bug I added a reproducer project and discovered that if the description is empty in the package.json file like so {"description": ""}
node-deb crashes. Not super-critial, and people should really have a description. The error message was pretty good also so it was easy to just add a description. 👍 for good error messages.
I would like to use the command line feature to configure my app like so
$myapp --update --config --file --or --whatever
It could be there is a different script in the package.json that will be run on cli or so.
The main reason is the use case where the user runs the cli without parameters. Here I would like to display program usage as per usual, but there is no way(?) to differ between service starting and starting from cli.
Suggestion from a coworker. Need to see if it makes sense.
@jeffhiltz, can you elaborate?
Hi,
while using your module i faced a complication that the package requires legacy nodejs installed in the system, while i prefer to build one from source, whenever i have to install the .deb file built from the module i have to use --ignore-depends flag to bypass dependency failure. Now this is fine when i am manually installing the package, this may not work if for instance i will add a repository to my package manager to provide update automatically, which i am planing to do. so maybe not include forced nodejs as package dependency and ask user to add nodejs if they want in their package.json file. if he feels its necessary.
`if [ -z "$package_dependencies" ]; then
package_dependencies=$(jq -r '.node_deb.dependencies' package.json)
if [[ "$package_dependencies" == 'null' ]]; then
package_dependencies="nodejs" #remove nodejs or have some alternate solution.
else
package_dependencies="nodejs, $package_dependencies" #remove nodejs or have some alternate solution.
fi
fi`
Maybe i am missing something, What do you think? Thanks You.
It looks like node-deb has a problem with '&'s in the start command, I wanted to redirect stderr in my start command and 2>&1
came out like this:
2>{{ node_deb_start_command }}1
It seems to include the template string where the '&' was.
Figure out why, write tests.
These aren't used anywhere and are actually broken in the systemd
template.
The package generation is very slow. The performance bottleneck is the loop which copies the files at
https://github.com/ehartsuyker/node-deb/blob/develop/node-deb#L451
For every file it spawns a new dirname process which takes a long time if you have 10k js files in your modules.
I don't understand why no cp -Rv
is used here....
Should probably just copy what was done in postinst
.
dpkg: warning: while removing simple, directory '/usr/share/simple/app' not empty so not removed
This is likely because of npm install
or other shenanigans. Force kill it on purge/removal.
Because a coworker "wants to know the program didn't hang when watching Jenkins output."
I have built a Node.js CLI packaged with node-deb
. It fails to create a tmp
folder because of permissions errors because it thinks that the current working directory is /usr/share/$app/app
instead of /home/$user
. I see why it is doing this but I can't figure out a workaround (aside from running with sudo
). Any help would be appreciated.
I am using var tmpDir = process.cwd() + '/tmp'
to set the tmp
directory location. I've also tried simply var tmpDir = 'tmp'
and var tmpDir = __dirname + '/tmpDir'
but it always comes out with this directory: /usr/share/$app/app
. Not /hone/$user/tmp
. It works just fine when installed normally with NPM.
write_md5sum() {
# Using $@ and not $1 because of files with whitespace
declare file="$@"
# Debian/Ubuntu
if hash md5sum 2>/dev/null; then
declare -r sum=$(md5sum "$file" | cut -d ' ' -f1)
# OSX
elif hash md5 2>/dev/null; then
# RIGHT HERE <----------------------
declare -r sum=$(md5 "$file" | awk -F '=' '{ printf $NF }' | tr -d ' ')
# Oh dear...
else
die 'Unable to find suitable md5 sum program'
fi
file=$(echo "$file" | sed -e "s/$(escape "$deb_dir")//" | sed -e 's:^\.::' -e 's:^/*::')
echo "$sum $file" >> "$deb_dir/DEBIAN/md5sums"
}
Per default, npm install
also installs the devDependencies. If you don't want to have these dependencies, you need to add the --production
switch.
The documentation explains this switch:
By default, npm install will install all modules listed as dependencies in package.json.
With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies.
For the differences between the dependencies and the dev dependencies see the explanation of package.json:
dependencies
Please do not put test harnesses or transpilers in your dependencies object. See devDependencies, below.devDependencies
If someone is planning on downloading and using your module in their program, then they probably don't want or need to download and build the external test or documentation framework that you use.
In this case, it's best to map these additional items in a devDependencies object.
These things will be installed when doing npm link or npm install from the root of a package, and can be managed like any other npm configuration param. See npm-config for more on the topic.
For build steps that are not platform-specific, such as compiling CoffeeScript or other languages to JavaScript, use the prepublish script to do this, and make the required package a devDependency.
Yup. Forgot that.
hi,
first of all thank you very much for working on this. i very much like the fact that i don’t have to get into debian packaging :).
i want to use node-deb with mirror-mirror. the debian-pkg branch contains the necessary changes. packaging itself works fine but npm rebuild --production
in postinst fails. it seems like npm is quite picky about the build environment and considering that i compile code from – somewhat – untrusted sources that might be a good thing.
unfortunately this means that my sqlite dependency will throw an exception when npm tries to build it.
this can easily be fixed by using --unsafe-perm
for npm install/rebuild but i’m not sure if this would be smart. anyway… i think this needs a solution. maybe it’s a good idea to chown the node_modules directory to the package user than executing rebuild/install and chown-ing it back.
i’ll try to submit a pull request if you favor any solution.
thanks!
For some reason e.g. istanbul code coverage tools gets included even though it's in the devDependencies
section of the package.json file. Not supported? Can I help out somehow?
I was lazy and used three VMs. This could have been done with two.
root@ops-jenkins1:~# node-deb --help
jq: package.json: No such file or directory
Usage: node-deb [opts] -- file1 file2 ...
...
Solution: move the $(jq ...)
commands below the option parsing.
Hello,
Ubuntu 15.x need the preset to activate the service on startup, so I have modified my postinst to match it:
elif hash systemctl 2> /dev/null; then
if [[ "$init_type" == 'auto' || "$init_type" == 'systemd' ]]; then
{
systemctl preset "$service_name.service" &&
systemctl enable "$service_name.service" &&
systemctl start "$service_name.service"
It's me the issue spammer again. Found another small issue
When sudo apt remove myapp
I get this consistently.
Failed to stop myapp.service\x7d.service: Unit myapp.service\x7d.service not loaded.
myapp wasn't even running!
The problem seems to be a spurious closing brace at prerm:12
Add a chdir to the binary directly. Possibly remove it from the upstart script.
Whilst dpkg-builddeb certainly works, you are doing an awful lot of stuff manually and not able to use the multitude of useful packaging utilities by not ultimately building the package with dpkg-buildpackage. Did you reject this approach?
The tests have gotten so unwieldy they are almost useless. vagrant
and the guest additions take forever.
Similarly, remove the actual node
package and create a fake .deb
that "provides" it.
I see that you moved the running of npm install
from package time to install time. (Thanks for the warnings - no time was wasted) I understand the reason this was done but it causes some new problems. Both options for npm install
are bad:
I haven't tried this, but I think the solution is to npm install
at packaging time and then just do an npm rebuild
at install time.
Hi, great package!
It would be really swell to have a simple way to chown all or some directories to the installing user so that tmp dirs etc can be setup within the package.
Regards,
Tarjei
This line change to working dir so adding files or dirs will not work in node-deb.
https://github.com/heartsucker/node-deb/blob/develop/templates/executable#L6
As services started from packages built by node-deb typically will run in production mode, the NODE_ENV=production
environment should also be set. This is used by e.g. express to suppress stacktraces and other security sensitive information.
It could either be set inside node_deb
in conjunction to computing the start_command
string or we could juse prepend NODE_ENV=production
in templates/executable
.
I use
"node_deb": { "entrypoints": { "daemon": "server.js " } }
server.js is not marked executable and so install fails.
As noted in #34
First off, thanks for a very helpful package. How do I install a file to e.g. /etc/myconfigfile.json
?
This might be too annoying with all the white space problems that exist. Needs investigation.
I've tried to setup my own debian package repository, but it seems there is an issue in size.
packages available here:
http://www.e-nef.com/domoticz/mdah/
$ du -s :
896 node-mydomoathome-0.0.31.deb
Installed-Size: 1164
error:
Les NOUVEAUX paquets suivants seront installés :
MyDomoAtHome
0 mis à jour, 1 nouvellement installés, 0 à enlever et 1 non mis à jour.
Il est nécessaire de prendre 913 ko dans les archives.
Après cette opération, 1 192 ko d'espace disque supplémentaires seront utilisés.
Réception de : 1 http://www.e-nef.com/domoticz/mdah/ MyDomoAtHome 0.0.31 [913 kB]
915 ko réceptionnés en 0s (1 277 ko/s)
E: Impossible de récupérer http://www.e-nef.com/domoticz/mdah/./node-mydomoathome-0.0.31.deb Taille incohérente
E: Impossible de récupérer certaines archives, peut-être devrez-vous lancer apt-get update ou essayer avec --fix-missing ?
Hello,
there is no npm install of dependencies upon startup, could you add this too ?
On linux it seems you need to use nodejs
everywhere, e.g. for the npm start
commands, etc, while on the mac node
is the program to call. What's the best way to handle this? Not code on mac? Create symlink on mac? Create symlink on linux? When to create it? I guess the best way is to create the symlink on Mac as that is dev only if you need deb-packages.... No real issue, just want your thoughts.
hi,
the systemd service file in /etc/systemd/… that node-deb creates seems to be executable. systemd ignores it but issues a warning like this
Configuration file /etc/systemd/system/mirror-mirror.service is marked executable. Please remove executable permission bits. Proceeding anyway.
the template itself is not executable so this may happen during packaging.
thanks
The variables in /etc/default/{{app}} didn't load when the upstart script execute, so i add the '-E' option to preserve it.
# start the process
script
. "/etc/default/uchuva"
exec sudo -E -u 'uchuva' 'bin/uchuva'
end script
Is there a better way to handle?
First reported by @empierre on issue #16. New ticket for organization.
also had issues of npm unpak issues, had to add this to correct the issue (clean cache and install as an unprivillegied user:
preinst:
npm cache clean
postint:
chown 'www-data:www-data' '/var/www/'
chown -R 'www-data:www-data' '/usr/share/mydomoathome'
npm_install() {
cd "/usr/share/$1/app"
if [ -e 'node_modules' ]; then
rm -rf 'node_modules'
fi
sudo -u www-data npm install --production
}
$ npm install -g node-deb
$ node-deb
Error: Cannot find module 'jq'
sudo npm install -g jq
recursive calls?
gyp WARN EACCES user "root" does not have permission to access the dev dir "/usr/lib/node_modules/jq/node_modules/contextify/.node-gyp/8.1.2"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/lib/node_modules/jq/node_modules/contextify/.node-gyp"
Need to be run twice to do the job
$ node-deb
Error: Cannot find module 'commander'
$ sudo npm install -g commander
$ node-deb
Error: Cannot find module 'async'
$ sudo npm install -g async
$ node-deb
Error: Cannot find module 'rimraf'
Error: Cannot find module 'winston'
Error: Cannot find module 'colors'
I have been shipping crap software lately. Let the FOSS gods save me from myself as I offer up my humble package to the pedestal of judgement that is TravisCI.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.