Created
August 3, 2023 14:12
-
-
Save Dania02525/f698a491adc4fe6e201c373db9972dc3 to your computer and use it in GitHub Desktop.
An AWS cloudformation stack to run plausible analytics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Resources: | |
Cluster: | |
Type: AWS::ECS::Cluster | |
DeletionPolicy: Retain | |
Properties: | |
ClusterName: <the name of your already created cluster> | |
Analytics: | |
Type: AWS::ECS::Service | |
DeletionPolicy: Delete | |
Properties: | |
Cluster: !Ref Cluster | |
EnableExecuteCommand: true | |
DesiredCount: 1 | |
LaunchType: FARGATE | |
TaskDefinition: !Ref AnalyticsTaskDefinition | |
ServiceName: analytics-service | |
NetworkConfiguration: | |
AwsvpcConfiguration: | |
AssignPublicIp: ENABLED | |
SecurityGroups: | |
- <the security group configuration for your Fargate task> | |
Subnets: | |
- <the subnet for your task, must be in common with the load balancer> | |
LoadBalancers: | |
- ContainerName: plausible | |
ContainerPort: 8000 | |
TargetGroupArn: <the already created target group arn where this task will be found by the load balancer> | |
AnalyticsTaskDefinition: | |
Type: AWS::ECS::TaskDefinition | |
DeletionPolicy: Retain | |
Properties: | |
Family: plausible-analytics | |
Memory: 4096 | |
Cpu: 2048 | |
TaskRoleArn: <task role arn> | |
ExecutionRoleArn: <task execution role arn> | |
RequiresCompatibilities: | |
- FARGATE | |
NetworkMode: awsvpc | |
RuntimePlatform: | |
OperatingSystemFamily: LINUX | |
ContainerDefinitions: | |
- Name: mail | |
Essential: true | |
Image: bytemark/smtp | |
LogConfiguration: | |
LogDriver: awslogs | |
Options: | |
awslogs-group: /ecs/plausible | |
awslogs-region: <your aws region> | |
awslogs-stream-prefix: ecs | |
- Name: plausible_db | |
Essential: true | |
Image: postgres:14-alpine | |
Environment: | |
- Name: POSTGRES_PASSWORD | |
Value: <a suitable postgres password> | |
- Name: POSTGRES_USER | |
Value: plausible | |
- Name: PGDATA | |
Value: /data/postgres | |
MountPoints: | |
- ContainerPath: /data/postgres | |
SourceVolume: analytics-pg-storage | |
HealthCheck: | |
Command: | |
- "CMD-SHELL" | |
- "pg_isready" | |
- "-q" | |
- "-d" | |
- "plausible_db" | |
- "-U" | |
- "plausible" | |
Interval: 10 | |
Retries: 5 | |
StartPeriod: 30 | |
PortMappings: | |
- ContainerPort: 5432 | |
LogConfiguration: | |
LogDriver: awslogs | |
Options: | |
awslogs-group: /ecs/plausible | |
awslogs-region: <your aws region> | |
awslogs-stream-prefix: ecs | |
- Name: plausible_events_db | |
Essential: true | |
Image: clickhouse/clickhouse-server:22.6-alpine | |
Ulimits: | |
- Name: nofile | |
SoftLimit: 262144 | |
HardLimit: 262144 | |
MountPoints: | |
- ContainerPath: /var/lib/clickhouse | |
SourceVolume: analytics-clickhouse-storage | |
PortMappings: | |
- ContainerPort: 8123 | |
LogConfiguration: | |
LogDriver: awslogs | |
Options: | |
awslogs-group: /ecs/plausible | |
awslogs-region: <your aws region> | |
awslogs-stream-prefix: ecs | |
- Name: geoip-updater | |
Essential: true | |
Image: maxmindinc/geoipupdate | |
Environment: | |
- Name: GEOIPUPDATE_EDITION_IDS | |
Value: GeoLite2-Country | |
- Name: GEOIPUPDATE_FREQUENCY | |
Value: 168 | |
- Name: GEOIPUPDATE_ACCOUNT_ID | |
Value: <your maxmind account id> | |
- Name: GEOIPUPDATE_LICENSE_KEY | |
Value: <your maxmind license key> | |
MountPoints: | |
- ContainerPath: /usr/share/GeoIP | |
SourceVolume: analytics-maxmind-storage | |
LogConfiguration: | |
LogDriver: awslogs | |
Options: | |
awslogs-group: /ecs/plausible | |
awslogs-region: <your aws region> | |
awslogs-stream-prefix: ecs | |
- Name: plausible | |
Image: plausible/analytics:latest | |
Command: | |
- "sh" | |
- "-c" | |
- "sleep 10 && /entrypoint.sh db createdb && /entrypoint.sh db migrate && /entrypoint.sh run" | |
Environment: | |
- Name: BASE_URL | |
Value: <the place where you host anaylytics, eg; https://analytics.mysite.com> | |
- Name: SECRET_KEY_BASE | |
Value: <a suitable secret key generated for the app (mix.phx.gen secret)> | |
- Name: DISABLE_REGISTRATION | |
Value: < Note, after you have created your first user, this should be 'invite_only'> | |
- Name: GEOLITE2_COUNTRY_DB | |
Value: /geoip/GeoLite2-Country.mmdb | |
- Name: DATABASE_URL | |
Value: postgres://<db plausible:password from above>@localhost:5432/plausible_db | |
- Name: CLICKHOUSE_DATABASE_URL | |
Value: http://localhost:8123/plausible_events_db | |
- Name: MAILER_EMAIL | |
Value: <the email address used as a sender, eg, analytics@mysite.com> | |
- Name: SMTP_HOST_ADDR | |
Value: localhost | |
- Name: SMTP_HOST_PORT | |
Value: 25 | |
DependsOn: | |
- Condition: START | |
ContainerName: mail | |
- Condition: HEALTHY | |
ContainerName: plausible_db | |
- Condition: START | |
ContainerName: plausible_events_db | |
- Condition: START | |
ContainerName: geoip-updater | |
MountPoints: | |
- ContainerPath: /geoip | |
SourceVolume: analytics-maxmind-storage | |
PortMappings: | |
- ContainerPort: 8000 | |
LogConfiguration: | |
LogDriver: awslogs | |
Options: | |
awslogs-group: /ecs/plausible | |
awslogs-region: <your aws region> | |
awslogs-stream-prefix: ecs | |
Volumes: | |
- Name: analytics-clickhouse-storage | |
EFSVolumeConfiguration: | |
FilesystemId: <an EFS fs-xxx id for an already-created EFS> | |
- Name: analytics-pg-storage | |
EFSVolumeConfiguration: | |
FilesystemId: <an EFS fs-xxx id for an already-created EFS> | |
- Name: analytics-maxmind-storage | |
EFSVolumeConfiguration: | |
FilesystemId: <an EFS fs-xxx id for an already-created EFS> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment