Skip to content

Commit

Permalink
Web server rootless update
Browse files Browse the repository at this point in the history
Update web server to work without root
  • Loading branch information
Angelo Delli Santi authored and pataxis committed Jan 19, 2024
1 parent 554f798 commit b4788f1
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/web-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
axis-os: ["11.7.57"]
axis-os: ["11.8.61"]
arch: ["armv7hf", "aarch64"]
env:
EXREPO: acap-native-examples
Expand Down
14 changes: 7 additions & 7 deletions web-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ARG ARCH=armv7hf
ARG REPO=axisecp
ARG SDK=acap-native-sdk
ARG UBUNTU_VERSION=22.04
ARG VERSION=1.11
ARG VERSION=1.12

FROM ${REPO}/${SDK}:${VERSION}-${ARCH}-ubuntu${UBUNTU_VERSION}

Expand All @@ -20,11 +20,11 @@ RUN git apply --ignore-space-change --ignore-whitespace ../monkey.patch &&\
--prefix=/usr/local \
--bindir=/usr/local/bin \
--libdir=/usr/local/lib \
--sysconfdir=/usr/local/packages/monkey/html \
--datadir=/usr/local/packages/monkey/html \
--sysconfdir=/usr/local/packages/list/html \
--datadir=/usr/local/packages/list/html \
--mandir=/usr/local/man \
--logdir=/tmp \
--plugdir=/usr/local/packages/monkey/lib \
--plugdir=/usr/local/packages/list/lib \
--pidfile=/tmp/monkey.pid \
--incdir=/usr/local/include/monkey \
--systemddir=/usr/lib/systemd/system &&\
Expand All @@ -40,9 +40,9 @@ RUN . /opt/axis/acapsdk/environment-setup* &&\
mkdir -p "$SDKTARGETSYSROOT"/usr/local &&\
cp -r /usr/local "$SDKTARGETSYSROOT"/usr &&\
mkdir -p lib &&\
cp /usr/local/lib/libmonkey.so.1.5 /usr/local/packages/monkey/lib/*.so -t lib/ &&\
cp -r /usr/local/packages/monkey/html . &&\
acap-build . -a reverseproxy.conf
cp /usr/local/lib/libmonkey.so.1.5 /usr/local/packages/list/lib/*.so -t lib/ &&\
cp -r /usr/local/packages/list/html . &&\
acap-build .

ENV PATH="${PATH}:/opt/axis/acapsdk/sysroots/x86_64-pokysdk-linux/usr/bin"
ENTRYPOINT [ "/bin/bash" ]
25 changes: 9 additions & 16 deletions web-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ This example addresses a similar problem as the [web-server-using-fastcgi](../we

[Reverse Proxy configuration](https://httpd.apache.org/docs/2.4/howto/reverse_proxy.html) provides a flexible way for an ACAP application to expose an external API through the Apache Server in AXIS OS and internally route the requests to a small Web Server running in the ACAP application.

Reverse Proxy is a technique that can be used for exposing many types of network APIs and can e.g. cover same cgi usecases as axHttp API.
**Reverse proxy** is a technique that can be used for exposing many types of network APIs and can e.g. cover the same CGI use cases as the old [AxHTTP](https://axiscommunications.github.io/acap-documentation/docs/acap-sdk-version-3/api/#http-api) API and is a different implementation to the [FastCGI](https://axiscommunications.github.io/acap-documentation/docs/api/native-sdk-api.html#fastcgi) API.

The Apache server is configured using post-install and pre-uninstall scripts features in a native ACAP. The post-install script adds a configuration file to apache configuration with reverse configuration for monkey server and applies it to Apache Server, and in the pre-uninstall the configuration is removed.
The Apache server is configured using the manifest.json file in an ACAP application. In manifest.json under `configuration`, it is possible to specify a `settingPage` and a `reverseProxy` where the latter will connect the Monkey server to the Apache server.

The Web Server running in the ACAP application can also be exposed directly to the network by allowing external access to the port in the network configuration for the device. There are some disavantages with exposing Web Server directly to the network such as non standard ports and no reuse of authentication, TLS and other features that comes with Apache Server.
The Web Server running in the ACAP application can also be exposed directly to the network by allowing external access to the port in the network configuration for the device. There are some disadvantages with exposing Web Server directly to the network such as non standard ports and no reuse of authentication, TLS and other features that comes with Apache Server.

## Monkey Web Server

Monkey is a fast and lightweight Web Server for Linux. It has been designed to be very scalable with low memory and CPU consumption, the perfect solution for Embedded Linux and high end production environments. Besides the common features as HTTP server, it expose a flexible C API which aims to behave as a fully HTTP development framework, so it can be extended as desired through the plugins interface. The Monkey Web Server [documentation](http://monkey-project.com/documentation/1.5) describes the configuration in detail.

> [!NOTE]
> Currently, there's an issue with the Monkey web server when using the reverse proxy, impacting asset discovery. As a workaround, we're showcasing the `list` example.
## Getting started

These instructions will guide you on how to execute the code. Below is the structure and scripts used in the example:
These instructions will guide you on how to execute the code. Below is the structure used in the example:

```sh
web-server
├── app
│ ├── LICENSE - Text file which lists all open source licensed source code distributed with the application
│ ├── manifest.json - Defines the application and its configuration
│ ├── postinstall.sh - Shell script for adding configration to apache
│ ├── preuninstall.sh - Shell script for removing configration to apache
│ └── reverseproxy.conf - Configuration for reverse proxy
│ └── manifest.json - Defines the application and its configuration
├── Dockerfile - Docker file with the specified Axis container image to build the example specified
├── monkey.patch - Patch for using monkey examples in a native ACAP
└── README.md - Step by step instructions on how to run the example
Expand Down Expand Up @@ -71,7 +71,7 @@ docker run --rm web-server:$ARCH eap-install.sh $DEVICE_IP $PASS install
Goto your device web page > Click on the tab **Apps** in the device GUI and locate the application. Run the application by enabling the **Start** switch.
The Web Server can be accessed from a Web Browser eighter directly using a port number (i.e. http://<device-ip>:2001) or through the Apache Server in the device using an extension to the device web URL (i.e http://<device-ip>/monkey/index.html) or by using the Open button in the application page in the **Apps** tab.
The Web Server can be accessed from a Web Browser through the Apache Server in the device using an extension to the device web URL (i.e http://<device-ip>/local/list/server/)
# Start your application from command line
Expand All @@ -83,13 +83,6 @@ docker run --rm web-server:$ARCH eap-install.sh $DEVICE_IP $PASS stop
docker run --rm web-server:$ARCH eap-install.sh $DEVICE_IP $PASS remove
```
## C API Examples
When you build the code, Some C API examples shall be copied into the app directory inside the build container. To build any of the examples, use the build and install procedure as described above after making following changes to the build files:
1. app/manifest.json: Replace AppName "monkey" with the name of the example: hello, list or quiz
2. Dockerfile: Replace monkey in /usr/local/packages/monkey with the name of the example: hello, list or quiz
## License
**[Apache License 2.0](../LICENSE)**
44 changes: 20 additions & 24 deletions web-server/app/manifest.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
{
"schemaVersion": "1.4.0",
"acapPackageConf": {
"setup": {
"appName": "monkey",
"vendor": "Axis Communications",
"embeddedSdkVersion": "3.0",
"user": {
"username": "sdk",
"group": "sdk"
},
"runMode": "never",
"version": "1.0.0"
},
"installation": {
"postInstallScript": "postinstall.sh"
},
"uninstallation": {
"preUninstallScript": "preuninstall.sh"
},
"configuration": {
"settingPage": "index.html"
}
}
}
"schemaVersion": "1.5.0",
"acapPackageConf": {
"setup": {
"appName": "list",
"vendor": "Axis Communications",
"embeddedSdkVersion": "3.0",
"runMode": "never",
"version": "1.0.0"
},
"configuration": {
"reverseProxy": [
{
"apiPath": "my_web_server",
"target": "http://localhost:2001",
"access": "admin"
}
]
}
}
}
3 changes: 0 additions & 3 deletions web-server/app/postinstall.sh

This file was deleted.

3 changes: 0 additions & 3 deletions web-server/app/preuninstall.sh

This file was deleted.

2 changes: 0 additions & 2 deletions web-server/app/reverseproxy.conf

This file was deleted.

0 comments on commit b4788f1

Please sign in to comment.