Initial commit

This commit is contained in:
Waffles
2022-12-21 22:30:01 -08:00
commit 19ebda26b4
47 changed files with 1429 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
---
dependencies:
- role: geerlingguy.docker
- role: yttrx
+32
View File
@@ -0,0 +1,32 @@
---
# Setup users etc
- name: create the mastodon user account
user:
name: mastodon
shell: /bin/bash
group: docker
- name: Check if mastodon repo checked out
stat: path=/home/mastodon/live
register: p
- import_tasks: swap.yml
- import_tasks: repo.yml
when: not p.stat.exists
- name: Install statsd mapper
template:
src: statsd-mapping.yaml.j2
dest: /root/statsd-mapping.yml
- name: Install .env.production file
template:
src: env.production.j2
dest: /home/mastodon/live/.env.production
- name: Install docker-compose.yml file
template:
src: docker-compose.yml.j2
dest: /home/mastodon/live/docker-compose.yml
notify: "docker-compose up"
+7
View File
@@ -0,0 +1,7 @@
---
- name: clone mastodon repo
git:
repo: https://github.com/mastodon/mastodon.git
dest: /home/mastodon/live
version: v4.0.2
+36
View File
@@ -0,0 +1,36 @@
- name: set swap_file variable
set_fact:
swap_file: /{{ swap_space }}.swap
- name: check if swap file exists
stat:
path: "{{ swap_file }}"
register: swap_file_check
- name: create swap file
command: fallocate -l {{ swap_space }} {{ swap_file }}
args:
creates: /{{ swap_file }}
- name: set permissions on swap file
file:
path: "{{ swap_file }}"
mode: 0600
- name: format swap file
command: mkswap {{ swap_file }}
when: not swap_file_check.stat.exists
- name: add to fstab
lineinfile:
dest: /etc/fstab
regexp: "{{ swap_file }}"
line: "{{ swap_file }} none swap sw 0 0"
- name: turn on swap
command: swapon -a
- name: set swapiness
sysctl:
name: vm.swappiness
value: "1"
@@ -0,0 +1,20 @@
sidekiq-default:
image: tootsuite/mastodon:{{ MASTODON_VERSION }}
restart: always
env_file: .env.production
command: bundle exec sidekiq -q default -c 5
depends_on:
- pgbouncer
networks:
- external_network
- internal_network
volumes:
- ./public/system:/mastodon/public/system
- ./config:/opt/mastodon/config
environment:
{% if DB_POOL is defined %}
- 'DB_POOL={{ DB_POOL }}'
{% endif %}
healthcheck:
test: ['CMD-SHELL', "ps aux | grep '[s]idekiq\ 6' || false"]
@@ -0,0 +1,19 @@
# sidekiq-ingress
sidekiq-ingress:
image: tootsuite/mastodon:{{ MASTODON_VERSION }}
restart: always
env_file: .env.production
command: bundle exec sidekiq -q ingress
depends_on:
- pgbouncer
networks:
- external_network
- internal_network
volumes:
- ./public/system:/mastodon/public/system
- ./config:/opt/mastodon/config
environment:
- 'DB_POOL=25'
healthcheck:
test: ['CMD-SHELL', "ps aux | grep '[s]idekiq\ 6' || false"]
@@ -0,0 +1,20 @@
sidekiq-mailers:
image: tootsuite/mastodon:{{ MASTODON_VERSION }}
restart: always
env_file: .env.production
command: bundle exec sidekiq -q mailers -c 5
depends_on:
- pgbouncer
networks:
- external_network
- internal_network
volumes:
- ./public/system:/mastodon/public/system
- ./config:/opt/mastodon/config
environment:
- 'DB_POOL=25'
healthcheck:
test: ['CMD-SHELL', "ps aux | grep '[s]idekiq\ 6' || false"]
@@ -0,0 +1,19 @@
sidekiq-pushpull:
image: tootsuite/mastodon:{{ MASTODON_VERSION }}
restart: always
env_file: .env.production
command: bundle exec sidekiq -q push -q pull -c 5
depends_on:
- pgbouncer
networks:
- external_network
- internal_network
volumes:
- ./public/system:/mastodon/public/system
- ./config:/opt/mastodon/config
environment:
- 'DB_POOL=25'
healthcheck:
test: ['CMD-SHELL', "ps aux | grep '[s]idekiq\ 6' || false"]
@@ -0,0 +1,19 @@
sidekiq-scheduler:
image: tootsuite/mastodon:{{ MASTODON_VERSION }}
restart: always
env_file: .env.production
command: bundle exec sidekiq -q scheduler
depends_on:
- pgbouncer
networks:
- external_network
- internal_network
volumes:
- ./public/system:/mastodon/public/system
- ./config:/opt/mastodon/config
environment:
- 'DB_POOL=25'
healthcheck:
test: ['CMD-SHELL', "ps aux | grep '[s]idekiq\ 6' || false"]
@@ -0,0 +1,15 @@
sidekiq:
image: tootsuite/mastodon:{{ MASTODON_VERSION }}
restart: always
env_file: .env.production
command: bundle exec sidekiq
depends_on:
- pgbouncer
networks:
- external_network
- internal_network
volumes:
- ./public/system:/mastodon/public/system
- ./config:/opt/mastodon/config
healthcheck:
test: ['CMD-SHELL', "ps aux | grep '[s]idekiq\ 6' || false"]
@@ -0,0 +1,33 @@
version: '3'
services:
{% if ENV_PRODUCTION['STATSD_ADDR'] is defined %}
statsd:
restart: always
image: prom/statsd-exporter
command: --statsd.mapping-config=/tmp/statsd_mapping.yml
volumes:
- /root/statsd-mapping.yml:/tmp/statsd_mapping.yml
networks:
- internal_network
- external_network
ports:
- 9102:9102
- "127.0.0.1:9125:9125"
{% endif %}
pgbouncer:
restart: always
image: edoburu/pgbouncer
networks:
- internal_network
- external_network
environment:
- 'DB_HOST={{ REAL_DB_HOST }}'
- 'DB_NAME={{ ENV_PRODUCTION["DB_NAME"] }}'
- 'DB_USER={{ ENV_PRODUCTION["DB_USER"] }}'
- 'DB_PASSWORD={{ ENV_PRODUCTION["DB_PASS"] }}'
- 'SERVER_TLS_SSLMODE=prefer'
networks:
external_network:
internal_network:
internal: true
@@ -0,0 +1,3 @@
{% for key, val in ENV_PRODUCTION.items() %}
{{ key }}={{ val }}
{% endfor %}
@@ -0,0 +1,96 @@
## Prometheus Statsd Exporter mapping for Mastodon 4.0+
##
## Version 1.0, November 2022
##
## Documentation: https://ipng.ch/s/articles/2022/11/27/mastodon-3.html
mappings:
## Web collector
- match: Mastodon\.production\.web\.(.+)\.(.+)\.(.+)\.status\.(.+)
match_type: regex
name: "mastodon_controller_status"
labels:
controller: $1
action: $2
format: $3
status: $4
mastodon: "web"
- match: Mastodon\.production\.web\.(.+)\.(.+)\.(.+)\.db_time
match_type: regex
name: "mastodon_controller_db_time"
labels:
controller: $1
action: $2
format: $3
mastodon: "web"
- match: Mastodon\.production\.web\.(.+)\.(.+)\.(.+)\.view_time
match_type: regex
name: "mastodon_controller_view_time"
labels:
controller: $1
action: $2
format: $3
mastodon: "web"
- match: Mastodon\.production\.web\.(.+)\.(.+)\.(.+)\.total_duration
match_type: regex
name: "mastodon_controller_duration"
labels:
controller: $1
action: $2
format: $3
mastodon: "web"
## Database collector
- match: Mastodon\.production\.db\.tables\.(.+)\.queries\.(.+)\.duration
match_type: regex
name: "mastodon_db_operation"
labels:
table: "$1"
operation: "$2"
mastodon: "db"
## Cache collector
- match: Mastodon\.production\.cache\.(.+)\.duration
match_type: regex
name: "mastodon_cache_duration"
labels:
operation: "$1"
mastodon: "cache"
## Sidekiq collector
- match: Mastodon\.production\.sidekiq\.(.+)\.processing_time
match_type: regex
name: "mastodon_sidekiq_worker_processing_time"
labels:
worker: "$1"
mastodon: "sidekiq"
- match: Mastodon\.production\.sidekiq\.(.+)\.success
match_type: regex
name: "mastodon_sidekiq_worker_success_total"
labels:
worker: "$1"
mastodon: "sidekiq"
- match: Mastodon\.production\.sidekiq\.(.+)\.failure
match_type: regex
name: "mastodon_sidekiq_worker_failure_total"
labels:
worker: "$1"
mastodon: "sidekiq"
- match: Mastodon\.production\.sidekiq\.queues\.(.+)\.enqueued
match_type: regex
name: "mastodon_sidekiq_queue_enqueued"
labels:
queue: "$1"
mastodon: "sidekiq"
- match: Mastodon\.production\.sidekiq\.queues\.(.+)\.latency
match_type: regex
name: "mastodon_sidekiq_queue_latency"
labels:
queue: "$1"
mastodon: "sidekiq"
- match: Mastodon\.production\.sidekiq\.(.+)
match_type: regex
name: "mastodon_sidekiq_$1"
labels:
mastodon: "sidekiq"