Skip to content

Commit

Permalink
Repository initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
stephdl committed Sep 25, 2023
1 parent aadc337 commit 5160ec8
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/clean-registry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ jobs:
steps:
- uses: NethServer/ns8-github-actions/.github/actions/delete-image@v1
with:
images: "kickstart"
images: "imapsync"
delete_image_token: ${{ secrets.IMAGES_CLEANUP_TOKEN }}
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# ns8-kickstart
# ns8-imapsync

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

Expand All @@ -13,9 +13,9 @@ To start a new module from it:
1. Rename some references inside the repo:
```
modulename=$(basename $(pwd) | sed 's/^ns8-//')
git mv imageroot/systemd/user/kickstart.service imageroot/systemd/user/${modulename}.service
git mv tests/kickstart.robot tests/${modulename}.robot
sed -i "s/kickstart/${modulename}/g" $(find .github/ * -type f)
git mv imageroot/systemd/user/imapsync.service imageroot/systemd/user/${modulename}.service
git mv tests/imapsync.robot tests/${modulename}.robot
sed -i "s/imapsync/${modulename}/g" $(find .github/ * -type f)
git commit -a -m "Repository initialization"
```

Expand All @@ -32,16 +32,16 @@ To start a new module from it:

Instantiate the module with:

add-module ghcr.io/nethserver/kickstart:latest 1
add-module ghcr.io/nethserver/imapsync:latest 1

The output of the command will return the instance name.
Output example:

{"module_id": "kickstart1", "image_name": "kickstart", "image_url": "ghcr.io/nethserver/kickstart:latest"}
{"module_id": "imapsync1", "image_name": "imapsync", "image_url": "ghcr.io/nethserver/imapsync:latest"}

## Configure

Let's assume that the kickstart instance is named `kickstart1`.
Let's assume that the imapsync instance is named `imapsync1`.

Launch `configure-module`, by setting the following parameters:
- `<MODULE_PARAM1_NAME>`: <MODULE_PARAM1_DESCRIPTION>
Expand All @@ -50,16 +50,16 @@ Launch `configure-module`, by setting the following parameters:

Example:

api-cli run module/kickstart1/configure-module --data '{}'
api-cli run module/imapsync1/configure-module --data '{}'

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

Send a test HTTP request to the kickstart backend service:
Send a test HTTP request to the imapsync backend service:

curl http://127.0.0.1/kickstart/
curl http://127.0.0.1/imapsync/

## Smarthost setting discovery

Expand All @@ -68,14 +68,14 @@ Some configuration settings, like the smarthost setup, are not part of the
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
kickstart starts, the command `bin/discover-smarthost` runs and refreshes
imapsync 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 kickstart is already
Furthermore if smarthost setup is changed when imapsync is already
running, the event handler `events/smarthost-changed/10reload_services`
restarts the main module service.

