Skip to content

Commit

Permalink
Merge pull request #1016 from NagiosEnterprises/dev-v3
Browse files Browse the repository at this point in the history
Merge NCPA v3 into master
  • Loading branch information
ne-bbahn committed Nov 15, 2023
2 parents a424014 + 00d2048 commit dce4c60
Show file tree
Hide file tree
Showing 127 changed files with 5,307 additions and 3,987 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/build.yml
@@ -0,0 +1,44 @@
name: Build

on:
push:
branches: [ 'dev-v3' ]

jobs:

build:

runs-on: ${{ matrix.os }}
strategy:
matrix:
# os: [ubuntu-latest, macos-latest, windows-latest]
# os: [ubuntu-latest, macos-latest]
# os: [ubuntu-20.04]
os: [macos-latest]

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.11'
- name: Check system platform
run: python -c "import sys; print(sys.platform)"
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade -r build/resources/require.txt
- name: Install OS-specific dependencies
if: runner.os == 'Windows'
run: python -m pip install pypiwin32 cx_Logging
- name: Build the NCPA binaries
run: |
python setup.py build_exe
pwd
../build/build_github.sh
working-directory: agent
- name: Upload ${{ matrix.os }} artifact
uses: actions/upload-artifact@v2
with:
name: NCPA-3.0.0-${{ matrix.os }}
path: build/ncpa_3.0.0-*.*
25 changes: 25 additions & 0 deletions .github/workflows/tests.yml
@@ -0,0 +1,25 @@
name: Tests

on:
push:
branches: [ 'dev-v3' ]

jobs:

test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pytest
python -m pip install --upgrade -r build/resources/require.txt
- name: Run Tests
run: pytest
28 changes: 24 additions & 4 deletions .gitignore
Expand Up @@ -6,15 +6,35 @@
*.cfg
.idea/
.vagrant
.coverage
.cover
.cache/
agent/build/*
.vscode/
docs/_build
*.exe
agent/plugins/*
ncpa.db
prereqs.installed
.python-version
.DS_Store
launch.json

agent/build
agent/plugins/*
# agent/var/log/*
agent/var/run/*.pid

build/resources/*.tgz
build/resources/Python*/*
build/resources/openssl/*
build/bin
build/include
build/lib
build/ncpa.spec
build/ncpa
build/ncpa-3*/
build/ncpa-3*/
build/NCPA-INSTALL-*/
build/*.deb
build/*.rpm
build/*.dmg
build/NCPA-*
build/share
build/NCPA-INSTALL-*/*
4 changes: 0 additions & 4 deletions .travis.yml

This file was deleted.

235 changes: 38 additions & 197 deletions BUILDING.rst
Expand Up @@ -10,6 +10,9 @@ This document contains instructions for:

* `Building on MacOS <https://github.com/NagiosEnterprises/ncpa/blob/master/BUILDING.rst#building-on-macos>`_

*WARNING*: DO THIS ON A DEDICATED VM OR A NON-PRODUCTION SYSTEM!

THE BUILD SCRIPT WILL MAKE CHANGES TO THE SYSTEM THAT MAY BE INCOMPATIBLE WITH OTHER SOFTWARE

Building on Windows
===================
Expand All @@ -19,237 +22,75 @@ must be executed by cmd.exe. For this reason, any Windows commands
listed in this document will be written with cmd.exe compatibility
in mind.*

**Prerequisites for Windows** (Installing some of these prerequisites requires admin rights)
-------------------------

* `Git for Windows <https://git-scm.com/download/win>`_
* Python 2.7.16 (32-Bit) (`Download <https://www.python.org/downloads/release/python-2716/>`_)
* `OpenSSL for Windows (32-bit) <https://slproweb.com/download/Win32OpenSSL-1_1_1d.exe>`_
* `Microsoft Visual C++ Compiler for Python 2.7 <https://web.archive.org/web/20160309215513/https://www.microsoft.com/en-us/download/details.aspx?id=44266>`_
* `Microsoft Visual C++ 2010 runtime (32-bit) <https://download.microsoft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC/vcredist_x64.exe>`_
* `NSIS 3 <http://nsis.sourceforge.net/Download>`_

**Python Packages**

