Skip to content

Commit

Permalink
Working draft
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidePrincipi committed Dec 5, 2023
1 parent 436a1f2 commit 0fcae05
Show file tree
Hide file tree
Showing 63 changed files with 240 additions and 11,813 deletions.
29 changes: 0 additions & 29 deletions .devcontainer/devcontainer.json

This file was deleted.

12 changes: 0 additions & 12 deletions .github/workflows/build-apidoc.yml

This file was deleted.

9 changes: 0 additions & 9 deletions .github/workflows/clean-apidoc.yml

This file was deleted.

19 changes: 0 additions & 19 deletions .github/workflows/clean-registry.yml

This file was deleted.

26 changes: 0 additions & 26 deletions .github/workflows/test-module.yml

This file was deleted.

104 changes: 0 additions & 104 deletions .gitignore

This file was deleted.

5 changes: 0 additions & 5 deletions .vscode/settings.json

This file was deleted.

83 changes: 2 additions & 81 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,6 @@
# ns8-porthos

This is a template module for [NethServer 8](https://github.com/NethServer/ns8-core).
To start a new module from it:

1. Click on [Use this template](https://github.com/NethServer/ns8-porthos/generate).
Name your repo with `ns8-` prefix (e.g. `ns8-mymodule`).
Do not end your module name with a number, like ~~`ns8-baaad2`~~!

1. Clone the repository, enter the cloned directory and
[configure your GIT identity](https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup#_your_identity)

1. Rename some references inside the repo:
```
modulename=$(basename $(pwd) | sed 's/^ns8-//')
git mv imageroot/systemd/user/porthos.service imageroot/systemd/user/${modulename}.service
git mv tests/porthos.robot tests/${modulename}.robot
sed -i "s/porthos/${modulename}/g" $(find .github/ * -type f)
git commit -a -m "Repository initialization"
```

1. Edit this `README.md` file, by replacing this section with your module
description

1. Adjust `.github/workflows` to your needs. `clean-registry.yml` might
need the proper list of image names to work correctly. Unused workflows
can be disabled from the GitHub Actions interface.

1. Commit and push your local changes
Repository mirror of base OS packages

## Install

Expand All @@ -41,65 +15,12 @@ Output example:

## Configure

Let's assume that the porthos instance is named `porthos1`.

Launch `configure-module`, by setting the following parameters:
- `<MODULE_PARAM1_NAME>`: <MODULE_PARAM1_DESCRIPTION>
- `<MODULE_PARAM2_NAME>`: <MODULE_PARAM2_DESCRIPTION>
- ...

Example:

api-cli run module/porthos1/configure-module --data '{}'

The above command will:
- start and configure the porthos instance
- (describe configuration process)
- ...

Send a test HTTP request to the porthos backend service:

curl http://127.0.0.1/porthos/

## Smarthost setting discovery

Some configuration settings, like the smarthost setup, are not part of the
`configure-module` action input: they are discovered by looking at some
Redis keys. To ensure the module is always up-to-date with the
centralized [smarthost
setup](https://nethserver.github.io/ns8-core/core/smarthost/) every time
porthos starts, the command `bin/discover-smarthost` runs and refreshes
the `state/smarthost.env` file with fresh values from Redis.

Furthermore if smarthost setup is changed when porthos is already
running, the event handler `events/smarthost-changed/10reload_services`
restarts the main module service.

See also the `systemd/user/porthos.service` file.

This setting discovery is just an example to understand how the module is
expected to work: it can be rewritten or discarded completely.

## Uninstall

To uninstall the instance:

remove-module --no-preserve porthos1
TODO

## Testing

Test the module using the `test-module.sh` script:


./test-module.sh <NODE_ADDR> ghcr.io/nethserver/porthos:latest

The tests are made using [Robot Framework](https://robotframework.org/)

## UI translation

Translated with [Weblate](https://hosted.weblate.org/projects/ns8/).

To setup the translation process:

- add [GitHub Weblate app](https://docs.weblate.org/en/latest/admin/continuous.html#github-setup) to your repository
- add your repository to [hosted.weblate.org]((https://hosted.weblate.org) or ask a NethServer developer to add it to ns8 Weblate project
53 changes: 35 additions & 18 deletions build-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,51 @@ set -e
images=()
# The image will be pushed to GitHub container registry
repobase="${REPOBASE:-ghcr.io/nethserver}"

#
# php-fpm -- Using Debian for precompiled Redis extension
#
echo "Building the FPM image..."
reponame="porthos-fpm"
container=$(buildah from docker.io/library/debian:12.2-slim)
buildah run "${container}" sh <<'EOF'
set -e
apt-get update
apt-get -y install php-fpm php-redis
apt-get clean
mkdir -p /srv/porthos/webroot
chown -R www-data:www-data /srv/porthos
ln -v -s /usr/sbin/php-fpm* /usr/local/sbin/php-fpm
php --version
echo $(php -m)
php-fpm --version
EOF
buildah add "${container}" fpm /imageroot
buildah config \
--workingdir=/srv/porthos/webroot \
--volume=/srv/porthos/webroot \
--entrypoint='[]' \
--cmd='bash -l' \
"${container}"
# Commit the image
buildah commit "${container}" "${repobase}/${reponame}"

# Append the image URL to the images array
images+=("${repobase}/${reponame}")

# Configure the image name
reponame="porthos"

# Create a new empty container image
container=$(buildah from scratch)

# Reuse existing nodebuilder-porthos container, to speed up builds
if ! buildah containers --format "{{.ContainerName}}" | grep -q nodebuilder-porthos; then
echo "Pulling NodeJS runtime..."
buildah from --name nodebuilder-porthos -v "${PWD}:/usr/src:Z" docker.io/library/node:lts
fi

echo "Build static UI files with node..."
buildah run \
--workingdir=/usr/src/ui \
--env="NODE_OPTIONS=--openssl-legacy-provider" \
nodebuilder-porthos \
sh -c "yarn install && yarn build"

# Add imageroot directory to the container image
buildah add "${container}" imageroot /imageroot
buildah add "${container}" ui/dist /ui
buildah add "${container}" ui /ui
# Setup the entrypoint, ask to reserve one TCP port with the label and set a rootless container
buildah config --entrypoint=/ \
--label="org.nethserver.authorizations=traefik@node:routeadm" \
--label="org.nethserver.tcp-ports-demand=1" \
--label="org.nethserver.rootfull=0" \
--label="org.nethserver.images=docker.io/jmalloc/echo-server:latest" \
--label="org.nethserver.tcp-ports-demand=3" \
--label="org.nethserver.images=$(printf "%s:${IMAGETAG:-latest} " "${images[@]}") docker.io/library/nginx:1.25.3-alpine" \
"${container}"
# Commit the image
buildah commit "${container}" "${repobase}/${reponame}"
Expand Down
10 changes: 10 additions & 0 deletions fpm/srv/porthos/etc/fpm.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[porthos]
user = www-data
group = www-data
listen = /srv/porthos/run/fpm.sock
listen.mode = 0666
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
Empty file added fpm/srv/porthos/run/.gitignore
Empty file.
Loading

0 comments on commit 0fcae05

Please sign in to comment.