Search code examples
angularjsnginxrpmrpmbuildrpm-spec

Packing a static AngularJS website with any web server (e.g. nginx) into a single rpm package


And thank you very much to everyone who responded :)

I have no experience building rpm packages with such requirements

For several days now, I can’t defeat the task of packing a static website (AngularJS) by a web server in one rpm package. That it would be possible to install and receive a ready site on any rhel/centos server.

What did I do.

%{__mkdir} -p $RPM_BUILD_ROOT%{_datadir}/nginx
%{__mv} $RPM_BUILD_ROOT%{_sysconfdir}/nginx/html $RPM_BUILD_ROOT%{_datadir}/nginx/

I tried use

cp -r -f %{SOURCE14}/*.* $RPM_BUILD_ROOT%{_datadir}/nginx/html/

and

%{__install} -D -pm 755 %{SOURCE14}/*.* $RPM_BUILD_ROOT%{_datadir}/nginx/html/

But after rpmbuild -bb nginx.spec I didn`t have any changes in rpmbuild/BUILD/nginx-1.16.1/html/ folder, it contains only index.html and 50x.html

Pls help me with resolve this task. Where in the spec file I need add my website copy step? What the best way to modify Nginx default.conf? Because I need to add support AngularJS (add servername, HTTP to https rewrite allow some type of fonts and etc)


Solution

    1. You should create a tarball from your website folder. Here is relevant documentation https://rpm-packaging-guide.github.io/#preparing-source-code-for-packaging
    2. Then you need to alter %prep section. Which will be tricky if you want to keep the Source0 of original nginx. The documentation is here: https://rikers.org/rpmbook/node70.html#SECTION03541000000000000000 See section "Using %setup in a Multi-source Spec File"

    Instead of modifying existing nginx spec file, I would suggest you to create new spec file from scratch. Read through existing documentation like:

    Back to the core of your issue.

    When you do:

    Source14: website
    

    then rpmbuild will include only the directory - or should, I actually never tried it, every case and source code assume only one filename there. The wildcards do not work there. Therefore later cp -r -f %{SOURCE14}/*.* does not match anything, because it expands to cp -r -f website/*.* but the folder is actually empty.

    If you try to do:

    Source14: website/foo
    Source15: website/bar/foo
    

    then it will 1) be hell of manual work 2) not work, because SourceX takes only the basename and expect it to be present in rpmbuild/SOURCES/ - and obviously you will have collision sooner or later. Therefore you want to tarball your work.