* pip (installed by default in Python 2.7 for Windows)
* cx_Freeze (patched)
* cx_Logging (http://cx-logging.sourceforge.net/)
* pywin32 (https://github.com/mhammond/pywin32/releases/download/b228/pywin32-228.win32-py2.7.exe)

(pywin32 provides a bunch OS checking stuff that is not available via pip.)

There are more Python packages that need to be installed too but they are installed when you run the build.sh script for the first time. A full list of required packages is available in *ncpa/build/resources/requires.txt*.

Configure the Windows Build Environment
-------------------------------

Install Prerequisites
~~~~~~~~~~~~~~~~~~~~~

* Python

1. Download and install Python 2.7.16. (`see prerequisites <https://github.com/NagiosEnterprises/ncpa/blob/master/BUILDING.rst#prerequisites>`_)
2. Execute the installer as usual. It's important that the
installation path is not changed from the default of
C:\\python27 as cx_Freeze can have difficulty finding
Python resources if it's installed at a custom path.

* OpenSSL

1. Download and install the OpenSSL package. (`see prerequisites <https://github.com/NagiosEnterprises/ncpa/blob/master/BUILDING.rst#prerequisites>`_)
2. Be sure to make a not of the installation directory while installing.

* Microsoft Visual C++ Compiler for Python 2.7

1. Download and run the installer. (`see prerequisites <https://github.com/NagiosEnterprises/ncpa/blob/master/BUILDING.rst#prerequisites>`_)

Running the installer without administrator privileges will
cause the files to be installed to::

%LOCALAPPDATA%\Programs\Common\Microsoft\Visual C++ for Python\9.0

* Microsoft Visual C++ 2010 runtime (32-bit)

1. Download and run the installer. (`see prerequisites <https://github.com/NagiosEnterprises/ncpa/blob/master/BUILDING.rst#prerequisites>`_)

* NSIS

1. Download and run the installer. (`see prerequisites <https://github.com/NagiosEnterprises/ncpa/blob/master/BUILDING.rst#prerequisites>`_)

* pywin32

1. Download and run the installer (`see prerequisites <https://github.com/NagiosEnterprises/ncpa/blob/master/BUILDING.rst#prerequisites>`_)

If the installer says python isn't in the registry, then the installer doesn't match your python (which should be 2.7.16 32-bit).

* pip

* Pip is installed by default in Python 2.7.16 but should be updated before continuing::

"%pydir%" -m pip install --upgrade pip

Set Environment Variables
~~~~~~~~~~~~~~~~~~~~~~~~~
Two variables must be set for the win_build_setup.bat script to run properly:

* **pydir**: The root directory of your Python installation.

This should be:

C:\Python27

* **openssldir**: The root directory of your OpenSSL installation.

This should be:

C:\Program Files (x86)\OpenSSL-Win32

Set these variables by entering::

set pydir=C:\Python27
set openssldir=C:\Program Files (x86)\OpenSSL-Win32

Install the Last Modules
~~~~~~~~~~~~~~~~~~~~~~~~
*Note: The current Windows build should be run on a Windows machine without Python installed.*

* Install the full list of python modules
Install the Prerequisites/Build NCPA
------------------------------------

"%pydir%\python" -m pip install --upgrade -r build/resources/require.txt
From a command prompt with Administrative priveleges run::

* cx_Logging (http://cx-logging.sourceforge.net/)
cd /path/to/ncpa/build/
build_windows.bat

* Install the python 2.7 version of cx_Logging for Windows via the .msi
This will use Chocolatey to install various prerequisites for building NCPA and then build NCPA. If you have not yet built NCPA 3 on your machine, the script will likely tell you that a reboot is required/pending. This means that you need to restart your machine and then rerun the script and it will continue the installation/build processes. This may happen several times during the installation process.

* cx_Freeze (patched)

* Install cx_Freeze via pip:

pip install cx_Freeze==4.3.4

* Then, copy our patch into the package:

ncpa\build\resources\cx_Freeze-4.3.4.tar.gz
copy "ncpa\build\resources\cx_Freeze-4.3.4.tar\cx_Freeze-4.3.4\cx_Freeze\freezer.py" C:\Python27\Lib\site-packages\cx_Freeze\freezer.py

Build NCPA
~~~~~~~~~~

Run the build script::

"%pydir%\python" build\build_windows.py
This will create a file called ``ncpa-<version>.exe`` in the ``build`` directory.
This is the installer for NCPA and can be used to install NCPA on a Windows system.


Building on Linux
=================

Building on CentOS 7 is the easiest way to get a working package for all Linux distributions except the SuSE variants which seem to build most easily on openSuSE 15 Leap, and SLES 15. For Ubuntu/Debian, you will need copy the generated .rpm to an Ubuntu system (20.04 recommended) with alien installed and run alien to create a .deb file that will work on all of the supported distributions.

That said, in most cases (CentOS 9 being a notable exception), building on the distribution that is targeted, e.g. building on Ubuntu 20.04 to deploy on Ubuntu 20.04, will work, but the resulting package will not be as portable.

The CentOS 7 build flow (for all non-SuSE linux)
-------------------------------------------------
**Clone the git repo on a CentOS 7 machine** (*It must have wget and git installed*)::

cd ~
git clone https://github.com/NagiosEnterprises/ncpa

**Select the correct .spec file**::

cd ~/ncpa/build/linux

For a package targeting CentOS 9::

cp ncpa.spec el7-ncpa.spec
cp el9-ncpa.spec ncpa.spec

For other non-SuSE distributions, use the existing ncpa.spec file

**Run build script to install the requirements and build an rpm**::

cd ~/ncpa/build
./build.sh
Building on CentOS 7 is the easiest way to get a working package for all Linux distributions. When you build on CentOS 7, both a .deb as well as an .rpm package are built.

**Creating a package for Ubuntu or Debian**
(*Note: this step not necessary if building on Ubuntu*)
In most cases, building on the distribution that is targeted, e.g. building on Ubuntu 20.04 to deploy on Ubuntu 20.04, will work, but the resulting package will not be as portable.

Copy the resulting ~/ncpa/build/ncpa-2.x.x-1.elx.x86_64.rpm to an Ubuntu 20.04 server** with alien installed (`apt install alien`) and generate a .deb file::
To start, clone the repository in your directory::

`alien -c -k -v ./ncpa-2.x.x-1.elx.x86_64.rpm > build.log`
cd ~
git clone https://github.com/NagiosEnterprises/ncpa

** *Ubuntu 20.04 generates a .deb that will run on the most targets, but other distributions may work for your specific case.*
Now run the setup scripts to install the requirements::

The SuSE build flows (OpenSuSE and SLES):
------------------------------------------------
cd ncpa/build
./build.sh

**OpenSuSE**

Building on OpenSuSE is the same process as build on CentOS 7, except you do it on an OpenSuSE machine, and you use a different .spec file.

**Clone the git repo on an OpenSuSE Leap 15 machine** (*It must have wget and git installed*)::

cd ~
git clone https://github.com/NagiosEnterprises/ncpa

**Select the correct .spec file**::

cd ~/ncpa/build/linux
cp ncpa.spec el7-ncpa.spec
cp suse-ncpa.spec ncpa.spec

Note: this will name your rpm with "sle15" in the release segment. If you want it to be "os15", edit line 3 in ncpa.spec accordingly.

**Run build script to install the requirements and build an rpm**::

cd ~/ncpa/build
./build.sh


**SLES**

On SLES 15, the build script fails because rpm-build is no longer available in the zypper repositories. Hence, this process is not really recommended, but it is provided for those useers for whom building on older versions of SLES is necessary.

**Clone the repo as for OpenSuSE above.**

**Edit linux/setup.sh and remove "rpm-build" from line 49**

**Run build script to install the requirements and build an archive**

The script will die when it tries to invoke rpm-build leaving a compressed tarball in the build directory, e.g., ncpa-2.4.1.tar.gz.

**Copy this .gz into the build dir of the ncpa repo on another distrbution that that has rpm-build available, .e.g, a CentOS 7 VM.**

**Select the proper .spec file, as for OpenSuSE above.**

**From the build directory, run linux/package.sh**

An rpm, e.g., ncpa-2.4.1-sle15.x86_64.rpm, will be generated.
Follow the prompts to setup the system. When running the build.sh script it will setup
the system and build the ncpa binary.


**Install on the target Linux server**
--------------------------------

Copy the resulting ~/ncpa/build/ncpa-2.x.x-1.elx.x86_64.rpm or ncpa_2.4.1-1.el7_amd64.deb to the desired server and install using the appropriate package system:
Copy the resulting ~/ncpa/build/ncpa-3.0.0-latest.x86_64.rpm or ncpa_3.0.0-latest_amd64.deb to the desired server and install using the appropriate package system:

On CentOS/RHEL/Oracle/Amazon/Rocky::

On CentOs/RHEL::
yum install ./ncpa-3.0.0-latest.x86_64.rpm

yum install ./ncpa-2.x.x-1.elx.x86_64.rpm
On Ubuntu 18+/Debian 10+::

On Ubuntu/Debian::
dpkg -i ./ncpa_3.0.0-latest._amd64.deb

apt install ./ncpa_2.4.1-1.el7_amd64.deb
On Ubuntu 14-16/Debian 8-9 (not supported, but may work)::

dpkg --force-depends -i ./ncpa_3.0.0-latest._amd64.deb

On OpenSuSE/SLES::

zypper install ./ncpa_2.4.1-1.el7_amd64.deb
zypper install ./ncpa-3.0.0-latest.x86_64.rpm


Building on MacOS
=================

Working on this section. Using the new build system, these four lines should be enough
to create a working NCPA DMG.
*Not updated for v3, yet.*
It's basically the same as Linux, however you may need to
install the libraries and python differently, due to it being macOS. You must have
python3, wget and git installed prior to building NCPA v3.x.:


**Clone the git repo on an MacOS machine** (*It must have wget and git installed*)::
**Clone the repository into your directory**::

cd ~
git clone https://github.com/NagiosEnterprises/ncpa
Expand Down

0 comments on commit dce4c60

Please sign in to comment.