Requirements

Linux

To update and test the command line tool you need

  • git
  • wget
  • a local PHP8 cli.

MS windows

Note: Work in progress.

On my test system I’ve installed with Chocolatey:

  • “Git (Install)” (the larger package with 125 MB) - additional tools below usr/bin/ are needed (spc tells you what to add in PATH)
  • Visual Studio 2022 Community (“viualstudioc2022community”)
  • PHP 8.4.4
  • Wget

🤕 During install the spc build process failed while compiling libiconv. I will continue if I found a solution or it.

Prepare environment

Get sources

In your personal development folder checkout the repsitory

cd <YOUR-PROJECTS>
git clone https://git-repo.iml.unibe.ch/iml-open-source/appmonitor-cli-client.git
cd appmonitor-cli-client

You get this initial structure:

.
├── build.php
├── examples
    └── embed_example.php
├── inc_functions.php
├── inc_vars.php
├── installer.php
├── readme.md
└── src
    └── amcli.php

Installer

Run the ./installer.php to download apmonitor source and spc. It prepares the micro build and creates a merged php file of all appmonitor client checks. This script has command line parameter support.

./installer.php -h

  CLI client
  DEVELOPMENT ENVIRONMENT

  I N S T A L L E R   *   U P D A T E R

...............................................................................

    - Get appmonitor sources or updates it
    - Get spc binary
    - Installations with spc doctor
    - Download PHP and libs with spc
    - Build Micro sfx with spc

...............................................................................

 ✨ SYNTAX:

    ./installer.php [OPTIONS]

 🔷 OPTIONS:

    -h, --help     Show this help
    -r, --reset    Reset; delete created folders of installer and build

The newly created files and dirs are:

.
├── build                    << working directory for builds
│   
├── external
│   ├── appmonitor           << cloned IML appmonitor project
│   └── bin
│       └── spc              << downloaded spc binary
│
├── src
│   └── include_checks.php   << merged appmonitor client checks
:

Video of the installer

The installer automates several things.

Espacially the download and compiler steps take a while. This video shows the process on my machine.

But a 2nd run is faster. It needs to git pull the appmonitor sources.

Build

To build the amcli binary start ./build.php. This script has command line parameter support.

 ./build.php -h

  CLI client
  DEVELOPMENT ENVIRONMENT

  B U I L D E R

...............................................................................

    - Merge PHP sources to a single file
    - Compile binary
    - Test binary
    - Coy to architecture specific binary
    - Create readme with buildinfos

...............................................................................

 ✨ SYNTAX:

    ./build.php [OPTIONS]

 🔷 OPTIONS:

    -h, --help     Show this help
    -f, --force    Force rebuild on unchanged sources
    -t, --test     Run full test suite: ./tests/00_start.php
                   without '-t': run a  single check only.

First it merges src/amcli.php and src/include_checks.php to src/amcli.php**.tmp** which is used for the build command of spc.

Output directory is built_packages.

After building the binary it executes it (with -V to show the version). If it is OK then it creates a copy with platform and architecture suffix.

Test

Start the script ./tests/00_start.php to test all included checks and ini styles.

This script has command line parameter support.

./tests/00_start.php -h

This ist the test suite for amcli calls.
It executes all scripts in this directory. They perform checks for metadata, 
help, all checks and ini features.

 ✨ SYNTAX:

    00_start.php [-b]

 🔷 OPTIONS:

    -h, --help           Show this help
    -b, --bin [=<FILE>]  Set amcli binary. If a FILE is given then use that one.
                         Default is the php script
                         /home/axel/data/opensource/php-class/amc-cli/tests/../src/amcli.php

                         Default of -b without file is
                         /home/axel/data/opensource/php-class/amc-cli/tests/../built_packages/amcli
    -l, --list           list filenames of tests

 👉 EXAMPLES:

    00_start.php         Run all tests with php sccript src/amcli.php
    00_start.php --bin   Run all tests with compiled binary built_packages/amcli
    00_start.php --bin=<FILE>
                         Run all tests with given binary

By default the testsuite is executed with the php script ./src/amcli.php. To test a compiled binary

This test will executed too, if you use the build script with -t.

Repeat?

You need to re-run install.php + build.php if

  • there is a newer appmonitor client version
  • you compile with a newer php version
  • you change the set of included php modules. For database access are included sqlite, mysql and postgres. For other database types supported by PHP you need to add the module in inc_vars.php $php_libs="..." and recompile the binary: php installer.php && php build.php;.

The build.php (without install.php) needs to be executed if the src/amcli.php was changed.

Start over

You can manually remove the dirs

  • built_packages
  • build
  • external

… and this file

  • src/include_checks.php

Then start ./installer.php and ./build.php

OR

You can use the -r / --reset parameter when starting the installer.php:

./installer.php --reset