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 0013926
Show file tree
Hide file tree
Showing 63 changed files with 266 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
69 changes: 51 additions & 18 deletions build-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,67 @@ set -e
images=()
# The image will be pushed to GitHub container registry
repobase="${REPOBASE:-ghcr.io/nethserver}"


#
# base for php fpm
#
reponame="porthos-fpm-base"
container="porthos-fpm-container"
# Prepare a local Ubuntu-based samba image
if ! buildah inspect --type container "${container}" &>/dev/null; then
container=$(buildah from --name "${container}" 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 vi
apt-get clean
mkdir -vp /srv/porthos/webroot
chown -c -R www-data:www-data /srv/porthos/webroot
ln -v -s /usr/sbin/php-fpm* /usr/local/sbin/php-fpm
php --version
echo $(php -m)
php-fpm --version
EOF
buildah commit "${container}" "${repobase}/${reponame}"
fi

#
# php-fpm -- Using Debian for precompiled Redis extension
#
echo "Building the FPM image..."
reponame="porthos-fpm"
container=$(buildah from ${repobase}/porthos-fpm-base)
buildah add "${container}" fpm /
buildah config \
--workingdir=/srv/porthos/webroot \
--volume=/srv/porthos/webroot \
--entrypoint='["php-fpm", "-F", "-O", "-y", "/srv/porthos/etc/fpm.conf"]' \
--cmd='' \
"${container}"
# Commit the image
buildah commit "${container}" "${repobase}/${reponame}"

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

#
# module image
#
echo "Building the module image..."
# 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
Loading

0 comments on commit 0013926

Please sign in to comment.