Skip to content

Commit 490f48e

Browse files
authored
Merge pull request #6 from MITLibraries/awsorg
Migrate Matomo to AWS Organization (Stage-Workloads) * deploy Matomo container to Stage-Workloads ECR
2 parents e39f757 + b7f6ac8 commit 490f48e

File tree

21 files changed

+1819
-106
lines changed

21 files changed

+1819
-106
lines changed

.github/pull-request-template.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
### What does this PR do?
2+
3+
Describe the overall purpose of the PR changes. Doesn't need to be as specific as the
4+
individual commits.
5+
6+
### Helpful background context
7+
8+
Describe any additional context beyond what the PR accomplishes if it is likely to be
9+
useful to a reviewer.
10+
11+
Delete this section if it isn't applicable to the PR.
12+
13+
### How can a reviewer manually see the effects of these changes?
14+
15+
Explain how to see the proposed changes in the application if possible.
16+
17+
Delete this section if it isn't applicable to the PR.
18+
19+
### Includes new or updated dependencies?
20+
21+
YES | NO
22+
23+
### What are the relevant tickets?
24+
25+
Include links to Jira Software and/or Jira Service Management tickets here.
26+
27+
### Developer
28+
29+
- [ ] All new ENV is documented in README (or there is none)
30+
- [ ] Stakeholder approval has been confirmed (or is not needed)
31+
32+
### Code Reviewer
33+
34+
- [ ] The commit message is clear and follows our guidelines
35+
(not just this pull request message)
36+
- [ ] There are appropriate tests covering any new functionality
37+
- [ ] The documentation has been updated or is unnecessary
38+
- [ ] The changes have been verified
39+
- [ ] New dependencies are appropriate or there were no changes

.github/workflows/dev_build.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
### This is the Terraform-generated dev-build.yml workflow for the matomo-dev app repository ###
2+
name: Dev Build and Deploy Fargate Container
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
branches:
7+
- main
8+
paths-ignore:
9+
- '.github/**'
10+
11+
jobs:
12+
deploy:
13+
name: Dev Deploy Fargate Container
14+
uses: mitlibraries/.github/.github/workflows/fargate-shared-deploy-dev.yml@main
15+
secrets: inherit
16+
with:
17+
AWS_REGION: "us-east-1"
18+
GHA_ROLE: "matomo-gha-dev"
19+
ECR: "matomo-dev"

.github/workflows/prod-promote.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
### This is the Terraform-generated prod-promote.yml workflow for the matomo-prod app repository ###
2+
name: Prod Promote Fargate Container
3+
on:
4+
workflow_dispatch:
5+
release:
6+
types: [published]
7+
8+
jobs:
9+
deploy:
10+
name: Prod Promote Fargate Container
11+
uses: mitlibraries/.github/.github/workflows/fargate-shared-promote-prod.yml@main
12+
secrets: inherit
13+
with:
14+
AWS_REGION: "us-east-1"
15+
GHA_ROLE_STAGE: matomo-gha-stage
16+
GHA_ROLE_PROD: matomo-gha-prod
17+
ECR_STAGE: "matomo-stage"
18+
ECR_PROD: "matomo-prod"

.github/workflows/stage-build.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
### This is the Terraform-generated stage-build.yml workflow for the matomo-stage app repository ###
2+
name: Stage Build and Deploy Fargate Container
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
paths-ignore:
9+
- '.github/**'
10+
11+
jobs:
12+
deploy:
13+
name: Stage Deploy Fargate Container
14+
uses: mitlibraries/.github/.github/workflows/fargate-shared-deploy-stage.yml@main
15+
secrets: inherit
16+
with:
17+
AWS_REGION: "us-east-1"
18+
GHA_ROLE: "matomo-gha-stage"
19+
ECR: "matomo-stage"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.env
2+
**/.DS_Store

Dockerfile

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
FROM matomo:latest
2-
3-
# Install system dependencies
4-
RUN apt-get update && apt-get upgrade -y
5-
6-
7-
EXPOSE 80 443
8-
9-
COPY config.ini.php /var/www/html/config/config.ini.php
10-
11-
1+
FROM matomo:3.13.6-apache
122

