From 4be61aa14ccd7bfbf3a8b2a54208e3c4e2458a3c Mon Sep 17 00:00:00 2001 From: Ivan Reshetnikov Date: Mon, 21 Oct 2024 21:16:05 +0500 Subject: [PATCH] Use redis role to set up mastodon --- roles/mastodon/files/redis-cache.conf | 5 -- roles/mastodon/files/redis.conf | 1 - roles/mastodon/tasks/main.yml | 95 ++++++++++++++++++++++++++- roles/mastodon/tasks/mastodon.yml | 68 ------------------- roles/mastodon/tasks/redis.yml | 62 ----------------- 5 files changed, 93 insertions(+), 138 deletions(-) delete mode 100644 roles/mastodon/files/redis-cache.conf delete mode 100644 roles/mastodon/files/redis.conf delete mode 100644 roles/mastodon/tasks/mastodon.yml delete mode 100644 roles/mastodon/tasks/redis.yml diff --git a/roles/mastodon/files/redis-cache.conf b/roles/mastodon/files/redis-cache.conf deleted file mode 100644 index d258a4d..0000000 --- a/roles/mastodon/files/redis-cache.conf +++ /dev/null @@ -1,5 +0,0 @@ -save "" -appendonly no - -maxmemory 64mb -maxmemory-policy allkeys-lru diff --git a/roles/mastodon/files/redis.conf b/roles/mastodon/files/redis.conf deleted file mode 100644 index 3628768..0000000 --- a/roles/mastodon/files/redis.conf +++ /dev/null @@ -1 +0,0 @@ -save 60 1000 diff --git a/roles/mastodon/tasks/main.yml b/roles/mastodon/tasks/main.yml index 1a950c2..fa29d79 100644 --- a/roles/mastodon/tasks/main.yml +++ b/roles/mastodon/tasks/main.yml @@ -1,3 +1,94 @@ --- -- import_tasks: redis.yml -- import_tasks: mastodon.yml +- name: Create redis-mastodon docker network + become: true + community.docker.docker_network: + name: redis-mastodon + state: absent +- name: Create mastodon docker network + become: true + community.docker.docker_network: + name: mastodon +- name: Create redis container + include_role: + name: redis + vars: + preset: persistent + container_name: redis-mastodon + docker_networks: + - name: mastodon + docker_volume: redis-mastodon +- name: Create redis cache container + include_role: + name: redis + vars: + preset: cache + container_name: redis-mastodon-cache + docker_networks: + - name: mastodon +- name: Create mastodon's public volume + become: true + community.docker.docker_volume: + name: mastodon-public-system +- name: Create mastodon config directory + become: true + ansible.builtin.file: + path: /etc/mastodon + state: directory + mode: '1750' + owner: root + group: root +- name: Copy env file + become: true + ansible.builtin.template: + src: mastodon.env.j2 + dest: /etc/mastodon/.env + mode: '0660' + owner: root + group: root +- name: Create web container + become: true + community.docker.docker_container: + name: mastodon-web + image: ghcr.io/mastodon/mastodon:{{ version }} + env_file: /etc/mastodon/.env + command: ["bundle", "exec", "puma", "-C", "config/puma.rb"] + networks: + - name: mastodon + - name: postgresql + - name: minio + - name: haproxy + - name: authentik + ports: + - 127.0.0.1:3000:3000 + volumes: + - mastodon-public-system:/mastodon/public/system + restart_policy: unless-stopped +- name: Create streaming container + become: true + community.docker.docker_container: + name: mastodon-streaming + image: ghcr.io/mastodon/mastodon-streaming:{{ version }} + env_file: /etc/mastodon/.env + command: ["node", "./streaming/index.js"] + networks: + - name: mastodon + - name: postgresql + - name: haproxy + ports: + - 127.0.0.1:3001:4000 + restart_policy: unless-stopped +- name: Create sidekiq container + become: true + community.docker.docker_container: + name: mastodon-sidekiq + image: ghcr.io/mastodon/mastodon:{{ version }} + env_file: /etc/mastodon/.env + command: ["bundle", "exec", "sidekiq"] + networks: + - name: mastodon + - name: postgresql + - name: minio + - name: authentik + volumes: + - mastodon-public-system:/mastodon/public/system + restart_policy: unless-stopped diff --git a/roles/mastodon/tasks/mastodon.yml b/roles/mastodon/tasks/mastodon.yml deleted file mode 100644 index 3efc828..0000000 --- a/roles/mastodon/tasks/mastodon.yml +++ /dev/null @@ -1,68 +0,0 @@ ---- -- name: Create mastodon's public volume - become: true - community.docker.docker_volume: - name: mastodon-public-system -- name: Create mastodon config directory - become: true - ansible.builtin.file: - path: /etc/mastodon - state: directory - mode: '1750' - owner: root - group: root -- name: Copy env file - become: true - ansible.builtin.template: - src: mastodon.env.j2 - dest: /etc/mastodon/.env - mode: '0660' - owner: root - group: root -- name: Create web container - become: true - community.docker.docker_container: - name: mastodon-web - image: ghcr.io/mastodon/mastodon:{{ version }} - env_file: /etc/mastodon/.env - command: ["bundle", "exec", "puma", "-C", "config/puma.rb"] - networks: - - name: redis-mastodon - - name: postgresql - - name: minio - - name: haproxy - - name: authentik - ports: - - 127.0.0.1:3000:3000 - volumes: - - mastodon-public-system:/mastodon/public/system - restart_policy: unless-stopped -- name: Create streaming container - become: true - community.docker.docker_container: - name: mastodon-streaming - image: ghcr.io/mastodon/mastodon-streaming:{{ version }} - env_file: /etc/mastodon/.env - command: ["node", "./streaming/index.js"] - networks: - - name: redis-mastodon - - name: postgresql - - name: haproxy - ports: - - 127.0.0.1:3001:4000 - restart_policy: unless-stopped -- name: Create sidekiq container - become: true - community.docker.docker_container: - name: mastodon-sidekiq - image: ghcr.io/mastodon/mastodon:{{ version }} - env_file: /etc/mastodon/.env - command: ["bundle", "exec", "sidekiq"] - networks: - - name: redis-mastodon - - name: postgresql - - name: minio - - name: authentik - volumes: - - mastodon-public-system:/mastodon/public/system - restart_policy: unless-stopped diff --git a/roles/mastodon/tasks/redis.yml b/roles/mastodon/tasks/redis.yml deleted file mode 100644 index 9ce11f1..0000000 --- a/roles/mastodon/tasks/redis.yml +++ /dev/null @@ -1,62 +0,0 @@ ---- -- name: Create redis-mastodon docker network - become: true - community.docker.docker_network: - name: redis-mastodon - -- name: Create redis-mastodon docker volume - become: true - community.docker.docker_volume: - name: redis-mastodon - -- name: Create /etc/redis/mastodon dir - become: true - ansible.builtin.file: - path: /etc/redis/mastodon - state: directory - mode: '1755' - owner: root - group: root -- name: Create /etc/redis/mastodon-cache dir - become: true - ansible.builtin.file: - path: /etc/redis/mastodon-cache - state: directory - mode: '1755' - owner: root - group: root - -- name: Copy redis config - become: true - ansible.builtin.copy: - src: redis.conf - dest: /etc/redis/mastodon/redis.conf -- name: Copy redis cache config - become: true - ansible.builtin.copy: - src: redis-cache.conf - dest: /etc/redis/mastodon-cache/redis.conf - -- name: Create redis container - become: true - community.docker.docker_container: - name: redis-mastodon - image: redis:7.4-bookworm - command: ["redis-server", "/etc/redis/redis.conf"] - networks: - - name: redis-mastodon - volumes: - - redis-mastodon:/data - - /etc/redis/mastodon:/etc/redis:ro - restart_policy: unless-stopped -- name: Create redis cache container - become: true - community.docker.docker_container: - name: redis-mastodon-cache - image: redis:7.4-bookworm - command: ["redis-server", "/etc/redis/redis.conf"] - networks: - - name: redis-mastodon - volumes: - - /etc/redis/mastodon-cache:/etc/redis:ro - restart_policy: unless-stopped