Split out aws s3 and otp roles.
authorLuke Hoersten <luke@hoersten.org>
Wed, 01 Jul 2020 12:16:48 -0500
changeset 103 78a072bbf3c1
parent 102 5afa8c28e689
child 104 73eb2db468ec
Split out aws s3 and otp roles.
pleroma-otp/defaults/main.yaml
pleroma-otp/files/pleroma-s3-backup.sh
pleroma-otp/files/[email protected]
pleroma-otp/files/[email protected]
pleroma-otp/handlers/main.yaml
pleroma-otp/tasks/main.yaml
pleroma-otp/tasks/s3-backup.yaml
pleroma-otp/templates/config.exs.j2
pleroma-otp/templates/pleroma.cloudflare.index.nginx.conf.j2
pleroma-otp/templates/pleroma.cloudflare.nginx.conf.j2
pleroma-otp/templates/pleroma.letsencrypt.nginx.conf.j2
pleroma-otp/templates/setup_db.psql.j2
pleroma/aws-s3-backup/files/pleroma-s3-backup.sh
pleroma/aws-s3-backup/files/[email protected]
pleroma/aws-s3-backup/meta/main.yaml
pleroma/aws-s3-backup/tasks/main.yaml
pleroma/otp/defaults/main.yaml
pleroma/otp/files/[email protected]
pleroma/otp/handlers/main.yaml
pleroma/otp/tasks/main.yaml
pleroma/otp/templates/config.exs.j2
pleroma/otp/templates/pleroma.cloudflare.index.nginx.conf.j2
pleroma/otp/templates/pleroma.cloudflare.nginx.conf.j2
pleroma/otp/templates/pleroma.letsencrypt.nginx.conf.j2
pleroma/otp/templates/setup_db.psql.j2
--- a/pleroma-otp/defaults/main.yaml	Tue Jun 16 10:54:59 2020 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
----
-
-pleroma_host: "localhost"
-pleroma_port: 4000
-pleroma_scheme: "http"
-
-pleroma_proxy_pass: "{{pleroma_scheme}}://{{pleroma_host}}:{{pleroma_port}}"
-
-pleroma_link_host: "localhost"
-pleroma_link_port: "443"
-pleroma_link_scheme: "https"
-
-pleroma_instance_name: "{{pleroma_link_host}}"
-pleroma_desc: "A Pleroma fediverse instance."
-pleroma_admin_email: "admin@{{pleroma_link_host}}"
-pleroma_char_limit: 5000
-pleroma_signup_open: "true"
-pleroma_db_host: "localhost"
-pleroma_db_superuser: "postgres"
-
-pleroma_download_url: "https://git.pleroma.social/api/v4/projects/2/jobs/artifacts/stable/download?job={{pleroma_flavor}}"
-
-pleroma_db: "pleroma_{{pleroma_instance}}"
-pleroma_db_user: "pleroma_{{pleroma_instance}}"
-pleroma_data_dir: "/var/lib/pleroma/instance_data"
-
-pleroma_s3_backup_enabled: true
-pleroma_cleanup_tmp: false
--- a/pleroma-otp/files/pleroma-s3-backup.sh	Tue Jun 16 10:54:59 2020 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-#!/bin/bash
-
-INSTANCE=$1
-DATE=`date --iso-8601`
-
-BUCKET="pleroma-${INSTANCE//_/-}-backup"
-BACKUP_DIR="/tmp/s3-backup/$BUCKET"
-BACKUP_TAR="/tmp/s3-backup/$BUCKET-$DATE.tgz"
-
-DB_NAME="pleroma_$INSTANCE"
-CONFIG="/etc/pleroma/$INSTANCE.config.exs"
-
-UPLOADS_DIR=`grep uploads $CONFIG | cut -d '"' -f 2`
-STATIC_DIR=`grep static $CONFIG | cut -d '"' -f 2`
-
-mkdir -m 775 -p "$BACKUP_DIR/"
-chown root:postgres "$BACKUP_DIR/"
-
-su postgres -c "pg_dump -d $DB_NAME --format=custom -f $BACKUP_DIR/$DB_NAME.pgdump"
-cp $CONFIG "$BACKUP_DIR/"
-cp -r $UPLOADS_DIR "$BACKUP_DIR/"
-cp -r $STATIC_DIR "$BACKUP_DIR/"
-
-tar -zc -f $BACKUP_TAR $BACKUP_DIR
-aws s3 mb "s3://$BUCKET/"
-aws s3 cp $BACKUP_TAR "s3://$BUCKET/"
--- a/pleroma-otp/files/[email protected]	Tue Jun 16 10:54:59 2020 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-[Unit]
-Description=Pleroma s3 backup for instance "%I"
-
-[Service]
-Type=oneshot
-ExecStart=/usr/local/bin/pleroma-s3-backup.sh %i
-
-[Install]
-WantedBy=aws-s3-backup.target
--- a/pleroma-otp/files/[email protected]	Tue Jun 16 10:54:59 2020 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-[Unit]
-Description=Pleroma social network instance "%I"
-After=network.target postgresql.service nginx.service
-
-[Service]
-User=pleroma
-WorkingDirectory=/opt/pleroma
-
-Environment="HOME=/opt/pleroma"
-Environment="PLEROMA_CONFIG_PATH=/etc/pleroma/%i.config.exs"
-Environment="PLUG_TMPDIR=/tmp/%i"
-Environment="RELEASE_NODE=%[email protected]"
-
-ExecStart=/opt/pleroma/bin/pleroma start
-ExecReload=/opt/pleroma/bin/pleroma stop
-
-KillMode=process
-Restart=on-failure
-
-; Some security directives.
-; Use private /tmp and /var/tmp folders inside a new file system namespace, which are discarded after the process stops.
-PrivateTmp=true
-; The /home, /root, and /run/user folders can not be accessed by this service anymore. If your Pleroma user has its home folder in one of the restricted places, or use one of these folders as its working directory, you have to set this to false.
-ProtectHome=true
-; Mount /usr, /boot, and /etc as read-only for processes invoked by this service.
-ProtectSystem=full
-; Sets up a new /dev mount for the process and only adds API pseudo devices like /dev/null, /dev/zero or /dev/random but not physical devices. Disabled by default because it may not work on devices like the Raspberry Pi.
-PrivateDevices=false
-; Ensures that the service process and all its children can never gain new privileges through execve().
-NoNewPrivileges=true
-; Drops the sysadmin capability from the daemon.
-CapabilityBoundingSet=~CAP_SYS_ADMIN
-
-[Install]
-WantedBy=multi-user.target
--- a/pleroma-otp/handlers/main.yaml	Tue Jun 16 10:54:59 2020 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
----
-
-- name: restart pleroma instance
-  become: yes
-  systemd: name="pleroma@{{pleroma_instance}}.service" state="restarted" daemon_reload="yes"
-
-- name: restart pleroma instance s3 backup
-  become: yes
-  systemd: name="pleroma-s3-backup@{{pleroma_instance}}.service" enabled="yes" daemon_reload="yes"
--- a/pleroma-otp/tasks/main.yaml	Tue Jun 16 10:54:59 2020 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,111 +0,0 @@
----
-
-- name: add users
-  become: yes
-  user: name="pleroma" shell="/bin/false" home="/opt/pleroma" system="yes"
-
-- name: apt install pleroma dependencies
-  become: yes
-  apt: name="libtinfo5"
-
-- name: create config and data directory
-  become: yes
-  file:
-    path: "{{item}}"
-    state: "directory"
-    mode: "0755"
-  with_items:
-    - "{{pleroma_data_dir}}"
-    - "/etc/pleroma"
-    - "/opt/pleroma"
-
-- name: install pleroma config
-  template:
-    src: "config.exs.j2"
-    dest: "/etc/pleroma/{{pleroma_instance}}.config.exs"
-    owner: "pleroma"
-    group: "pleroma"
-    mode: "0600"
-  become: yes
-  notify: restart pleroma instance
-
-- name: create instance data directory
-  become: yes
-  file:
-    path: "{{item}}"
-    state: "directory"
-    owner: "pleroma"
-    group: "pleroma"
-    mode: "0755"
-  with_items:
-    - "{{pleroma_data_dir}}/{{pleroma_instance}}"
-    - "{{pleroma_data_dir}}/{{pleroma_instance}}/uploads"
-    - "{{pleroma_data_dir}}/{{pleroma_instance}}/static"
-    - "{{pleroma_data_dir}}/{{pleroma_instance}}/static/emoji"
-
-- name: install pleroma db schema file
-  become: yes
-  template:
-    src: "setup_db.psql.j2"
-    dest: "/tmp/setup_db_{{pleroma_instance}}.psql"
-    owner: "{{pleroma_db_superuser}}"
-    group: "{{pleroma_db_superuser}}"
-    mode: "0600"
-  changed_when: false
-
-- name: install pleroma psql
-  become: yes
-  become_user: "{{pleroma_db_superuser}}"
-  command: "psql -f /tmp/setup_db_{{pleroma_instance}}.psql"
-  changed_when: false
-
-- name: download and unarchive pleroma release
-  become: yes
-  unarchive:
-    src: "{{pleroma_download_url}}"
-    dest: "/tmp/"
-    remote_src: yes
-    creates: "/tmp/release"
-  notify: restart pleroma instance
-
-- name: install pleroma release
-  become: yes
-  copy:
-    remote_src: true
-    src: "/tmp/release/"
-    dest: "/opt/pleroma/"
-    owner: "pleroma"
-    group: "pleroma"
-  changed_when: false
-
-- name: remove tmp release folder
-  become: yes
-  file: path="{{item}}" state="absent"
-  with_items:
-    - "/tmp/setup_db.psql"
-    - "/tmp/release/"
-  when: pleroma_cleanup_tmp
-
-- import_tasks: s3-backup.yaml
-  when: pleroma_s3_backup_enabled
-
-- name: configure pleroma systemd service
-  become: yes
-  copy:
-    src: "[email protected]"
-    dest: "/lib/systemd/system/[email protected]"
-  notify: restart pleroma instance
-
-- name: ensure pleroma instance is enabled and started
-  become: yes
-  systemd: name="pleroma@{{pleroma_instance}}.service" enabled="yes" state="started"
-
-- name: migrate db
-  become: yes
-  become_user: "pleroma"
-  command: "/opt/pleroma/bin/pleroma_ctl migrate"
-  args:
-    chdir: "/opt/pleroma/"
-  environment:
-    PLEROMA_CONFIG_PATH: "/etc/pleroma/{{pleroma_instance}}.config.exs"
-  changed_when: false
--- a/pleroma-otp/tasks/s3-backup.yaml	Tue Jun 16 10:54:59 2020 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
----
-
-- name: create s3 backup shell script
-  become: yes
-  copy:
-    src: "pleroma-s3-backup.sh"
-    dest: "/usr/local/bin/pleroma-s3-backup.sh"
-    mode: "0755"
-
-- name: configure s3 backup systemd service
-  become: yes
-  copy:
-    src: "[email protected]"
-    dest: "/lib/systemd/system/[email protected]"
-    mode: "0644"
-  notify: restart pleroma instance s3 backup
-
-- name: ensure s3 backup is enabled
-  become: yes
-  systemd: name="pleroma-s3-backup@{{pleroma_instance}}.service" enabled="yes"
--- a/pleroma-otp/templates/config.exs.j2	Tue Jun 16 10:54:59 2020 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,44 +0,0 @@
-import Config
-
-config :pleroma, Pleroma.Web.Endpoint,
-  url: [host: "{{pleroma_link_host}}", scheme: "{{pleroma_link_scheme}}", port: {{pleroma_link_port}}],
-  http: [port: {{pleroma_port}}, ip: {127, 0, 0, 1}],
-  secret_key_base: "{{pleroma_secret_key}}",
-  secure_cookie_flag: true
-
-config :pleroma, :http_security,
-  enabled: true,
-  sts: true,
-  referrer_policy: "same-origin"
-
-config :pleroma, :instance,
-  name: "{{pleroma_instance_name}}",
-  description: "{{pleroma_desc}}",
-  email: "{{pleroma_admin_email}}",
-  limit: {{pleroma_char_limit}},
-  registrations_open: {{pleroma_signup_open}},
-  invites_enabled: {{pleroma_invites_enabled}},
-  static_dir: "{{pleroma_data_dir}}/{{pleroma_instance}}/static/"
-
-config :pleroma, Pleroma.Upload,
-  uploader: Pleroma.Uploaders.Local,
-  filters: [Pleroma.Upload.Filter.Dedupe]
-
-config :pleroma, Pleroma.Uploaders.Local,
-  uploads: "{{pleroma_data_dir}}/{{pleroma_instance}}/uploads/"
-
-config :pleroma, :media_proxy,
-  enabled: false,
-  redirect_on_failure: true
-  #base_url: "https://cache.pleroma.social"
-
-# Configure your database
-config :pleroma, Pleroma.Repo,
-  adapter: Ecto.Adapters.Postgres,
-  username: "{{pleroma_db_user}}",
-  password: "{{pleroma_db_passwd}}",
-  database: "{{pleroma_db}}",
-  hostname: "{{pleroma_db_host}}",
-  pool_size: 10,
-  timeout: 60000,
-  pool_timeout: 60000
--- a/pleroma-otp/templates/pleroma.cloudflare.index.nginx.conf.j2	Tue Jun 16 10:54:59 2020 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,75 +0,0 @@
-# default nginx site config for Pleroma
-#
-# Simple installation instructions:
-# 1. Install your TLS certificate, possibly using Let's Encrypt.
-# 2. Replace 'example.tld' with your instance's domain wherever it appears.
-# 3. Copy this file to /etc/nginx/sites-available/ and then add a symlink to it
-#    in /etc/nginx/sites-enabled/ and run 'nginx -s reload' or restart nginx.
-
-proxy_cache_path /tmp/{{pleroma_instance}}-pleroma-media-cache levels=1:2 keys_zone={{pleroma_instance}}-pleroma_media_cache:10m max_size=10g
-                 inactive=720m use_temp_path=off;
-
-server {
-    listen 80;
-    server_name {{nginx_server_name}};
-    return 301 https://$host$request_uri;
-}
-
-# Enable SSL session caching for improved performance
-ssl_session_cache shared:ssl_session_cache:10m;
-
-server {
-    listen 443 ssl http2;
-    server_name {{nginx_server_name}};
-
-    ssl_certificate {{nginx_ssl_cert}};
-    ssl_certificate_key {{nginx_ssl_privkey}};
-    ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1;
-
-    add_header Strict-Transport-Security "max-age=31536000" always;
-
-    gzip_vary on;
-    gzip_proxied any;
-    gzip_comp_level 6;
-    gzip_buffers 16 8k;
-    gzip_http_version 1.1;
-    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript application/activity+json application/atom+xml;
-
-    # the nginx default is 1m, not enough for large media uploads
-    client_max_body_size 16m;
-
-    location = / {
-        return 301 http://www.$host$request_uri;
-    }
-
-    location / {
-        try_files $uri @pleroma;
-    }
-
-    location @pleroma {
-        add_header X-XSS-Protection "1; mode=block";
-        add_header X-Permitted-Cross-Domain-Policies none;
-        add_header X-Frame-Options DENY;
-        add_header X-Content-Type-Options nosniff;
-        add_header Referrer-Policy same-origin;
-        add_header X-Download-Options noopen;
-
-        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
-
-        proxy_http_version 1.1;
-        proxy_set_header Upgrade $http_upgrade;
-        proxy_set_header Connection "upgrade";
-        proxy_set_header Host $http_host;
-
-        proxy_pass {{pleroma_proxy_pass}};
-
-        client_max_body_size 16m;
-    }
-
-    location /proxy {
-        proxy_cache {{pleroma_instance}}-pleroma_media_cache;
-        proxy_cache_lock on;
-        proxy_ignore_client_abort on;
-        proxy_pass {{pleroma_proxy_pass}};
-    }
-}
--- a/pleroma-otp/templates/pleroma.cloudflare.nginx.conf.j2	Tue Jun 16 10:54:59 2020 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,67 +0,0 @@
-# default nginx site config for Pleroma
-#
-# Simple installation instructions:
-# 1. Install your TLS certificate, possibly using Let's Encrypt.
-# 2. Replace 'example.tld' with your instance's domain wherever it appears.
-# 3. Copy this file to /etc/nginx/sites-available/ and then add a symlink to it
-#    in /etc/nginx/sites-enabled/ and run 'nginx -s reload' or restart nginx.
-
-proxy_cache_path /tmp/{{pleroma_instance}}-pleroma-media-cache levels=1:2 keys_zone={{pleroma_instance}}-pleroma_media_cache:10m max_size=10g
-                 inactive=720m use_temp_path=off;
-
-server {
-    listen 80;
-    server_name {{nginx_server_name}};
-    return 301 https://$host$request_uri;
-}
-
-# Enable SSL session caching for improved performance
-ssl_session_cache shared:ssl_session_cache:10m;
-
-server {
-    listen 443 ssl http2;
-    server_name {{nginx_server_name}};
-
-    ssl_certificate {{nginx_ssl_cert}};
-    ssl_certificate_key {{nginx_ssl_privkey}};
-    ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1;
-
-    add_header Strict-Transport-Security "max-age=31536000" always;
-
-    gzip_vary on;
-    gzip_proxied any;
-    gzip_comp_level 6;
-    gzip_buffers 16 8k;
-    gzip_http_version 1.1;
-    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript application/activity+json application/atom+xml;
-
-    # the nginx default is 1m, not enough for large media uploads
-    client_max_body_size 16m;
-
-    location / {
-        add_header X-XSS-Protection "1; mode=block";
-        add_header X-Permitted-Cross-Domain-Policies none;
-        add_header X-Frame-Options DENY;
-        add_header X-Content-Type-Options nosniff;
-        add_header Referrer-Policy same-origin;
-        add_header X-Download-Options noopen;
-
-        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
-
-        proxy_http_version 1.1;
-        proxy_set_header Upgrade $http_upgrade;
-        proxy_set_header Connection "upgrade";
-        proxy_set_header Host $http_host;
-
-        proxy_pass {{pleroma_proxy_pass}};
-
-        client_max_body_size 16m;
-    }
-
-    location /proxy {
-        proxy_cache {{pleroma_instance}}-pleroma_media_cache;
-        proxy_cache_lock on;
-        proxy_ignore_client_abort on;
-        proxy_pass {{pleroma_proxy_pass}};
-    }
-}
--- a/pleroma-otp/templates/pleroma.letsencrypt.nginx.conf.j2	Tue Jun 16 10:54:59 2020 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,72 +0,0 @@
-# default nginx site config for Pleroma
-#
-# Simple installation instructions:
-# 1. Install your TLS certificate, possibly using Let's Encrypt.
-# 2. Replace 'example.tld' with your instance's domain wherever it appears.
-# 3. Copy this file to /etc/nginx/sites-available/ and then add a symlink to it
-#    in /etc/nginx/sites-enabled/ and run 'nginx -s reload' or restart nginx.
-
-proxy_cache_path /tmp/{{pleroma_instance}}-pleroma-media-cache levels=1:2 keys_zone={{pleroma_instance}}-pleroma_media_cache:10m max_size=10g
-                 inactive=720m use_temp_path=off;
-
-server {
-    listen 80;
-    server_name {{nginx_server_name}};
-    return 301 https://$host$request_uri;
-}
-
-# Enable SSL session caching for improved performance
-ssl_session_cache shared:ssl_session_cache:10m;
-
-server {
-    listen 443 ssl http2;
-    server_name {{nginx_server_name}};
-
-    ssl_certificate {{nginx_ssl_cert}};
-    ssl_certificate_key {{nginx_ssl_privkey}};
-    include /etc/letsencrypt/options-ssl-nginx.conf;
-    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
-
-    ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1;
-    ssl_stapling on;
-    ssl_stapling_verify on;
-
-    add_header Strict-Transport-Security "max-age=31536000" always;
-
-    gzip_vary on;
-    gzip_proxied any;
-    gzip_comp_level 6;
-    gzip_buffers 16 8k;
-    gzip_http_version 1.1;
-    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript application/activity+json application/atom+xml;
-
-    # the nginx default is 1m, not enough for large media uploads
-    client_max_body_size 16m;
-
-    location / {
-        add_header X-XSS-Protection "1; mode=block";
-        add_header X-Permitted-Cross-Domain-Policies none;
-        add_header X-Frame-Options DENY;
-        add_header X-Content-Type-Options nosniff;
-        add_header Referrer-Policy same-origin;
-        add_header X-Download-Options noopen;
-
-        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
-
-        proxy_http_version 1.1;
-        proxy_set_header Upgrade $http_upgrade;
-        proxy_set_header Connection "upgrade";
-        proxy_set_header Host $http_host;
-
-        proxy_pass {{pleroma_proxy_pass}};
-
-        client_max_body_size 16m;
-    }
-
-    location /proxy {
-        proxy_cache {{pleroma_instance}}-pleroma_media_cache;
-        proxy_cache_lock on;
-        proxy_ignore_client_abort on;
-        proxy_pass {{pleroma_proxy_pass}};
-    }
-}
--- a/pleroma-otp/templates/setup_db.psql.j2	Tue Jun 16 10:54:59 2020 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,7 +0,0 @@
-CREATE USER {{pleroma_db_user}} WITH ENCRYPTED PASSWORD '{{pleroma_db_passwd}}';
-CREATE DATABASE {{pleroma_db}} WITH OWNER {{pleroma_db_user}};
-\c {{pleroma_db}};
---Extensions made by ecto.migrate that need superuser access
-CREATE EXTENSION IF NOT EXISTS citext;
-CREATE EXTENSION IF NOT EXISTS pg_trgm;
-CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pleroma/aws-s3-backup/files/pleroma-s3-backup.sh	Wed Jul 01 12:16:48 2020 -0500
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+INSTANCE=$1
+DATE=`date --iso-8601`
+
+BUCKET="pleroma-${INSTANCE//_/-}-backup"
+BACKUP_DIR="/tmp/s3-backup/$BUCKET"
+BACKUP_TAR="/tmp/s3-backup/$BUCKET-$DATE.tgz"
+
+DB_NAME="pleroma_$INSTANCE"
+CONFIG="/etc/pleroma/$INSTANCE.config.exs"
+
+UPLOADS_DIR=`grep uploads $CONFIG | cut -d '"' -f 2`
+STATIC_DIR=`grep static $CONFIG | cut -d '"' -f 2`
+
+mkdir -m 775 -p "$BACKUP_DIR/"
+chown root:postgres "$BACKUP_DIR/"
+
+su postgres -c "pg_dump -d $DB_NAME --format=custom -f $BACKUP_DIR/$DB_NAME.pgdump"
+cp $CONFIG "$BACKUP_DIR/"
+cp -r $UPLOADS_DIR "$BACKUP_DIR/"
+cp -r $STATIC_DIR "$BACKUP_DIR/"
+
+tar -zc -f $BACKUP_TAR $BACKUP_DIR
+aws s3 mb "s3://$BUCKET/"
+aws s3 cp $BACKUP_TAR "s3://$BUCKET/"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pleroma/aws-s3-backup/files/[email protected]	Wed Jul 01 12:16:48 2020 -0500
@@ -0,0 +1,9 @@
+[Unit]
+Description=Pleroma s3 backup for instance "%I"
+
+[Service]
+Type=oneshot
+ExecStart=/usr/local/bin/pleroma-s3-backup.sh %i
+
+[Install]
+WantedBy=aws-s3-backup.target
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pleroma/aws-s3-backup/meta/main.yaml	Wed Jul 01 12:16:48 2020 -0500
@@ -0,0 +1,4 @@
+---
+
+dependencies:
+  - aws-s3-backup
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pleroma/aws-s3-backup/tasks/main.yaml	Wed Jul 01 12:16:48 2020 -0500
@@ -0,0 +1,20 @@
+---
+
+- name: create s3 backup shell script
+  become: yes
+  copy:
+    src: "pleroma-s3-backup.sh"
+    dest: "/usr/local/bin/pleroma-s3-backup.sh"
+    mode: "0755"
+
+- name: configure s3 backup systemd service
+  become: yes
+  copy:
+    src: "[email protected]"
+    dest: "/lib/systemd/system/[email protected]"
+    mode: "0644"
+  notify: restart pleroma instance s3 backup
+
+- name: ensure s3 backup is enabled
+  become: yes
+  systemd: name="pleroma-s3-backup@{{pleroma_instance}}.service" enabled="yes"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pleroma/otp/defaults/main.yaml	Wed Jul 01 12:16:48 2020 -0500
@@ -0,0 +1,27 @@
+---
+
+pleroma_host: "localhost"
+pleroma_port: 4000
+pleroma_scheme: "http"
+
+pleroma_proxy_pass: "{{pleroma_scheme}}://{{pleroma_host}}:{{pleroma_port}}"
+
+pleroma_link_host: "localhost"
+pleroma_link_port: "443"
+pleroma_link_scheme: "https"
+
+pleroma_instance_name: "{{pleroma_link_host}}"
+pleroma_desc: "A Pleroma fediverse instance."
+pleroma_admin_email: "admin@{{pleroma_link_host}}"
+pleroma_char_limit: 5000
+pleroma_signup_open: "true"
+pleroma_db_host: "localhost"
+pleroma_db_superuser: "postgres"
+
+pleroma_download_url: "https://git.pleroma.social/api/v4/projects/2/jobs/artifacts/stable/download?job={{pleroma_flavor}}"
+
+pleroma_db: "pleroma_{{pleroma_instance}}"
+pleroma_db_user: "pleroma_{{pleroma_instance}}"
+pleroma_data_dir: "/var/lib/pleroma/instance_data"
+
+pleroma_cleanup_tmp: false
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pleroma/otp/files/[email protected]	Wed Jul 01 12:16:48 2020 -0500
@@ -0,0 +1,35 @@
+[Unit]
+Description=Pleroma social network instance "%I"
+After=network.target postgresql.service nginx.service
+
+[Service]
+User=pleroma
+WorkingDirectory=/opt/pleroma
+
+Environment="HOME=/opt/pleroma"
+Environment="PLEROMA_CONFIG_PATH=/etc/pleroma/%i.config.exs"
+Environment="PLUG_TMPDIR=/tmp/%i"
+Environment="RELEASE_NODE=%[email protected]"
+
+ExecStart=/opt/pleroma/bin/pleroma start
+ExecReload=/opt/pleroma/bin/pleroma stop
+
+KillMode=process
+Restart=on-failure
+
+; Some security directives.
+; Use private /tmp and /var/tmp folders inside a new file system namespace, which are discarded after the process stops.
+PrivateTmp=true
+; The /home, /root, and /run/user folders can not be accessed by this service anymore. If your Pleroma user has its home folder in one of the restricted places, or use one of these folders as its working directory, you have to set this to false.
+ProtectHome=true
+; Mount /usr, /boot, and /etc as read-only for processes invoked by this service.
+ProtectSystem=full
+; Sets up a new /dev mount for the process and only adds API pseudo devices like /dev/null, /dev/zero or /dev/random but not physical devices. Disabled by default because it may not work on devices like the Raspberry Pi.
+PrivateDevices=false
+; Ensures that the service process and all its children can never gain new privileges through execve().
+NoNewPrivileges=true
+; Drops the sysadmin capability from the daemon.
+CapabilityBoundingSet=~CAP_SYS_ADMIN
+
+[Install]
+WantedBy=multi-user.target
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pleroma/otp/handlers/main.yaml	Wed Jul 01 12:16:48 2020 -0500
@@ -0,0 +1,9 @@
+---
+
+- name: restart pleroma instance
+  become: yes
+  systemd: name="pleroma@{{pleroma_instance}}.service" state="restarted" daemon_reload="yes"
+
+- name: restart pleroma instance s3 backup
+  become: yes
+  systemd: name="pleroma-s3-backup@{{pleroma_instance}}.service" enabled="yes" daemon_reload="yes"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pleroma/otp/tasks/main.yaml	Wed Jul 01 12:16:48 2020 -0500
@@ -0,0 +1,108 @@
+---
+
+- name: add users
+  become: yes
+  user: name="pleroma" shell="/bin/false" home="/opt/pleroma" system="yes"
+
+- name: apt install pleroma dependencies
+  become: yes
+  apt: name="libtinfo5"
+
+- name: create config and data directory
+  become: yes
+  file:
+    path: "{{item}}"
+    state: "directory"
+    mode: "0755"
+  with_items:
+    - "{{pleroma_data_dir}}"
+    - "/etc/pleroma"
+    - "/opt/pleroma"
+
+- name: install pleroma config
+  template:
+    src: "config.exs.j2"
+    dest: "/etc/pleroma/{{pleroma_instance}}.config.exs"
+    owner: "pleroma"
+    group: "pleroma"
+    mode: "0600"
+  become: yes
+  notify: restart pleroma instance
+
+- name: create instance data directory
+  become: yes
+  file:
+    path: "{{item}}"
+    state: "directory"
+    owner: "pleroma"
+    group: "pleroma"
+    mode: "0755"
+  with_items:
+    - "{{pleroma_data_dir}}/{{pleroma_instance}}"
+    - "{{pleroma_data_dir}}/{{pleroma_instance}}/uploads"
+    - "{{pleroma_data_dir}}/{{pleroma_instance}}/static"
+    - "{{pleroma_data_dir}}/{{pleroma_instance}}/static/emoji"
+
+- name: install pleroma db schema file
+  become: yes
+  template:
+    src: "setup_db.psql.j2"
+    dest: "/tmp/setup_db_{{pleroma_instance}}.psql"
+    owner: "{{pleroma_db_superuser}}"
+    group: "{{pleroma_db_superuser}}"
+    mode: "0600"
+  changed_when: false
+
+- name: install pleroma psql
+  become: yes
+  become_user: "{{pleroma_db_superuser}}"
+  command: "psql -f /tmp/setup_db_{{pleroma_instance}}.psql"
+  changed_when: false
+
+- name: download and unarchive pleroma release
+  become: yes
+  unarchive:
+    src: "{{pleroma_download_url}}"
+    dest: "/tmp/"
+    remote_src: yes
+    creates: "/tmp/release"
+  notify: restart pleroma instance
+
+- name: install pleroma release
+  become: yes
+  copy:
+    remote_src: true
+    src: "/tmp/release/"
+    dest: "/opt/pleroma/"
+    owner: "pleroma"
+    group: "pleroma"
+  changed_when: false
+
+- name: remove tmp release folder
+  become: yes
+  file: path="{{item}}" state="absent"
+  with_items:
+    - "/tmp/setup_db.psql"
+    - "/tmp/release/"
+  when: pleroma_cleanup_tmp
+
+- name: configure pleroma systemd service
+  become: yes
+  copy:
+    src: "[email protected]"
+    dest: "/lib/systemd/system/[email protected]"
+  notify: restart pleroma instance
+
+- name: ensure pleroma instance is enabled and started
+  become: yes
+  systemd: name="pleroma@{{pleroma_instance}}.service" enabled="yes" state="started"
+
+- name: migrate db
+  become: yes
+  become_user: "pleroma"
+  command: "/opt/pleroma/bin/pleroma_ctl migrate"
+  args:
+    chdir: "/opt/pleroma/"
+  environment:
+    PLEROMA_CONFIG_PATH: "/etc/pleroma/{{pleroma_instance}}.config.exs"
+  changed_when: false
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pleroma/otp/templates/config.exs.j2	Wed Jul 01 12:16:48 2020 -0500
@@ -0,0 +1,44 @@
+import Config
+
+config :pleroma, Pleroma.Web.Endpoint,
+  url: [host: "{{pleroma_link_host}}", scheme: "{{pleroma_link_scheme}}", port: {{pleroma_link_port}}],
+  http: [port: {{pleroma_port}}, ip: {127, 0, 0, 1}],
+  secret_key_base: "{{pleroma_secret_key}}",
+  secure_cookie_flag: true
+
+config :pleroma, :http_security,
+  enabled: true,
+  sts: true,
+  referrer_policy: "same-origin"
+
+config :pleroma, :instance,
+  name: "{{pleroma_instance_name}}",
+  description: "{{pleroma_desc}}",
+  email: "{{pleroma_admin_email}}",
+  limit: {{pleroma_char_limit}},
+  registrations_open: {{pleroma_signup_open}},
+  invites_enabled: {{pleroma_invites_enabled}},
+  static_dir: "{{pleroma_data_dir}}/{{pleroma_instance}}/static/"
+
+config :pleroma, Pleroma.Upload,
+  uploader: Pleroma.Uploaders.Local,
+  filters: [Pleroma.Upload.Filter.Dedupe]
+
+config :pleroma, Pleroma.Uploaders.Local,
+  uploads: "{{pleroma_data_dir}}/{{pleroma_instance}}/uploads/"
+
+config :pleroma, :media_proxy,
+  enabled: false,
+  redirect_on_failure: true
+  #base_url: "https://cache.pleroma.social"
+
+# Configure your database
+config :pleroma, Pleroma.Repo,
+  adapter: Ecto.Adapters.Postgres,
+  username: "{{pleroma_db_user}}",
+  password: "{{pleroma_db_passwd}}",
+  database: "{{pleroma_db}}",
+  hostname: "{{pleroma_db_host}}",
+  pool_size: 10,
+  timeout: 60000,
+  pool_timeout: 60000
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pleroma/otp/templates/pleroma.cloudflare.index.nginx.conf.j2	Wed Jul 01 12:16:48 2020 -0500
@@ -0,0 +1,75 @@
+# default nginx site config for Pleroma
+#
+# Simple installation instructions:
+# 1. Install your TLS certificate, possibly using Let's Encrypt.
+# 2. Replace 'example.tld' with your instance's domain wherever it appears.
+# 3. Copy this file to /etc/nginx/sites-available/ and then add a symlink to it
+#    in /etc/nginx/sites-enabled/ and run 'nginx -s reload' or restart nginx.
+
+proxy_cache_path /tmp/{{pleroma_instance}}-pleroma-media-cache levels=1:2 keys_zone={{pleroma_instance}}-pleroma_media_cache:10m max_size=10g
+                 inactive=720m use_temp_path=off;
+
+server {
+    listen 80;
+    server_name {{nginx_server_name}};
+    return 301 https://$host$request_uri;
+}
+
+# Enable SSL session caching for improved performance
+ssl_session_cache shared:ssl_session_cache:10m;
+
+server {
+    listen 443 ssl http2;
+    server_name {{nginx_server_name}};
+
+    ssl_certificate {{nginx_ssl_cert}};
+    ssl_certificate_key {{nginx_ssl_privkey}};
+    ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1;
+
+    add_header Strict-Transport-Security "max-age=31536000" always;
+
+    gzip_vary on;
+    gzip_proxied any;
+    gzip_comp_level 6;
+    gzip_buffers 16 8k;
+    gzip_http_version 1.1;
+    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript application/activity+json application/atom+xml;
+
+    # the nginx default is 1m, not enough for large media uploads
+    client_max_body_size 16m;
+
+    location = / {
+        return 301 http://www.$host$request_uri;
+    }
+
+    location / {
+        try_files $uri @pleroma;
+    }
+
+    location @pleroma {
+        add_header X-XSS-Protection "1; mode=block";
+        add_header X-Permitted-Cross-Domain-Policies none;
+        add_header X-Frame-Options DENY;
+        add_header X-Content-Type-Options nosniff;
+        add_header Referrer-Policy same-origin;
+        add_header X-Download-Options noopen;
+
+        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
+
+        proxy_http_version 1.1;
+        proxy_set_header Upgrade $http_upgrade;
+        proxy_set_header Connection "upgrade";
+        proxy_set_header Host $http_host;
+
+        proxy_pass {{pleroma_proxy_pass}};
+
+        client_max_body_size 16m;
+    }
+
+    location /proxy {
+        proxy_cache {{pleroma_instance}}-pleroma_media_cache;
+        proxy_cache_lock on;
+        proxy_ignore_client_abort on;
+        proxy_pass {{pleroma_proxy_pass}};
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pleroma/otp/templates/pleroma.cloudflare.nginx.conf.j2	Wed Jul 01 12:16:48 2020 -0500
@@ -0,0 +1,67 @@
+# default nginx site config for Pleroma
+#
+# Simple installation instructions:
+# 1. Install your TLS certificate, possibly using Let's Encrypt.
+# 2. Replace 'example.tld' with your instance's domain wherever it appears.
+# 3. Copy this file to /etc/nginx/sites-available/ and then add a symlink to it
+#    in /etc/nginx/sites-enabled/ and run 'nginx -s reload' or restart nginx.
+
+proxy_cache_path /tmp/{{pleroma_instance}}-pleroma-media-cache levels=1:2 keys_zone={{pleroma_instance}}-pleroma_media_cache:10m max_size=10g
+                 inactive=720m use_temp_path=off;
+
+server {
+    listen 80;
+    server_name {{nginx_server_name}};
+    return 301 https://$host$request_uri;
+}
+
+# Enable SSL session caching for improved performance
+ssl_session_cache shared:ssl_session_cache:10m;
+
+server {
+    listen 443 ssl http2;
+    server_name {{nginx_server_name}};
+
+    ssl_certificate {{nginx_ssl_cert}};
+    ssl_certificate_key {{nginx_ssl_privkey}};
+    ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1;
+
+    add_header Strict-Transport-Security "max-age=31536000" always;
+
+    gzip_vary on;
+    gzip_proxied any;
+    gzip_comp_level 6;
+    gzip_buffers 16 8k;
+    gzip_http_version 1.1;
+    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript application/activity+json application/atom+xml;
+
+    # the nginx default is 1m, not enough for large media uploads
+    client_max_body_size 16m;
+
+    location / {
+        add_header X-XSS-Protection "1; mode=block";
+        add_header X-Permitted-Cross-Domain-Policies none;
+        add_header X-Frame-Options DENY;
+        add_header X-Content-Type-Options nosniff;
+        add_header Referrer-Policy same-origin;
+        add_header X-Download-Options noopen;
+
+        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
+
+        proxy_http_version 1.1;
+        proxy_set_header Upgrade $http_upgrade;
+        proxy_set_header Connection "upgrade";
+        proxy_set_header Host $http_host;
+
+        proxy_pass {{pleroma_proxy_pass}};
+
+        client_max_body_size 16m;
+    }
+
+    location /proxy {
+        proxy_cache {{pleroma_instance}}-pleroma_media_cache;
+        proxy_cache_lock on;
+        proxy_ignore_client_abort on;
+        proxy_pass {{pleroma_proxy_pass}};
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pleroma/otp/templates/pleroma.letsencrypt.nginx.conf.j2	Wed Jul 01 12:16:48 2020 -0500
@@ -0,0 +1,72 @@
+# default nginx site config for Pleroma
+#
+# Simple installation instructions:
+# 1. Install your TLS certificate, possibly using Let's Encrypt.
+# 2. Replace 'example.tld' with your instance's domain wherever it appears.
+# 3. Copy this file to /etc/nginx/sites-available/ and then add a symlink to it
+#    in /etc/nginx/sites-enabled/ and run 'nginx -s reload' or restart nginx.
+
+proxy_cache_path /tmp/{{pleroma_instance}}-pleroma-media-cache levels=1:2 keys_zone={{pleroma_instance}}-pleroma_media_cache:10m max_size=10g
+                 inactive=720m use_temp_path=off;
+
+server {
+    listen 80;
+    server_name {{nginx_server_name}};
+    return 301 https://$host$request_uri;
+}
+
+# Enable SSL session caching for improved performance
+ssl_session_cache shared:ssl_session_cache:10m;
+
+server {
+    listen 443 ssl http2;
+    server_name {{nginx_server_name}};
+
+    ssl_certificate {{nginx_ssl_cert}};
+    ssl_certificate_key {{nginx_ssl_privkey}};
+    include /etc/letsencrypt/options-ssl-nginx.conf;
+    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
+
+    ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1;
+    ssl_stapling on;
+    ssl_stapling_verify on;
+
+    add_header Strict-Transport-Security "max-age=31536000" always;
+
+    gzip_vary on;
+    gzip_proxied any;
+    gzip_comp_level 6;
+    gzip_buffers 16 8k;
+    gzip_http_version 1.1;
+    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript application/activity+json application/atom+xml;
+
+    # the nginx default is 1m, not enough for large media uploads
+    client_max_body_size 16m;
+
+    location / {
+        add_header X-XSS-Protection "1; mode=block";
+        add_header X-Permitted-Cross-Domain-Policies none;
+        add_header X-Frame-Options DENY;
+        add_header X-Content-Type-Options nosniff;
+        add_header Referrer-Policy same-origin;
+        add_header X-Download-Options noopen;
+
+        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
+
+        proxy_http_version 1.1;
+        proxy_set_header Upgrade $http_upgrade;
+        proxy_set_header Connection "upgrade";
+        proxy_set_header Host $http_host;
+
+        proxy_pass {{pleroma_proxy_pass}};
+
+        client_max_body_size 16m;
+    }
+
+    location /proxy {
+        proxy_cache {{pleroma_instance}}-pleroma_media_cache;
+        proxy_cache_lock on;
+        proxy_ignore_client_abort on;
+        proxy_pass {{pleroma_proxy_pass}};
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pleroma/otp/templates/setup_db.psql.j2	Wed Jul 01 12:16:48 2020 -0500
@@ -0,0 +1,7 @@
+CREATE USER {{pleroma_db_user}} WITH ENCRYPTED PASSWORD '{{pleroma_db_passwd}}';
+CREATE DATABASE {{pleroma_db}} WITH OWNER {{pleroma_db_user}};
+\c {{pleroma_db}};
+--Extensions made by ecto.migrate that need superuser access
+CREATE EXTENSION IF NOT EXISTS citext;
+CREATE EXTENSION IF NOT EXISTS pg_trgm;
+CREATE EXTENSION IF NOT EXISTS "uuid-ossp";