From 9ee4e1c14b25aab28196a60e9d51cb227df6464c Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Tue, 21 Jul 2020 20:55:44 +0100 Subject: [PATCH] Add plausible analytics --- ansible/main.yml | 1 + .../roles/plausible/files/docker-compose.yml | 43 +++++++++++++++++++ ansible/roles/plausible/handlers/main.yml | 4 ++ ansible/roles/plausible/tasks/main.yml | 17 ++++++++ ansible/roles/plausible/vars/main.yml | 21 +++++++++ terraform/theorangeone.net.tf | 8 ++++ 6 files changed, 94 insertions(+) create mode 100644 ansible/roles/plausible/files/docker-compose.yml create mode 100644 ansible/roles/plausible/handlers/main.yml create mode 100644 ansible/roles/plausible/tasks/main.yml create mode 100644 ansible/roles/plausible/vars/main.yml diff --git a/ansible/main.yml b/ansible/main.yml index a2e6de3..114dbda 100644 --- a/ansible/main.yml +++ b/ansible/main.yml @@ -37,6 +37,7 @@ - netdata - home-assistant - intersect-docker + - plausible - hosts: grimes roles: diff --git a/ansible/roles/plausible/files/docker-compose.yml b/ansible/roles/plausible/files/docker-compose.yml new file mode 100644 index 0000000..86ab9cc --- /dev/null +++ b/ansible/roles/plausible/files/docker-compose.yml @@ -0,0 +1,43 @@ +version: "2.3" + +services: + plausible: + image: plausible/analytics:latest + depends_on: + - db + - clickhouse + expose: + - 8080 # https://github.com/plausible/analytics/pull/237 + labels: + - traefik.enable=true + - traefik.http.routers.plausible.rule=Host(`plausible.theorangeone.net`) + - traefik.http.routers.plausible.tls.certresolver=le + environment: + - PORT=8080 + - SECRET_KEY_BASE={{ secret_key }} + - SIGNING_SALT={{ signing_salt }} + - DATABASE_URL=postgres://plausible:plausible@db:5432/plausible + - DISABLE_REGISTRATION=true + - DISABLE_SUBSCRIPTION=true + - CLICKHOUSE_DATABASE_HOST=clickhouse + - CLICKHOUSE_DATABASE_NAME=plausible + - HOST=plausible.theorangeone.net + - SCHEME=https + + clickhouse: + image: yandex/clickhouse-server:latest + volumes: + - ./clickhouse:/var/lib/clickhouse + ulimits: + nofile: + soft: 262144 + hard: 262144 + + db: + image: postgres:12-alpine + restart: unless-stopped + volumes: + - ./postgres:/var/lib/postgresql/data + environment: + - POSTGRES_PASSWORD=plausible + - POSTGRES_USER=plausible diff --git a/ansible/roles/plausible/handlers/main.yml b/ansible/roles/plausible/handlers/main.yml new file mode 100644 index 0000000..2868580 --- /dev/null +++ b/ansible/roles/plausible/handlers/main.yml @@ -0,0 +1,4 @@ +- name: restart plausible + shell: + chdir: /opt/plausible + cmd: "{{ docker_update_command }}" diff --git a/ansible/roles/plausible/tasks/main.yml b/ansible/roles/plausible/tasks/main.yml new file mode 100644 index 0000000..d911756 --- /dev/null +++ b/ansible/roles/plausible/tasks/main.yml @@ -0,0 +1,17 @@ +- name: Create install directory + file: + path: /opt/plausible + state: directory + owner: "{{ docker_user.name }}" + mode: "{{ docker_compose_directory_mask }}" + become: true + +- name: Install compose file + template: + src: files/docker-compose.yml + dest: /opt/plausible/docker-compose.yml + mode: "{{ docker_compose_file_mask }}" + owner: "{{ docker_user.name }}" + validate: /usr/bin/docker-compose -f %s config + notify: restart plausible + become: true diff --git a/ansible/roles/plausible/vars/main.yml b/ansible/roles/plausible/vars/main.yml new file mode 100644 index 0000000..9d2dd72 --- /dev/null +++ b/ansible/roles/plausible/vars/main.yml @@ -0,0 +1,21 @@ +secret_key: !vault | + $ANSIBLE_VAULT;1.1;AES256 + 39336333353061326461306663306661393465646536323664353933643030623561393732323438 + 3162376361386238623238323765376261303431643530660a646234653266326264336636343264 + 38396537646661386435353134663033336133646233343334356364663136373233623436383862 + 6139326335313830370a623737303837643630613535363534613663343163353330626131376435 + 61346534303264643065663763653837396530333166336364346234663031616565666163323631 + 64626666626466333131353264313166313139623865393833393766636466383139323463313263 + 36376337623437346465346665633732333264333662363632623235326262626339366434396563 + 64326232306534656161343638316166313763333834393065323965626465663136356332636463 + 62343466396637643466373561316665333238393964306232353239303062653432303466666638 + 62623038393639393339303661633039306463306364656339656164313033643536356266363939 + 613233393837653836633837373339653934 +signing_salt: !vault | + $ANSIBLE_VAULT;1.1;AES256 + 35366665313061333735636265386535663830666531376365323033353338653536633334646566 + 3065393638663934623237336561633365303664613863350a326661393439393532316666653134 + 61353939626433396530636665636439313966636130386365396535326239366331646664383562 + 3763326533373266620a376230613664633332663065393561656565653634366130323534633865 + 35336236653664373131343364373637653261303030663239333534653432386438343162393866 + 3563353137633338623239346538643662393537313932386366 diff --git a/terraform/theorangeone.net.tf b/terraform/theorangeone.net.tf index f532372..9b55d2a 100644 --- a/terraform/theorangeone.net.tf +++ b/terraform/theorangeone.net.tf @@ -156,3 +156,11 @@ resource "cloudflare_record" "theorangeonenet_rng" { type = "A" ttl = 1 } + +resource "cloudflare_record" "theorangeonenet_plausible" { + zone_id = cloudflare_zone.theorangeonenet.id + name = "plausible" + value = vultr_server.casey.main_ip + type = "A" + ttl = 1 +}