Skip to content

Commit 30dc127

Browse files
authored
Merge pull request #26 from MITLibraries/IN-1301
Updates for New Use of EFS
2 parents 5e5ab5c + 6b59519 commit 30dc127

File tree

8 files changed

+67
-39
lines changed

8 files changed

+67
-39
lines changed

.github/CODEOWNERS

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
# Teams can be specified as code owners as well. Teams should be identified in
1414
# the format @org/team-name. Teams must have explicit write access to the
1515
# repository.
16-
* @mitlibraries/infraeng-terraform-reviewers
16+
* @mitlibraries/infraeng
17+
18+
# We assign Dhruti as an owner of the Dockerfile, since she should approve any
19+
# core changes to Matomo (especially version upgrades)
20+
/Dockerfile @dhrutibc
1721

1822
# We set the senior engineer in the team as the owner of the CODEOWNERS file as
1923
# a layer of protection for unauthorized changes.

Dockerfile

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,31 @@ COPY ./files/plugin-HeatmapSessionRecording-5.2.3/ /var/www/html/plugins/Heatmap
1414
# Add the UsersFlow plugin
1515
COPY ./files/plugin-UsersFlow-5.0.5/ /var/www/html/plugins/UsersFlow
1616

17-
# Our custom configuration settings
18-
COPY ./files/config.ini.php /var/www/html/config/config.ini.php
17+
# Our custom configuration settings. We put it in /usr/src because the
18+
# entrypoint.sh builds the /var/www/html folder from the /usr/src/matomo
19+
# folder. This ensures that the config file from our updated container is the
20+
# one that is pushed to the persistent EFS storage.
21+
COPY ./files/config.ini.php /usr/src/matomo/config/config.ini.php
1922

2023
# The HeatmapSessionRecording and UsersFlow update the matomo.js and piwik.js
2124
# files when they are activated. Those updates have been captured and we
22-
# pre-load them here (we put them in /usr/src because the entrypoint.sh is what
23-
# actually builds the /var/www/html folder as a Docker VOLUME)
25+
# pre-load them here (we put them in /usr/src because the entrypoint.sh builds
26+
# the /var/www/html folder from the /usr/src/matomo folder.
2427
COPY --chmod=0644 ./files/post_premium_plugins_matomo.js /usr/src/matomo/matomo.js
2528
COPY --chmod=0644 ./files/post_premium_plugins_piwik.js /usr/src/matomo/piwik.js
2629

2730
# Address "public" directories problem
28-
COPY --chmod=0644 --chown=root:root ./files/lang-htaccess /var/www/html/lang/.htaccess
29-
COPY --chmod=0644 --chown=root:root ./files/config-htaccess /var/www/html/config/.htaccess
30-
COPY --chmod=0644 --chown=root:root ./files/tmp-htaccess /var/www/html/tmp/.htaccess
31+
COPY --chmod=0644 --chown=root:root ./files/lang-htaccess /usr/src/matomo/lang/.htaccess
32+
COPY --chmod=0644 --chown=root:root ./files/config-htaccess /usr/src/matomo/config/.htaccess
33+
COPY --chmod=0644 --chown=root:root ./files/tmp-htaccess /usr/src/matomo/tmp/.htaccess
3134

3235
# Create mount point for EFS partition
3336
RUN mkdir -p /mnt/efs
3437

38+
# Fix the installation line in the entrypoint script. We have to modify this
39+
# because we enforce the uid/gid via the AWS EFS Access Point configuration.
40+
RUN sed -i 's|tar xf -|tar xf - --no-same-owner|' /entrypoint.sh
41+
3542
# Move in the "backup persistent files" script
3643
COPY --chmod=0755 ./files/backup-data.sh /usr/local/bin/backup-data.sh
3744

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ help: ## Print this message
1414

