ansible-role-mastodon/tasks/docker/docker.yml

109 lines
3.2 KiB
YAML
Raw Normal View History

2022-11-19 16:31:16 +01:00
---
2022-11-19 17:30:33 +01:00
- name: Clone Mastodon repo
git:
repo: https://github.com/mastodon/mastodon.git
2022-11-19 18:00:40 +01:00
dest: "{{ mastodon_composer_folder }}"
2022-11-19 17:30:33 +01:00
depth: 1
2022-11-19 19:17:41 +01:00
ignore_errors: true
2022-11-19 17:30:33 +01:00
- name: Copy Dockerfile from Mastodon repo
copy:
2022-11-19 17:56:21 +01:00
src: files/Dockerfile
2022-11-19 17:30:33 +01:00
dest: "{{ mastodon_composer_folder }}/Dockerfile"
2022-11-19 17:24:45 +01:00
- name: Ensure mastodon folder exists
file:
path: "{{ mastodon_composer_folder }}"
state: directory
- name: Create docker-compose.yaml file
copy:
src: files/docker-compose.yml
dest: "{{ mastodon_composer_folder }}/docker-compose.yml"
2022-11-19 16:31:16 +01:00
2022-11-19 16:47:52 +01:00
- name: Ensure mastodon configuration is present
template:
src: templates/env.j2
2022-11-19 17:24:45 +01:00
dest: "{{ mastodon_composer_folder }}/.env.production"
2022-11-19 16:47:52 +01:00
2022-11-19 19:06:51 +01:00
- name: Build Mastodon container
2022-11-19 16:31:16 +01:00
community.docker.docker_compose:
project_name: mastodon
2022-11-19 17:24:45 +01:00
project_src: "{{ mastodon_composer_folder }}/"
2022-11-19 16:31:16 +01:00
state: present
2022-11-19 19:06:51 +01:00
- name: Generate secret key
shell: docker-compose run --rm web bundle exec rake secret
2022-11-19 19:16:26 +01:00
args:
chdir: "{{ mastodon_composer_folder }}"
2022-11-19 19:06:51 +01:00
register: secret_key_cmd
when: mastodon_secret_key_base == ''
- name: Add secret key to Mastodon config
lineinfile:
path: "{{ mastodon_composer_folder }}/.env.production"
line: "SECRET_KEY_BASE={{ secret_key_cmd.stdout }}"
regexp: "^SECRET_KEY_BASE="
backup: yes
- name: Generate OTP secret key
shell: docker-compose run --rm web bundle exec rake secret
2022-11-19 19:16:26 +01:00
args:
chdir: "{{ mastodon_composer_folder }}"
2022-11-19 19:06:51 +01:00
register: otp_key_cmd
when: mastodon_otp_secret == ''
- name: Add OTP key to Mastodon config
lineinfile:
path: "{{ mastodon_composer_folder }}/.env.production"
line: "OTP_SECRET={{ otp_key_cmd.stdout }}"
regexp: "^OTP_SECRET="
backup: yes
- name: Generate Paperclip secret key
shell: docker-compose run --rm web bundle exec rake secret
2022-11-19 19:16:26 +01:00
args:
chdir: "{{ mastodon_composer_folder }}"
2022-11-19 19:06:51 +01:00
register: paperclip_key_cmd
when: mastodon_paperclip_secret == ''
- name: Add Paperclip key to Mastodon config
lineinfile:
path: "{{ mastodon_composer_folder }}/.env.production"
line: "PAPERCLIP_SECRET={{ paperclip_key_cmd.stdout }}"
regexp: "^PAPERCLIP_SECRET="
backup: yes
- name: Generate VAPID keypair
2022-11-19 19:16:26 +01:00
shell: 'docker-compose run --rm web bundle exec rake mastodon:webpush:generate_vapid_key'
args:
chdir: "{{ mastodon_composer_folder }}"
2022-11-19 19:06:51 +01:00
register: vapid_key_cmd
when: vapid_public_key == ''
- name: Add Paperclip private key to Mastodon config
lineinfile:
path: "{{ mastodon_composer_folder }}/.env.production"
line: "{{ vapid_key_cmd.stdout_lines[0] }}"
regexp: "^VAPID_PRIVATE_KEY="
backup: yes
- name: Add Paperclip public key to Mastodon config
lineinfile:
path: "{{ mastodon_composer_folder }}/.env.production"
line: "{{ vapid_key_cmd.stdout_lines[1] }}"
regexp: "^VAPID_PUBLIC_KEY="
backup: yes
2022-11-19 19:14:41 +01:00
2022-11-19 19:20:35 +01:00
- name: Build (again) Mastodon container to include secrets
community.docker.docker_compose:
project_name: mastodon
project_src: "{{ mastodon_composer_folder }}/"
state: present
2022-11-19 19:14:41 +01:00
- name: Set up database
shell: docker-compose run --rm web rails db:migrate && echo "Database set up." > /var/lib/mastodon_db_setup
args:
2022-11-19 19:16:26 +01:00
creates: /var/lib/mastodon_db_setup
chdir: "{{ mastodon_composer_folder }}"