See also the `systemd/user/kickstart.service` file.
See also the `systemd/user/imapsync.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.
Expand All @@ -84,14 +84,14 @@ expected to work: it can be rewritten or discarded completely.

To uninstall the instance:

remove-module --no-preserve kickstart1
remove-module --no-preserve imapsync1

## Testing

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


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

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

Expand Down
10 changes: 5 additions & 5 deletions build-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ images=()
# The image will be pushed to GitHub container registry
repobase="${REPOBASE:-ghcr.io/nethserver}"
# Configure the image name
reponame="kickstart"
reponame="imapsync"

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

# Reuse existing nodebuilder-kickstart container, to speed up builds
if ! buildah containers --format "{{.ContainerName}}" | grep -q nodebuilder-kickstart; then
# Reuse existing nodebuilder-imapsync container, to speed up builds
if ! buildah containers --format "{{.ContainerName}}" | grep -q nodebuilder-imapsync; then
echo "Pulling NodeJS runtime..."
buildah from --name nodebuilder-kickstart -v "${PWD}:/usr/src:Z" docker.io/library/node:lts
buildah from --name nodebuilder-imapsync -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-kickstart \
nodebuilder-imapsync \
sh -c "yarn install && yarn build"

# Add imageroot directory to the container image
Expand Down
6 changes: 3 additions & 3 deletions imageroot/actions/configure-module/20configure
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ request = json.load(sys.stdin)

# TODO: do something with the request payload. For example configure a
# custom route in our web router. Here the path is hardcoded as
# 'kickstart'.
# 'imapsync'.

# Configure Traefik to route "/kickstart" path requests to the kickstart service
# Configure Traefik to route "/imapsync" path requests to the imapsync service
response = agent.tasks.run(
agent_id=agent.resolve_agent_id('traefik@node'),
action='set-route',
Expand All @@ -26,7 +26,7 @@ response = agent.tasks.run(
'url': 'http://127.0.0.1:' + os.environ["TCP_PORT"],
'http2https': False,
'lets_encrypt': False,
'path': '/kickstart',
'path': '/imapsync',
},
)

Expand Down
2 changes: 1 addition & 1 deletion imageroot/actions/configure-module/80start_services
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@

touch smarthost.env

systemctl --user enable --now kickstart.service
systemctl --user enable --now imapsync.service
4 changes: 2 additions & 2 deletions imageroot/actions/configure-module/validate-input.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "configure-module input",
"$id": "http://schema.nethserver.org/kickstart/configure-module-input.json",
"description": "Configure kickstart",
"$id": "http://schema.nethserver.org/imapsync/configure-module-input.json",
"description": "Configure imapsync",
"examples": [],
"type": "object"
}
4 changes: 2 additions & 2 deletions imageroot/actions/get-configuration/validate-output.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "get-configuration output",
"$id": "http://schema.nethserver.org/kickstart/get-configuration-output.json",
"description": "Get kickstart configuration",
"$id": "http://schema.nethserver.org/imapsync/get-configuration-output.json",
"description": "Get imapsync configuration",
"examples": [],
"type": "object"
}
2 changes: 1 addition & 1 deletion imageroot/events/smarthost-changed/10reload_services
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

set -e

systemctl --user try-reload-or-restart kickstart.service
systemctl --user try-reload-or-restart imapsync.service
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@
#

#
# This systemd unit starts a kickstart instance using Podman.
# This systemd unit starts a imapsync instance using Podman.
# Most parts of this file come from podman-generate-systemd.
#
[Unit]
Description=kickstart server
Description=imapsync server

[Service]
Environment=PODMAN_SYSTEMD_UNIT=%n
EnvironmentFile=%S/state/environment
WorkingDirectory=%S/state
Restart=always
ExecStartPre=/bin/rm -f %t/kickstart.pid %t/kickstart.ctr-id
ExecStartPre=/bin/rm -f %t/imapsync.pid %t/imapsync.ctr-id
ExecStartPre=-runagent discover-smarthost
ExecStart=/usr/bin/podman run \
--detach \
--conmon-pidfile=%t/kickstart.pid \
--cidfile=%t/kickstart.ctr-id \
--conmon-pidfile=%t/imapsync.pid \
--cidfile=%t/imapsync.ctr-id \
--cgroups=no-conmon \
--replace --name=%N \
--publish=127.0.0.1:${TCP_PORT}:8080 \
--env-file=smarthost.env
${ECHO_SERVER_IMAGE}
ExecStop=/usr/bin/podman stop --ignore --cidfile %t/kickstart.ctr-id -t 10
ExecStopPost=/usr/bin/podman rm --ignore -f --cidfile %t/kickstart.ctr-id
PIDFile=%t/kickstart.pid
ExecStop=/usr/bin/podman stop --ignore --cidfile %t/imapsync.ctr-id -t 10
ExecStopPost=/usr/bin/podman rm --ignore -f --cidfile %t/imapsync.ctr-id
PIDFile=%t/imapsync.pid
Type=forking

[Install]
Expand Down
10 changes: 5 additions & 5 deletions tests/kickstart.robot → tests/imapsync.robot
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
Library SSHLibrary

*** Test Cases ***
Check if kickstart is installed correctly
Check if imapsync is installed correctly
${output} ${rc} = Execute Command add-module ${IMAGE_URL} 1
... return_rc=True
Should Be Equal As Integers ${rc} 0
&{output} = Evaluate ${output}
Set Suite Variable ${module_id} ${output.module_id}

Check if kickstart can be configured
Check if imapsync can be configured
${rc} = Execute Command api-cli run module/${module_id}/configure-module --data '{}'
... return_rc=True return_stdout=False
Should Be Equal As Integers ${rc} 0

Check if kickstart works as expected
${rc} = Execute Command curl -f http://127.0.0.1/kickstart/
Check if imapsync works as expected
${rc} = Execute Command curl -f http://127.0.0.1/imapsync/
... return_rc=True return_stdout=False
Should Be Equal As Integers ${rc} 0

Check if kickstart is removed correctly
Check if imapsync is removed correctly
${rc} = Execute Command remove-module --no-preserve ${module_id}
... return_rc=True return_stdout=False
Should Be Equal As Integers ${rc} 0
4 changes: 2 additions & 2 deletions ui/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# NS8 kickstart UI development
# NS8 imapsync UI development

To develop kickstart UI please refer to [this section of the Developer manual](https://nethserver.github.io/ns8-core/ui/modules/#module-ui-development).
To develop imapsync UI please refer to [this section of the Developer manual](https://nethserver.github.io/ns8-core/ui/modules/#module-ui-development).
10 changes: 5 additions & 5 deletions ui/public/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kickstart",
"name": "imapsync",
"description": {
"en": "My kickstart module"
"en": "My imapsync module"
},
"categories": [],
"authors": [
Expand All @@ -11,9 +11,9 @@
}
],
"docs": {
"documentation_url": "https://docs.kickstart.com/",
"documentation_url": "https://docs.imapsync.com/",
"bug_url": "https://github.com/NethServer/dev",
"code_url": "https://github.com/author/ns8-kickstart"
"code_url": "https://github.com/author/ns8-imapsync"
},
"source": "ghcr.io/nethserver/kickstart"
"source": "ghcr.io/nethserver/imapsync"
}

0 comments on commit 5160ec8

Please sign in to comment.