1515
### Terraform-generated Developer Deploy Commands for Dev environment ###
1616
dist-dev: ## Build docker container (intended for developer-based manual build)
17-
docker build --platform linux/amd64 \
17+
docker build \
18+
--platform linux/amd64 \
1819
-t $(ECR_URL_DEV):latest \
1920
-t $(ECR_URL_DEV):`git describe --always` \
2021
-t $(ECR_NAME_DEV):latest .
@@ -35,7 +36,8 @@ publish-dev: dist-dev ## Build, tag and push (intended for developer-based manua
3536
### authenticated to the correct AWS Account. The values for the environment ###
3637
### variables can be found in the stage_build.yml caller workflow. ###
3738
dist-stage: ## Only use in an emergency
38-
docker build --platform linux/amd64 \
39+
docker build \
40+
--platform linux/amd64 \
3941
-t $(ECR_URL_STAGE):latest \
4042
-t $(ECR_URL_STAGE):`git describe --always` \
4143
-t $(ECR_NAME_STAGE):latest .

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Run `make publish-dev` to build, tag, and push a container to Dev1 for testing,
2020

2121
Merge a PR to `main` to build, tag, and push the container to Stage-Workloads. After merging the PR to `main`, tag a release on the `main` branch to promote to production. GitHub Actions in this repo will take care of the build, tag, push to Stage and the copy from Stage to Production.
2222

23-
**Important Note**: There is no automation in GitHub to automatically deploy the new container after it is push to the ECR repository in AWS. At this time, the only method to deploy the updated container is to force a new deployment of the Matomo service via the AWS Console.
23+
**Important Note**: There is no automation in GitHub to automatically deploy the new container after it is push to the ECR repository in AWS. At this time, the only method to deploy the updated container is to force a new deployment of the Matomo service via the AWS Console or the CLI.
2424

2525
## Implementation notes
2626

@@ -39,7 +39,7 @@ The `config.ini.php` file contains some core Matomo configuration. There are a c
3939

