0

I have created my first rpm package for a NodeJS app which is ran as a systemd service.

Since I do not want to package the node_modules folder with the rpm (AFAIK npm install is system/node version dependent so it could create some other issues?) I put this in the %post section of the spec file:

npm install --prefix /opt/%{modname} --production

The first problem with this is that the resulting node_modules folder is now owned by the root user, and not the app user.

The other problem is that uninstalling the rpm package from the system does not remove the node_modules directory and the resulting package-lock.json file.

I realize that I could resolve these two problems by adding this in the %postun and %post sections but this way seems very "hacky" to me:

%post
...
%__chown -R %{username}:%{username} /opt/%{modname}

%postun
...
%__rm -rf /opt/%{modname}

Is there a "proper" way to accomplish what I am trying to do?

Here is the entire spec file: https://gist.github.com/shunkica/d6064c1a743029ea75328114b6dc036d

HomeIsWhereThePcIs
  • 134
  • 1
  • 2
  • 8
  • IMO https://gist.github.com/shunkica/d6064c1a743029ea75328114b6dc036d#file-mynodeapp-spec-L90 will never pass any review. RPM packages should be built even offline. And... inline config, service file? Follow https://src.fedoraproject.org/ Fedora packagers. I would drop whole idea to create a rpm package. Just create a Dockerfile. – Jiri B Mar 17 '21 at 18:36
  • I am not really trying to get this to pass any reviews. I am just looking for pointers since this is my first rpmbuild and will be used for my servers only. Also, currently my generated rpm is 43 KB in size. A base nodejs:14 docker image is just shy of 1GB. – HomeIsWhereThePcIs Mar 18 '21 at 09:08

0 Answers0