Skip to content

Commit 86df400

Browse files
authored
Merge pull request #16 from geniusdynamics/dev
Dev
2 parents b634f3c + 987f4d2 commit 86df400

4 files changed

Lines changed: 132 additions & 120 deletions

File tree

README.md

Lines changed: 77 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,127 @@
11
# ns8-matomo
22

3-
This is a module for [ns8-matomo8] for the Project (https://github.com/matomo-org/matomo).
4-
This is a module is based on the matomo Docker [matomo.org] (https://github.com/matomo-org/docker).
3+
This is a module for [NS8](https://github.com/NethServer/ns8-matomo) for the [Matomo](https://github.com/matomo-org/matomo) project.
54

6-
Start and configure a Matomo instance:
5+
The module is based on the official [Matomo Docker image](https://github.com/matomo-org/docker).
76

8-
with PHP FPM + nginx as a proxy
9-
redis caching
10-
MariaDB database The module uses Official matomo image.
7+
## Features
118

12-
1. Rename some references inside the repo:
13-
```
14-
modulename=$(basename $(pwd) | sed 's/^ns8-//')
15-
git mv imageroot/systemd/user/matomo.service imageroot/systemd/user/${modulename}.service
16-
git mv tests/matomo.robot tests/${modulename}.robot
17-
sed -i "s/matomo/${modulename}/g" $(find .github/ * -type f)
18-
git commit -a -m "Repository initialization"
19-
```
20-
21-
22-
23-
1. Adjust `.github/workflows` to your needs. `clean-registry.yml` might
24-
need the proper list of image names to work correctly. Unused workflows
25-
can be disabled from the GitHub Actions interface.
26-
27-
1. Commit and push your local changes
9+
- PHP FPM with nginx as reverse proxy
10+
- Redis caching
11+
- MariaDB database
2812

2913
## Install
3014

3115
Instantiate the module with:
3216

33-
add-module ghcr.io/compgeniuses/matomo:latest 1
17+
```bash
18+
add-module ghcr.io/geniusdynamics/matomo:latest 1
19+
```
3420

3521
The output of the command will return the instance name.
36-
Output example:
3722

38-
{"module_id": "matomo1", "image_name": "matomo", "image_url": "ghcr.io/compgeniuses/matomo:latest"}
23+
Example output:
24+
25+
```json
26+
{
27+
"module_id": "matomo1",
28+
"image_name": "matomo",
29+
"image_url": "ghcr.io/geniusdynamics/matomo:latest"
30+
}
31+
```
3932

4033
## Configure
4134

42-
Let's assume that the dokuwiki istance is named `matomo1`.
35+
Assuming the Matomo instance is named `matomo1`, launch `configure-module` with the following parameters:
36+
37+
### MariaDB Service Configuration
4338

44-
Then launch `configure-module`, by setting the following parameters:
45-
## MAriDB Service Configurations
39+
| Parameter | Value |
40+
| -------------------------------- | ----------------------------------- |
41+
| `MYSQL_ROOT_PASSWORD` | Set a strong password for root user |
42+
| `MARIADB_AUTO_UPGRADE` | 1 |
43+
| `MARIADB_DISABLE_UPGRADE_BACKUP` | 1 |
4644

47-
- `MYSQL_ROOT_PASSWORD`:
48-
- `MARIADB_AUTO_UPGRADE`: 1
49-
- `MARIADB_DISABLE_UPGRADE_BACKUP`: 1
45+
### Database Configuration
5046

51-
## DB Configurations
47+
| Parameter | Description |
48+
| ------------------------------- | ------------------------------------- |
49+
| `MYSQL_PASSWORD` | Password for the Matomo database user |
50+
| `MYSQL_DATABASE` | Name of the Matomo database |
51+
| `MYSQL_USER` | Username for the Matomo database |
52+
| `MATOMO_DATABASE_ADAPTER` | mysql |
53+
| `MATOMO_DATABASE_TABLES_PREFIX` | Table prefix (optional) |
54+
| `MATOMO_DATABASE_USERNAME` | Database username |
55+
| `MATOMO_DATABASE_PASSWORD` | Database password |
56+
| `MATOMO_DATABASE_DBNAME` | Database name |
57+
| `MARIADB_INITDB_SKIP_TZINFO` | 1 |
5258

53-
- `MYSQL_PASSWORD`: administrator mail address
54-
- `MYSQL_DATABASE`: administrator mail address
55-
- `MYSQL_USER`: administrator mail address
56-
- `MATOMO_DATABASE_ADAPTER`: mysql
57-
- `MATOMO_DATABASE_TABLES_PREFIX`: administrator mail address
58-
- `MATOMO_DATABASE_USERNAME`: administrator mail address
59-
- `MATOMO_DATABASE_PASSWORD`: administrator mail address
60-
- `MATOMO_DATABASE_DBNAME`: administrator mail address
61-
- `MARIADB_AUTO_UPGRADE`: 1
62-
- `MARIADB_INITDB_SKIP_TZINFO`: 1
59+
### Matomo Environment Configuration
6360

64-
## matomo env Configurations
65-
- `MATOMO_DATABASE_HOST`: 1
66-
- `PHP_MEMORY_LIMIT`: 2048
67-
- `host`: a fully qualified domain name for the wiki
68-
- `http2https`: enable or disable HTTP to HTTPS redirection
69-
- `lets_encrypt`: enable or disable Let's Encrypt certificate
61+
| Parameter | Description |
62+
| ---------------------- | ------------------------------------------- |
63+
| `MATOMO_DATABASE_HOST` | Database host (e.g., MariaDB module) |
64+
| `PHP_MEMORY_LIMIT` | PHP memory limit (e.g., 2048M) |
65+
| `host` | Fully qualified domain name for Matomo |
66+
| `http2https` | Enable or disable HTTP to HTTPS redirection |
67+
| `lets_encrypt` | Enable or disable Let's Encrypt certificate |
7068

7169
Example:
7270

73-
api-cli run module/matomo1/configure-module --data '{}'
71+
```bash
72+
api-cli run module/matomo1/configure-module --data '{}'
73+
```
7474

75-
The above command will:
76-
- start and configure the matomo instance
77-
- (describe configuration process)
78-
- ...
75+
The above command will start and configure the Matomo instance.
7976

80-
Send a test HTTP request to the matomo backend service:
77+
Test the Matomo backend service:
8178

82-
curl http://127.0.0.1/matomo/
79+
```bash
80+
curl http://127.0.0.1/matomo/
81+
```
8382

84-
## Smarthost setting discovery
83+
## Smarthost Setting Discovery
8584

86-
Some configuration settings, like the smarthost setup, are not part of the
87-
`configure-module` action input: they are discovered by looking at some
88-
Redis keys. To ensure the module is always up-to-date with the
89-
centralized [smarthost
90-
setup](https://compgeniuses.github.io/ns8-core/core/smarthost/) every time
91-
matomo starts, the command `bin/discover-smarthost` runs and refreshes
92-
the `state/smarthost.env` file with fresh values from Redis.
85+
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://geniusdynamics.github.io/ns8-core/core/smarthost/) every time Matomo starts, the command `bin/discover-smarthost` runs and refreshes the `state/smarthost.env` file with fresh values from Redis.
9386

94-
Furthermore if smarthost setup is changed when matomo is already
95-
running, the event handler `events/smarthost-changed/10reload_services`
96-
restarts the main module service.
87+
Furthermore if smarthost setup is changed when Matomo is already running, the event handler `events/smarthost-changed/10reload_services` restarts the main module service.
9788

9889
See also the `systemd/user/matomo.service` file.
9990

100-
This setting discovery is just an example to understand how the module is
101-
expected to work: it can be rewritten or discarded completely.
91+
This setting discovery is just an example to understand how the module is expected to work: it can be rewritten or discarded completely.
92+
93+
## Update
94+
95+
You can forcefully update the module
96+
97+
```bash
98+
api-cli run update-module --data '{"module_url":"ghcr.io/geniusdynamics/matomo:latest","instances":["matomo1"],"force":true}'
99+
```
102100

103101
## Uninstall
104102

105103
To uninstall the instance:
106104

107-
remove-module --no-preserve matomo1
105+
```bash
106+
remove-module --no-preserve matomo1
107+
```
108108

109109
## Testing
110110

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

113+
```bash
114+
./test-module.sh <NODE_ADDR> ghcr.io/geniusdynamics/matomo:latest
115+
```
113116

114-
./test-module.sh <NODE_ADDR> ghcr.io/compgeniuses/matomo:latest
117+
The tests are made using [Robot Framework](https://robotframework.org/).
115118

116-
The tests are made using [Robot Framework](https://robotframework.org/)
117-
118-
## UI translation
119+
## UI Translation
119120

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

122123
To setup the translation process:
123124

124-
- add [GitHub Weblate app](https://docs.weblate.org/en/latest/admin/continuous.html#github-setup) to your repository
125-
- add your repository to [hosted.weblate.org]((https://hosted.weblate.org) or ask a compgeniuses developer to add it to ns8 Weblate project
125+
1. Add [GitHub Weblate app](https://docs.weblate.org/en/latest/admin/continuous.html#github-setup) to your repository
126+
2. Add your repository to [hosted.weblate.org](https://hosted.weblate.org) or ask a NethServer developer to add it to the NS8 Weblate project
127+

build-images.sh

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,33 @@ images=()
1313
repobase="${REPOBASE:-ghcr.io/geniusdynamics}"
1414
# Configure the image name
1515
reponame="matomo"
16-
matomo_version="5.3.2"
16+
matomo_version="5.8.0"
1717
# Create a new empty container image
1818
container=$(buildah from scratch)
1919

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

2626
echo "Build static UI files with node..."
2727
buildah run \
28-
--workingdir=/usr/src/ui \
29-
--env="NODE_OPTIONS=--openssl-legacy-provider" \
30-
nodebuilder-matomo \
31-
sh -c "yarn install && yarn build"
28+
--workingdir=/usr/src/ui \
29+
--env="NODE_OPTIONS=--openssl-legacy-provider" \
30+
nodebuilder-matomo \
31+
sh -c "yarn install && yarn build"
3232

3333
# Add imageroot directory to the container image
3434
buildah add "${container}" imageroot /imageroot
3535
buildah add "${container}" ui/dist /ui
3636
# Setup the entrypoint, ask to reserve one TCP port with the label and set a rootless container
3737
buildah config --entrypoint=/ \
38-
--label="org.nethserver.authorizations=traefik@node:routeadm" \
39-
--label="org.nethserver.tcp-ports-demand=1" \
40-
--label="org.nethserver.rootfull=0" \
41-
--label="org.nethserver.images=docker.io/matomo:${matomo_version} docker.io/mariadb:10.11.6" \
42-
"${container}"
38+
--label="org.nethserver.authorizations=traefik@node:routeadm" \
39+
--label="org.nethserver.tcp-ports-demand=1" \
40+
--label="org.nethserver.rootfull=0" \
41+
--label="org.nethserver.images=docker.io/matomo:${matomo_version} docker.io/mariadb:10.11.6" \
42+
"${container}"
4343
# Commit the image
4444
buildah commit "${container}" "${repobase}/${reponame}"
4545

@@ -60,11 +60,11 @@ images+=("${repobase}/${reponame}")
6060
# Setup CI when pushing to Github.
6161
# Warning! docker::// protocol expects lowercase letters (,,)
6262
if [[ -n "${CI}" ]]; then
63-
# Set output value for Github Actions
64-
printf "images=%s\n" "${images[*],,}" >>"${GITHUB_OUTPUT}"
63+
# Set output value for Github Actions
64+
printf "images=%s\n" "${images[*],,}" >>"${GITHUB_OUTPUT}"
6565
else
66-
# Just print info for manual push
67-
printf "Publish the images with:\n\n"
68-
for image in "${images[@],,}"; do printf " buildah push %s docker://%s:%s\n" "${image}" "${image}" "${IMAGETAG:-latest}"; done
69-
printf "\n"
66+
# Just print info for manual push
67+
printf "Publish the images with:\n\n"
68+
for image in "${images[@],,}"; do printf " buildah push %s docker://%s:%s\n" "${image}" "${image}" "${IMAGETAG:-latest}"; done
69+
printf "\n"
7070
fi

imageroot/actions/configure-module/20configure

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,29 @@ h2hs = data.get("http2https", True)
2323
# Setup configuration from user input.
2424
agent.set_env("TRAEFIK_HOST", host)
2525
agent.set_env("TRAEFIK_LETS_ENCRYPT", le)
26+
agent.set_env("TRAEFIK_HTTP2HTTPS", h2hs)
2627

2728
# Make sure everything is saved inside the environment file
2829
# just before starting systemd unit
2930
agent.dump_env()
3031

3132
# Find default traefik instance for current node
32-
default_traefik_id = agent.resolve_agent_id('traefik@node')
33+
default_traefik_id = agent.resolve_agent_id("traefik@node")
3334
if default_traefik_id is None:
3435
sys.exit(2)
3536

3637
response = agent.tasks.run(
37-
agent_id=agent.resolve_agent_id('traefik@node'),
38-
action='set-route',
38+
agent_id=agent.resolve_agent_id("traefik@node"),
39+
action="set-route",
3940
data={
40-
'instance': os.environ['MODULE_ID'],
41-
'url': 'http://127.0.0.1:' + os.environ["TCP_PORT"],
42-
'host': host,
43-
'http2https': True,
44-
'lets_encrypt': le
41+
"instance": os.environ["MODULE_ID"],
42+
"url": "http://127.0.0.1:" + os.environ["TCP_PORT"],
43+
"host": host,
44+
"http2https": True,
45+
"lets_encrypt": le,
4546
},
4647
)
4748

4849
# Check if traefik configuration has been successfull
49-
agent.assert_exp(response['exit_code'] == 0)
50+
agent.assert_exp(response["exit_code"] == 0)
51+

imageroot/actions/get-configuration/20read

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,47 @@ from agent.ldapproxy import Ldapproxy
1010
config = {}
1111

1212
# Read current configuration from the environment file
13-
config["host"] = os.getenv("TRAEFIK_HOST","")
13+
config["host"] = os.getenv("TRAEFIK_HOST", "")
1414
config["lets_encrypt"] = os.getenv("TRAEFIK_LETS_ENCRYPT") == "True"
15-
config["matomo_database_username"] = os.getenv("MATOMO_DATABASE_USERNAME","matomo")
16-
config["matomo_database_password"] = os.getenv("MATOMO_DATABASE_PASSWORD","Matomo,1234")
17-
config["matomo_database_dbname"] = os.getenv("MATOMO_DATABASE_DBNAME","matomo")
18-
config["matomo_database_host"] = os.getenv("MATOMO_DATABASE_HOST","")
15+
config["http2https"] = os.getenv("TRAEFIK_HTTP2HTTPS") == "True"
16+
config["matomo_database_username"] = os.getenv("MATOMO_DATABASE_USERNAME", "matomo")
17+
config["matomo_database_password"] = os.getenv(
18+
"MATOMO_DATABASE_PASSWORD", "Matomo,1234"
19+
)
20+
config["matomo_database_dbname"] = os.getenv("MATOMO_DATABASE_DBNAME", "matomo")
21+
config["matomo_database_host"] = os.getenv("MATOMO_DATABASE_HOST", "")
1922
config["mariadb_auto_upgrade"] = os.getenv("MARIADB_AUTO_UPGRADE") == "1"
20-
config["mariadb_disable_upgrade_backup"] = os.getenv("MARIADB_DISABLE_UPGRADE_BACKUP") == "1"
21-
config["matomo_database_tables_prefix"] = os.getenv("MATOMO_DATABASE_TABLES_PREFIX","")
22-
config["matomo_database_adapter"] = os.getenv("MATOMO_DATABASE_ADAPTER","")
23+
config["mariadb_disable_upgrade_backup"] = (
24+
os.getenv("MARIADB_DISABLE_UPGRADE_BACKUP") == "1"
25+
)
26+
config["matomo_database_tables_prefix"] = os.getenv("MATOMO_DATABASE_TABLES_PREFIX", "")
27+
config["matomo_database_adapter"] = os.getenv("MATOMO_DATABASE_ADAPTER", "")
2328

2429

25-
rdb = agent.redis_connect() # full read-only access on every key
30+
rdb = agent.redis_connect() # full read-only access on every key
2631

27-
modules=[]
32+
modules = []
2833
tmp = []
2934

3035
# retrieve installed modules list
3136
for key in rdb.scan_iter("module:*"):
3237
tmp.append(key.decode("utf-8"))
33-
38+
3439
# retrieve LDAP domains list
3540
lp = Ldapproxy()
3641
domains = []
3742
for key in lp.get_domains_list():
38-
domains.append({
39-
"name": key,
40-
"label": key,
41-
"value": key,
42-
})
43+
domains.append(
44+
{
45+
"name": key,
46+
"label": key,
47+
"value": key,
48+
}
49+
)
4350

44-
config['user_domains_list'] = domains
51+
config["user_domains_list"] = domains
4552

4653

4754
# Dump the configuration to stdout
48-
json.dump(config, fp=sys.stdout)
55+
json.dump(config, fp=sys.stdout)
56+

0 commit comments

Comments
 (0)