4040
We use the [EnvironmentVariables](https://plugins.matomo.org/EnvironmentVariables) plugin that allows us to set configuration values for Matomo via environment variables via the [mitlib-tf-workloads-matomo](https://github.com/mitlibraries/mitlib-tf-workloads-matomo) infrastructure repo.
4141

42-
The current practice is to set the following core configuration information in `config.ini.php` via environment variables.
42+
The current practice is to set the following core configuration information in `config.ini.php` via environment variables.
4343

4444
* Database connection information
4545
* SSL/TLS configuration
@@ -75,7 +75,7 @@ Before promoting a new build to production, ensure that IPs are anonymized by vi
7575

7676
### Archiving reports
7777

78-
Matomo calls the process by which it compiles raw log data into human-readable report 'archiving'. By default, archiving occurs on demand, whenever a Matomo user attempts to view a report in the GUI. Following [Matomo's recommendation](https://matomo.org/docs/setup-auto-archiving/) to schedule this, the mitlib-tf-workloads-matomo infrastructure repository creates an EventBridge rule/schedule for running the reporting archiving hourly.
78+
Matomo calls the process by which it compiles raw log data into human-readable report 'archiving'. By default, archiving occurs on demand, whenever a Matomo user attempts to view a report in the GUI. Following [Matomo's recommendation](https://matomo.org/docs/setup-auto-archiving/) to schedule this, the [mitlib-tf-workloads-matomo](https://github.com/MITLibraries/mitlib-tf-workloads-matomo) infrastructure repository creates an EventBridge rule/schedule for running the reporting archiving hourly (only daily in Dev1).
7979

8080
### Authentication
8181

@@ -97,7 +97,7 @@ See the official [Recover from lost 2FA](https://matomo.org/faq/how-to/faq_27248
9797

9898
* Owner: See [CODEOWNERS](./.github/CODEOWNERS)
9999
* Team: See [CODEOWNERS](./.github/CODEOWNERS)
100-
* Last Maintenance: 2025-02
100+
* Last Maintenance: 2025-05
101101
* External Documentation:
102102
* [MIT Libraries dev docs](https://mitlibraries.github.io/guides/misc/matomo.html) - includes information about setting up a website for tracking in Matomo.
103103
* [Matomo help center](https://matomo.org/help/) - offical Matomo docs. Includes user guide, developer guide, FAQ, and community support forum.

docs/HowTos/HOWTO-matomo-upgrade.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ The database engine is managed by [mitlib-tf-workloads-matomo](https://github.co
1010

1111
These instructions assume you are working in the **dev** environment. Change to the appropriate `<env>` tag if you are working in a different environment.
1212

13-
1. Ensure that a backup of the current `config/config.ini.php` exists in the EFS mount.
13+
1. Ensure that an out-of-band backup of the current `config/config.ini.php` exists
1414
* SSH (via AWSCLI + Session Manager) to the container(see the [Troubleshooting](./HOWTO-miscellaneous.md) section for the AWS CLI connection command).
15-
* Run the **backup-data.sh** script `/usr/local/bin/backup-data.sh`
15+
* Run `cp /var/www/html/config/* /mnt/efs/backup/config`
1616
1. Make any necessary changes to the repo.
1717
* For version upgrades, change line 1 in **Dockerfile** to the new version.
1818
* Verify plugin versions for compatibility with new version of Matomo. See **Update Matomo Plugins** below for more details.
@@ -21,33 +21,34 @@ These instructions assume you are working in the **dev** environment. Change to
2121
* Run `make publish-dev` to push the new container to ECR and tag it as 'latest'.
2222
1. Deploy updated container for ECS service.
2323
* Via the AWS Console:
24-
* Go to ECS
25-
* Click on **matomo-ecs-dev-cluster**
26-
* Click on the checkbox in **Services** next to `matomo-ecs-dev-service`
27-
* Click `Update`
28-
* On the next page, expand **Deployment options** and choose `Force new deployment`
29-
* Click `Update`
24+
* Go to ECS
25+
* Click on **matomo-ecs-dev-cluster**
26+
* Click on the checkbox in **Services** next to `matomo-ecs-dev-service`
27+
* Click `Update`
28+
* On the next page, expand **Deployment options** and choose `Force new deployment`
29+
* Click `Update`
3030
* Via AWS CLI
31-
* `aws ecs update-service --cluster matomo-ecs-dev-cluster --service matomo-ecs-dev-service --force-new-deployment`
32-
*Either method takes a few minutes to complete the deployment. It's easiest to verify completion in the AWS Console. A green bar will appear at the top of the page stating `Service updated: matomo-ecs-dev-cluster:matomo-ecs-dev-service`
33-
1. Verify via webUI that the Matomo installation is ready to be upgraded. Ask someone in DEP to assist with this step.
31+
* `aws ecs update-service --cluster matomo-ecs-dev-cluster --service matomo-ecs-dev-service --force-new-deployment`
32+
* Either method takes a few minutes to complete the deployment. It's easiest to verify completion in the AWS Console. A green bar will appear at the top of the page stating `Service updated: matomo-ecs-dev-cluster:matomo-ecs-dev-service`
33+
1. Verify via webUI that the Matomo installation is ready to be upgraded.
34+
* (Infra members should have the "superuser" checkbox checked for their Matomo UI login; if not, please verify with UXWS)
3435
* This step is only necessary when a database update is required.
3536
1. SSH (via AWSCLI + Session Manager) to the container and run the upgrade on the CLI (see the [Troubleshooting](./HOWTO-miscellaneous.md) section for the AWS CLI connection command).
3637
* The database update command is `php /var/www/html/console core:update`.
3738
* This step is only necessary when there is a required update to the table structure in Matomo listed in the release notes.
38-
1. Copy the updated `config/config.ini.php` to the EFS mount.
39-
* Run the **backup-data.sh** script as in step 1.
39+
1. Compare the out-of-band `/mnt/efs/backup/config/config.ini/php` to the updated `config/config.ini.php` for changes.
4040
1. Verify that there were no changes to the `config.ini.php` file that need to be captured back in this repo.
4141
* See [compare-ini-files](./HOWTO-compare-ini-files.md)
42-
1. Log back in to the webUI to verify that everything is working. Ask someone in DEP to assist with this step.
42+
1. Log back in to the webUI to verify that everything is working.
43+
* (Infra members should have the "superuser" checkbox checked for their Matomo UI login; if not, please verify with UXWS)
4344

4445
## Update Matomo Plugins
4546

4647
Often, an update to the version of Matomo will require an update to a plugin version. See below for an overview of the plugin update process.
4748

48-
1. Ensure that a backup of the current `config/config.ini.php` exists in the EFS mount.
49+
1. Ensure that an out-of-band backup of the current `config/config.ini.php` exists
4950
* SSH (via AWSCLI + Session Manager) to the container(see the [Troubleshooting](./HOWTO-miscellaneous.md) section for the AWS CLI connection command).
50-
* Run the **backup-data.sh** script `/usr/local/bin/backup-data.sh`
51+
* Run `cp /var/www/html/config/* /mnt/efs/backup/config`
5152
1. Visit [Matomo plugins](https://plugins.matomo.org), select the correct version of Matomo, and then search for the plugins that are currently in use in our instance of Matomo.
5253
* If there is a newer version, download it from the site, unzip it, and store the unzipped folder in the [files/](../../files/) directory, following the naming convention in place (e.g., `plugin-<plugin_name>-<version>`)
5354
1. Update the [Dockerfile](../../Dockerfile) to reference the newer version of the plugin stored in the [files/](../../files/) directory.

docs/HowTos/HOWTO-miscellaneous.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ To retrieve the **task number** value for the command:
3434
OR
3535

3636
```bash
37-
aws ecs list-clusters | grep matomo
38-
aws ecs list-tasks --cluster matomo-ecs-dev-cluster (or result from previous command)
39-
# The task number is the 32 character hex string at the end of the line
37+
aws ecs list-clusters --output text | grep matomo | cut -d'/' -f2
38+
aws ecs list-tasks --cluster $(aws ecs list-clusters --output text | grep matomo | cut -d'/' -f2) --query "taskArns[*]" --output text | cut -d'/' -f3
4039
```
4140

4241
## Reset 2-Factor auth

files/backup-data.sh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
#!/bin/bash
22

3-
/bin/cp -r /var/www/html/config/ /mnt/efs/config/
4-
/bin/cp -r /var/www/html/misc/user /mnt/efs/misc_user
5-
/bin/cp -r /var/www/html/js/ /mnt/efs/js/
6-
/bin/cp -r /var/www/html/matomo.js /mnt/efs/matomo.js
7-
/bin/cp -r /var/www/html/piwik.js /mnt/efs/piwik.js
3+
target_dir="/mnt/efs"
4+
5+
mkdir -p "$target_dir/config"
6+
tar -cf - -C "/var/www/html/config" . | tar -xf - -C "$target_dir/config"
7+
8+
mkdir -p "$target_dir/misc"
9+
tar -cf - -C "/var/www/html/misc" . | tar -xf - -C "$target_dir/misc"
10+
11+
mkdir -p "$target_dir/js"
12+
tar -cf - -C "/var/www/html/js" . | tar -xf - -C "$target_dir/js"
13+
14+
cp -a "/var/www/html/matomo.js" "$target_dir/matomo.js"
15+
cp -a "/var/www/html/piwik.js" "$target_dir/piwik.js"

files/config.ini.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
collation = utf8mb4_general_ci
77

88
[General]
9+
; disable browser-triggered archiving and expire archives in 30 minutes
10+
browser_archiving_disabled_enforce = 1
11+
time_before_today_archive_considered_outdated = 1800
12+
13+
; for now, disable host checking since we are behind ALB that does host checking for us
14+
enable_trusted_host_check=0
15+
916
proxy_client_headers[] = "HTTP_X_FORWARDED_FOR"
1017

1118
; maximum number of rows for any of the Referers tables (keywords, search engines, campaigns, etc.), and Custom variables names
@@ -24,7 +31,7 @@
2431
datatable_archiving_maximum_rows_subtable_actions = 5000
2532

2633
; maximum number of rows for the Site Search table
27-
datatable_archiving_maximum_rows_site_search = 5000
34+
datatable_archiving_maximum_rows_site_search = 5000
2835

2936
; maximum number of rows for any of the Events tables (Categories, Actions, Names)
3037
datatable_archiving_maximum_rows_events = 5000

0 commit comments

Comments
 (0)