3+
# Add the EnvironmentVariables plugin
4+
COPY ./files/plugin-EnvironmentVariables-3.0.0/ /var/www/html/plugins/EnvironmentVariables
135

6+
# Preconfigure settings
7+
COPY ./files/config.ini.php /var/www/html/config/config.ini.php
148

9+
# Create mount point for EFS partition
10+
RUN mkdir -p /mnt/efs
1511

12+
EXPOSE 80

Makefile

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
1-
.PHONY: help dist publish promote
1+
.PHONY: help dist-dev publish-dev dist-stage publish-stage
22
SHELL=/bin/bash
3-
ECR_REGISTRY=672626379771.dkr.ecr.us-east-1.amazonaws.com
4-
DATETIME:=$(shell date -u +%Y%m%dT%H%M%SZ)
3+
### This is the Terraform-generated header for matomo-dev ###
4+
ECR_NAME_DEV:=matomo-dev
5+
ECR_URL_DEV:=222053980223.dkr.ecr.us-east-1.amazonaws.com/matomo-dev
6+
### End of Terraform-generated header ###
57

68
help: ## Print this message
79
@awk 'BEGIN { FS = ":.*##"; print "Usage: make <target>\n\nTargets:" } \
810
/^[-_[:alpha:]]+:.?*##/ { printf " %-15s%s\n", $$1, $$2 }' $(MAKEFILE_LIST)
911

10-
build: ## Build docker image
11-
docker build -t $(ECR_REGISTRY)/analytics-stage:latest \
12-
-t analytics-stage:latest .
13-
14-
15-
dist: dist ## Build, tag and push
16-
$$(aws ecr get-login --no-include-email --region us-east-1)
17-
docker push $(ECR_REGISTRY)/analytics-stage:latest
18-
aws ecs update-service --cluster analytics-stage-cluster --service analytics-stage --region us-east-1 --force-new-deployment
12+
### Terraform-generated Developer Deploy Commands for Dev environment ###
13+
dist-dev: ## Build docker container (intended for developer-based manual build)
14+
docker build --platform linux/amd64 \
15+
-t $(ECR_URL_DEV):latest \
16+
-t $(ECR_URL_DEV):`git describe --always` \
17+
-t $(ECR_NAME_DEV):latest .
1918

20-
publish: ## Promote the current staging build to production
21-
$$(aws ecr get-login --no-include-email --region us-east-1)
22-
docker pull $(ECR_REGISTRY)/analytics-stage:latest
23-
docker tag $(ECR_REGISTRY)/analytics-stage:latest $(ECR_REGISTRY)/analytics-prod:latest
24-
docker tag $(ECR_REGISTRY)/analytics-stage:latest $(ECR_REGISTRY)/analytics-prod:$(DATETIME)
25-
docker push $(ECR_REGISTRY)/analytics-prod:latest
26-
docker push $(ECR_REGISTRY)/analytics-prod:$(DATETIME)
27-
aws ecs update-service --cluster analytics-prod-cluster --service analytics-prod --region us-east-1 --force-new-deployment
19+
publish-dev: dist-dev ## Build, tag and push (intended for developer-based manual publish)
20+
docker login -u AWS -p $$(aws ecr get-login-password --region us-east-1) $(ECR_URL_DEV)
21+
docker push $(ECR_URL_DEV):latest
22+
docker push $(ECR_URL_DEV):`git describe --always`
23+
24+
### Terraform-generated manual shortcuts for deploying to Stage ###
25+
### This requires that ECR_NAME_STAGE & ECR_URL_STAGE environment variables are set locally
26+
### by the developer and that the developer has authenticated to the correct AWS Account.
27+
### The values for the environment variables can be found in the stage_build.yml caller workflow.
28+
dist-stage: ## Only use in an emergency
29+
docker build --platform linux/amd64 \
30+
-t $(ECR_URL_STAGE):latest \
31+
-t $(ECR_URL_STAGE):`git describe --always` \
32+
-t $(ECR_NAME_STAGE):latest .
33+
34+
publish-stage: ## Only use in an emergency
35+
docker login -u AWS -p $$(aws ecr get-login-password --region us-east-1) $(ECR_URL_STAGE)
36+
docker push $(ECR_URL_STAGE):latest
37+
docker push $(ECR_URL_STAGE):`git describe --always`

