From 78e36d76acd49ce84e23de785d013b456018de29 Mon Sep 17 00:00:00 2001 From: Denis Nutiu Date: Wed, 5 Feb 2025 21:18:32 +0200 Subject: [PATCH] add preliminary files for peertube --- peertube-server/playbook.yaml | 12 ++++++++--- peertube-server/templates/backup/backup.sh.j2 | 11 ++++++++++ .../templates/backup/peertube-backup.service | 8 ++++++++ .../templates/backup/peertube-backup.timer | 9 +++++++++ .../templates/services/peertube.container.j2 | 20 +++++++++++++++++++ .../templates/services/peertube.network | 7 +++++++ .../templates/services/postgres.container.j2 | 18 +++++++++++++++++ .../templates/services/redis.container.j2 | 11 ++++++++++ peertube-server/variables.yaml | 5 +++-- 9 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 peertube-server/templates/backup/backup.sh.j2 create mode 100644 peertube-server/templates/backup/peertube-backup.service create mode 100644 peertube-server/templates/backup/peertube-backup.timer create mode 100644 peertube-server/templates/services/peertube.container.j2 create mode 100644 peertube-server/templates/services/peertube.network create mode 100644 peertube-server/templates/services/postgres.container.j2 create mode 100644 peertube-server/templates/services/redis.container.j2 diff --git a/peertube-server/playbook.yaml b/peertube-server/playbook.yaml index dcf06e5..491319d 100644 --- a/peertube-server/playbook.yaml +++ b/peertube-server/playbook.yaml @@ -11,19 +11,25 @@ block: - name: Create PeerTube data directory ansible.builtin.file: - path: "/{{ peertube.data_directory }}" + path: "{{ peertube.base_directory }}/data" state: directory mode: "0755" ignore_errors: true - name: Create PeerTube config directory ansible.builtin.file: - path: "/{{ peertube.config_directory }}" + path: "{{ peertube.base_directory }}/config" state: directory mode: "0754" ignore_errors: true - name: Create PostgresSQL directory ansible.builtin.file: - path: "/{{ postgres.postgres_directory }}" + path: "{{ postgres.postgres_directory }}" + state: directory + mode: "0754" + ignore_errors: true + - name: Create Backups directory + ansible.builtin.file: + path: "{{ peertube.backups_directory }}" state: directory mode: "0754" ignore_errors: true diff --git a/peertube-server/templates/backup/backup.sh.j2 b/peertube-server/templates/backup/backup.sh.j2 new file mode 100644 index 0000000..210bec2 --- /dev/null +++ b/peertube-server/templates/backup/backup.sh.j2 @@ -0,0 +1,11 @@ +name=$(date '+%Y-%m-%d') +cd {{ peertube.base_directory }} +tar -zcvf "$name.config.tar.gz" config +tar -zcvf "$name.data.tar.gz" data +mkdir -p {{ peertube.backups_directory }} +mv *.tar.gz {{ peertube.backups_directory }} +cd {{ postgres.postgres_directory }}/.. +systemctl stop postgres.service +tar -zcvf "$name.postgres.tar.gz" postgres +systemctl start postgres.service +mv *.tar.gz {{ peertube.backups_directory }} \ No newline at end of file diff --git a/peertube-server/templates/backup/peertube-backup.service b/peertube-server/templates/backup/peertube-backup.service new file mode 100644 index 0000000..439abcf --- /dev/null +++ b/peertube-server/templates/backup/peertube-backup.service @@ -0,0 +1,8 @@ +# TODO +[Unit] +Description=peertube-backup + +[Service] +Type=oneshot +User=root +ExecStart=/bin/bash TODO/backup.sh \ No newline at end of file diff --git a/peertube-server/templates/backup/peertube-backup.timer b/peertube-server/templates/backup/peertube-backup.timer new file mode 100644 index 0000000..eaa3d25 --- /dev/null +++ b/peertube-server/templates/backup/peertube-backup.timer @@ -0,0 +1,9 @@ +[Unit] +Description=peertube-backup + +[Timer] +OnCalendar=weekly +Persistent=true + +[Install] +WantedBy=timers.target \ No newline at end of file diff --git a/peertube-server/templates/services/peertube.container.j2 b/peertube-server/templates/services/peertube.container.j2 new file mode 100644 index 0000000..1fa3af2 --- /dev/null +++ b/peertube-server/templates/services/peertube.container.j2 @@ -0,0 +1,20 @@ +[Unit] +Requires=redis.service +After=redis.service + +[Container] +ContainerName=peertube +EnvironmentFile={{ peertube.base_directory }}/{{ peertube.env_file }} +Image={{ peertube.image_name}} +PublishPort=1935:1935 +PublishPort=9000:9000 +Volume={{ peertube.base_directory }}/data:/data +Volume={{ peertube.base_directory }}/config:/config +SecurityLabelType=peertube.process +Network=peertube.network + +[Service] +Restart=always + +[Install] +WantedBy=default.target \ No newline at end of file diff --git a/peertube-server/templates/services/peertube.network b/peertube-server/templates/services/peertube.network new file mode 100644 index 0000000..39ea279 --- /dev/null +++ b/peertube-server/templates/services/peertube.network @@ -0,0 +1,7 @@ +[Unit] +Description=Peertube Network + +[Network] +Subnet=173.18.0.42/16 +Gateway=173.18.0.1 +Label=app=peertube \ No newline at end of file diff --git a/peertube-server/templates/services/postgres.container.j2 b/peertube-server/templates/services/postgres.container.j2 new file mode 100644 index 0000000..762ee70 --- /dev/null +++ b/peertube-server/templates/services/postgres.container.j2 @@ -0,0 +1,18 @@ +[Unit] +Requires=redis.service +After=redis.service + +[Container] +ServiceName=postgres +ContainerName=postgres +EnvironmentFile={{ peertube.base_directory }}/{{ peertube.env_file }} +Image={{ postgres.image_name }} +Volume={{ postgres.postgres_directory }}:/var/lib/postgresql/data +Network=peertube.network +SecurityLabelType=postgres.process + +[Service] +Restart=always + +[Install] +WantedBy=default.target \ No newline at end of file diff --git a/peertube-server/templates/services/redis.container.j2 b/peertube-server/templates/services/redis.container.j2 new file mode 100644 index 0000000..beb98e2 --- /dev/null +++ b/peertube-server/templates/services/redis.container.j2 @@ -0,0 +1,11 @@ +[Container] +ContainerName=redis +ServiceName=redis +Image={{ redis.image_name }} +Network=peertube.network + +[Service] +Restart=always + +[Install] +WantedBy=default.target \ No newline at end of file diff --git a/peertube-server/variables.yaml b/peertube-server/variables.yaml index 3f0b56f..62f49b9 100644 --- a/peertube-server/variables.yaml +++ b/peertube-server/variables.yaml @@ -1,6 +1,7 @@ peertube: - data_directory: "/peertube/data" - config_directory: "/peertube/config" + base_directory: "/peertube" + env_file: "environment_file" + backups_directory: "/peertube/backups" image_name: "docker.io/chocobozzz/peertube:v7.0.1-bookworm" postgres: postgres_directory: "/peertube/postgres"