Basic Guide for Debian Packaging (NodeJS)
Basic Guide for Debian Packaging (NodeJS)
The demand for application software is high. Debian comes with over 51,000 packages — for free! Check out this basic guide for Debian packaging. (NodeJS)
Join the DZone community and get the full member experience.Join For Free
What Is Debian?
The need for people is application software: programs to help them get what they want to do done, from editing documents to running a business to playing games to writing more software. Debian comes with over 51,000 packages (precompiled software that is bundled up in a nice format for easy installation on your machine), a package manager (APT), and other utilities that make it possible to manage thousands of packages on thousands of computers as easily as installing a single application. All of it is free.
It’s like a tower. At the base is the kernel. On top of that are all the basic tools. Next, is all the software that you run on the computer. At the top of the tower is Debian carefully organizing and fitting everything so it all works together.
What Is an Operating System?
An operating system is the set of basic programs and utilities that make your computer run. At the core of an operating system is the kernel. The kernel is the most fundamental program on the computer and does all the basic housekeeping and lets you start other programs.
What Is Debian Packaging?
Ever done Sudo apt install (anything)? Wondered how apt install works and what file it fetches and how the file gets auto-installed? So, here comes the Debian Packaging task. Packaging aims to allow the automation of installing, upgrading, configuring, and consistently removing computer programs for Debian.
To be simple, its like making .deb of any software or module like in windows we have .exe file
By doing Debian packaging we make Debian packages, which is a collection of files that allow for applications or libraries to be distributed via the Debian package management system.
Enough of this knowledge, get me to the coding part, and let's do the packaging.
Let's Start With Prerequisites
First, we need a Debian SID environment. Oops, I have an ubuntu/arch/Gentoo/mac machine and installing another OS, nah, not ready for a new OS - if that's what you are thinking now, don’t worry. We have Docker, lxc or virtual machine for you.
See instructions given below to setup Debian Sid.
- LXC - https://wiki.debian.org/Packaging/Pre-Requisites#LXC
- Docker - https://wiki.debian.org/Packaging/Pre-Requisites#Docker
- Virtual Machine - https://wiki.debian.org/Packaging/Pre-Requisites#Virtual_Machine
I prefer Docker, and when I started with Debian packaging, I started with Docker container.
Tips for Linux users, who use apt package manager, to install docker is now really easy, just do “sudo apt install docker.io”
You can go with the above setup link or the way I installed it.
My way of installation of Docker SID environment:
|Work to be done||Code|
|Pull Debian Sid image from docker hub using the following command||docker pull Debian:sid|
|Create a container with it and start bash on it||docker run - -privileged - -name “sid” -it debian:sid /bin/bash|
|Update and upgrade to latest versions of packages||apt-get update && apt-get upgrade|
Exit after your work is done.
If you need to connect to it later, use the following commands which will take you to the bash prompt.
“sudo docker start sid && sudo docker attach sid”
Now, we need tools to work with:
Install packaging tools inside the container
# apt-get install dh-make OR
# apt-get install gem2deb OR
# apt-get install npm2deb as required.
# apt-get install git-buildpackage sbuild dh-buildinfo quilt lintian these packages must be installed.
For Nodejs modules, use
npm2deb; for ruby gems, use
gem2deb; for go packages, use
dh-make-golang. If there is no tool specific to a language,
dh-make can be used as a generic tool for any language.
Still Having an Issue With Set-Up?
Join our real-time chat group using one of the 4 options and say hi. If you have difficulty with pre-requisites please ask here or on chat rooms.
- Matrix: #debian-browserify:diasp.in
- IRC: #debian-browserify on irc.oftc.net
- Telegram: https://t.me/debian_browserify
http://webchat.oftc.net/?channels=debian-browserify&uio=MT11bmRlZmluZWQb1 to join the IRC room
Okay to start with packaging, start with nodejs packages and understand the workflow and then you can shift with other language modules and then to higher multi-language modules. - Manas Kashyap
Lets, do it then!
Install a text editor (I like vim, for installation run sudo apt install vim ) and update .bashrc of docker container with the following environment variables
- Command ls -la shows the hidden .bashrc file, to edit with vim do vim .bashrc and add the above and the very end, update your current environment by running
- vim tips i – insert mode to enter text , :wq – write and exit ,:q!– exit without saving.
- Setup username and email address for git.
- git config –global user.name “Your name” git config –global user.email firstname.lastname@example.org
1) Check dependency use npm2deb depends
- Module qw has no dependencies. Here qw has no dependencies.
2) Search for existing work using npm2deb search
- Looking for similar package:
- Looking for existing repositories:
- Looking for wnpp bugs:
- Output shows no existing work and one can start work on it
3) Preview more info using npm2deb view
- Version: 1.0.1
- Description: None
- Homepage: https://github.com/iarna/node-qw#readme
- License: ISC
- Debian: None (None)
- License is automatically recognized as BSD, if this does not happen, please pass –upstream-license option during creation to set a correct license.
4) Automate debian package creation using npm2deb create.
- npm2deb fails to do it completely, our job is to fix those error which is shown by the prefix FIX_ME
- ‘You may want fix first these issues:
- qw/node-qw-1.0.1/debian/control:Description: FIX_ME write the Debian package description
- qw/node-qw_itp.mail:Subject: ITP: node-qw – FIX_ME write the Debian package description
- ls command shows npm2deb created a dir called qw ,
- change directory to qw, It has the following contents
- $ ls
- $ cd qw/
- $ ls
- node-qw node-qw-1.0.1.tar.gz node-qw_1.0.1-1.dsc qw_1.0.1- 1_amd64.buildinfo node-qw_1.0.1.orig.tar.gz node-qw-1.0.1 node-qw_1.0.1-1.debian.tar.xz node-qw_1.0.1-1_all.deb node- qw_1.0.1-1_amd64.changes node-qw_itp.mail
- node-qw is a temporary folder created by npm2deb its better to delete it to avoid confusion later
- $ rm -rf node-qw
5) Import package to git
- Now, we get a new dir called node-qw which is git tracked, cd into the newly created dir node-qw and see git branch and git tag
- $ git branch
- $ git tag
- Delete the debian tag by running git tag -d debian/1.0.1-1
6) File ITPFiling itp is a method by which we take ownership of the module by mailing to email@example.com, in return, we get a bug number, a sample mailing template is created by npm2deb for our use
- $ cat node-qw_itp.mail (to view the template )
- update the template by fixing the error with the prefix FIX_ME:
- sample itp is attached below https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=881423
7) Make package lintian clean
- /qw/node-qw$ ls
- LICENSE README.md debian package.json qw.js test
- lintian points out the errors we need to fix
- I: node-qw source: file-contains-fixme-placeholder debian/control:20 FIX_ME
- W: node-qw source: out-of-date-standards-version 4.1.1 (current is 4.2.1)
- places where errors were fixed regarding this module
- make sure to commit your changes as they are fixed by using the git command
- git commit -m “ commnet description” path/of/fixed/file
- for reference -https://salsa.debianorg/js-team/node-qw.git/tree/
8) Enable tests if present any, find the test command from package.json
- add the test command under override_dh_auto_test from debian/rules
- add the test framework (mocha, node-tape, etc) as a build dependency in
- debhelper (>= 9)
- , dh-buildinfo, nodejs
- , node-tap
- Standards-Version: 4.1.2
- add a Test-Command section to debian/tests/control
- reference link ;-https://salsa.debian.org/js-team/node-qw.git/tree/debian
- run dpkg-buildpackage and check if the tests ran successfully and change debian/changelog to release by running dch -r.
9) upload to https://salsa.debian.org ( as the team maintains it)
- create a new project as per your node-module name
- git remote add origin firstname.lastname@example.org:username/node-module-name.git (eg link)
- git push -u origin –all –follow-tags
- this is a temporary repo once you mature, will get official repo access
10) Clean build with sbuild
- … logout and re-login or use
newgrp sbuildin your current shell$ sudo sbuild-createchroot –include=eatmydata,ccache,gnupg unstable
- /srv/chroot/unstable-amd64-sbuild http://deb.debian.org/debian
11)Install deb package
Opinions expressed by DZone contributors are their own.