README.md

Lines changed: 31 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,60 @@
11
# Search Analytics (Matomo)
22

3-
This repository supports MIT Libraries' implementation of [Matomo](https://matomo.org/),
4-
which we use to collect discovery analytics. Our implementation uses the Docker
5-
container provided by Matomo. We host the application in AWS Fargate.
3+
This repository supports MIT Libraries' implementation of [Matomo](https://matomo.org/), which we use to collect discovery analytics. Our implementation uses the Docker container provided by Matomo. We host the application in AWS Fargate.
64

7-
## Building
5+
## Dependencies
86

9-
Run `make build` to create a new container tagged as `analytics-stage:latest`.
7+
* Deploying this container to AWS requires that the AWS ECR Repository for the container has been created by the [mitlib-tf-workloads-ecr](https://github.com/MITLibraries/mitlib-tf-workloads-ecr) repository.
8+
* Building this container requires access to [Official Docker Matomo](https://hub.docker.com/_/matomo/).
109

11-
## Deploying
10+
## Build
1211

13-
Run `make dist` to build, tag, and push a container to staging. To promote to
14-
production, run `make publish`.
12+
Run `make dist-dev` to create a new container tagged as `matomo:latest`.
1513

16-
Please see the corresponding [Terraform module](https://github.com/MITLibraries/mitlib-terraform/tree/master/apps/analytics) for deployment config.
14+
## Deploy
1715

18-
## URLs
19-
20-
- Staging: analytics-stage.mitlib.net (MIT VPN access only)
21-
- Production: analytics-prod.mitlib.net
16+
Run `make publish-dev` to build, tag, and push a container to Dev1 for testing, or open a PR to `main`. Merge a PR to `main` to build, tag, and push the container to Stage-Workloads. After merging the PR to `main`, tag a release to promote to production.
2217

2318
## Implementation notes
2419

25-
### PHP configuration file
20+
For detailed instructions on initial setup, migration, database upgrades, and application upgrades, see [docs/HOWTO.md](./docs/HOWTO.md).
21+
22+
### Configuration Management
23+
24+
"State" for Matomo is managed/stored in at most two locations:
2625

27-
`config.ini.php` file contains some basic Matomo configuration. There are a
28-
couple of sections worth addressing:
26+
* the `config.ini.php` file
27+
* the MySQL database
2928

30-
1. The `Plugins` section tells Matomo which plugins to enable on installation.
31-
To disable a plugin, simply remove it from this section. Our preference is to
32-
modify this section and not the `PluginsInstalled` section, as removing a
33-
plugin from `PluginsInstalled` would remove it from the application completely.
34-
2. The `mail` section configures the SMTP server. Matomo uses mailers for
35-
several core functions, including password resets and reporting. Some related
36-
config values (e.g., `login_password_recovery_email_address`) are defined in
37-
the `General` section.
29+
The `config.ini.php` file contains some core Matomo configuration. There are a couple of sections worth addressing:
3830

39-
When deploying from scratch, we noticed that the initial Matomo setup in the GUI
40-
seems to overwrite our config. As a result, it may be necessary on rare occasion
41-
to spin up an EC2 instance to touch the config file directly. So far, we've
42-
only had to do this after the initial deploy, so it's unlikely to come up often.
31+
1. The `[Plugins]` section tells Matomo which plugins to enable on installation. To disable a plugin, simply remove it from this section. Our preference is to modify this section and not the `PluginsInstalled` section, as removing a plugin from `PluginsInstalled` would remove it from the application completely. *Sadly, with the container-based Matomo, it seems to only way to activate a plugin is to use the Matomo web UI*.
32+
1. The `[mail]` section configures the SMTP server. Matomo uses mailers for several core functions, including password resets and reporting. Some related config values (e.g., `login_password_recovery_email_address`) are defined in the `[General]` section.
33+
1. The `[General]` section handles other configurations. A few of these settings are covered by the EnvironmentVariables plugin, but the rest are managed in this code.
34+
35+
By using the [EnvironmentVariables](https://plugins.matomo.org/EnvironmentVariables) plugin for Matomo, we generally don't need to store much in the `config.ini.php` file. Instead, the [mitlib-tf-workloads-matomo](https://github.com/MITLibraries/mitlib-tf-workloads-matomo) code defines the key environment variables for the ECS service, overriding anything in `config.ini.php` and `global.ini.php`.
36+
37+
The database stores the rest of the state of Matomo: all the data itself along with the Superuser credentials and the other user accounts and credentials.
4338

4439
### Data anonymization
4540

46-
We anonymize tracking data to protect our users' privacy. Specifically, we mask
47-
two bytes of visitors' IPs (e.g., 192.186.x.x), and we have disabled [Matomo's
48-
User ID plugin](https://matomo.org/docs/user-id/).
41+
We anonymize tracking data to protect our users' privacy. Specifically, we mask two bytes of visitors' IPs (e.g., 192.186.x.x), and we have disabled [Matomo's User ID plugin](https://matomo.org/docs/user-id/).
4942

50-
Before promoting a new build to production, ensure that IPs are anonymized by
51-
visiting Administration -> Privacy -> Anonymize data in the GUI. (You shouldn't
52-
ever need to modify these settings, but it's important to verify as part of the
53-
deploy process.)
43+
Before promoting a new build to production, ensure that IPs are anonymized by visiting Administration -> Privacy -> Anonymize data in the GUI. (You shouldn't ever need to modify these settings, but it's important to verify as part of the deploy process.)
5444

5545
### Archiving reports
5646

57-
Matomo calls the process by which it compiles raw log data into human-readable
58-
report 'archiving'. By default, archiving occurs on demand, whenever a Matomo
59-
user attempts to view a report in the GUI. Based on [Matomo's recommendation](https://matomo.org/docs/setup-auto-archiving/), we have configured a cron job to archive reports every
60-
hour.
61-
62-
The cron job runs as a scheduled ECS task and is defined in the
63-
[Terraform config](https://github.com/MITLibraries/mitlib-terraform/tree/master/apps/analytics).
47+
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.
6448

6549
### Authentication
6650

67-
The superuser account can create and manage user
68-
accounts in the GUI (Administration -> System -> Users). After creating a new
69-
account, the superuser should notify the account holder. The account holder
70-
can then reset their password by clicking the 'Lost your password?' link on the
71-
Matomo sign-in page.
51+
The superuser account can create and manage user accounts in the GUI (Administration -> System -> Users). After creating a new account, the superuser should notify the account holder. The account holder can then reset their password by clicking the 'Lost your password?' link on the Matomo sign-in page.
7252

73-
We generally assign the 'View' role to new users, unless they require a higher
74-
permissions level.
53+
We generally assign the 'View' role to new users, unless they require a higher permissions level.
7554

76-
Matomo has built-in two-factor authentication, which we enforce for all accounts.
77-
When a user logs in to Matomo for the first time, they will be prompted to
78-
configure 2FA. At this time, we are recommending Duo as an authenticator.
55+
Matomo has built-in two-factor authentication, which we enforce for all accounts. When a user logs in to Matomo for the first time, they will be prompted to configure 2FA. At this time, we are recommending Duo as an authenticator.
7956

8057
## Additional documentation
8158

82-
* [MIT Libraries dev docs](https://mitlibraries.github.io/guides/misc/matomo.html) - includes
83-
information about setting up a website for tracking in Matomo.
84-
* [Matomo help center](https://matomo.org/help/) - offical Matomo docs.
85-
Includes user guide, developer guide, FAQ, and community support forum.
59+
* [MIT Libraries dev docs](https://mitlibraries.github.io/guides/misc/matomo.html) - includes information about setting up a website for tracking in Matomo.
60+
* [Matomo help center](https://matomo.org/help/) - offical Matomo docs. Includes user guide, developer guide, FAQ, and community support forum.

0 commit comments

Comments
 (0)